当前位置:网站首页>Ansa secondary development - external programs use socket to communicate with ansa
Ansa secondary development - external programs use socket to communicate with ansa
2022-06-21 07:34:00 【CaeCoder】
The implementation steps are as follows :
- stay ANSA Script Edit Running server code in :
# Server code socket_server.py
import socket
import os
import sys
def work():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost',1000))
sock.listen(1)
while True:
try:
conn, addr = sock.accept()
ret = conn.recv(2048)
# result = os.popen(ret).read()
# popen(ret) Wrong command
result = exec(ret)
conn.send("success".encode())
except KeyboardInterrupt:
print('Now we will exit')
sys.exit(0)
sock.close()
if __name__ == '__main__':
work()
Click on 【 function 】 Button :

After operation ANSA The main program is locked :
2. Client code client.py
# Client code client.py
import socket
def socket_send(command):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 1000))
sock.send(command)
result = sock.recv(2048)
sock.close()
return result
cmd = '''from ansa import base from ansa import constants fields = {'X1': 3.5, 'X2': 10.8, 'X3': 246.7} new_grid = base.CreateEntity(constants.NASTRAN, 'GRID', fields) print('The id of the new grid:', new_grid._id) '''
print(socket_send(cmd.encode()))
open Python IDLE( need python3 The compiler ), as follows File —>Open open client.py

function Run:Run Module or F5 function
see ANSA Operation in : You can see that the node has been created ( Only the main process is closed socket after ANSA To operate , Created Grid Only then )

add to WX official account - CAE Second development of software Lab, See more great technical articles !
There are problems :
At present only in ANSA Run in the main thread socket, But running socket after ANSA The main thread is locked , Lead to ANSA Can't operate ; Only the main process is closed socket after ANSA To operate , Created ANSA Object appears .
边栏推荐
- Life cycle of kubernetes pod
- Tensorrt笔记(三)参考整理
- Exists and in
- Horizontal slot, one line of code can directly convert the web page to PDF and save it (pdfkit)
- [graduation season - advanced technology Er]: the technology sharing of senior college students and the future encouragement
- Matlab 3D diagram (unconventional)
- Research Report on anhydrous trisodium phosphate industry - market status analysis and development prospect forecast
- 【3】 AI studio project details - single machine multi machine training distributed training - Parl
- Exclusive Xiaoman education, medical and aesthetic education, and no direct marketing by stages
- Mathematics is a tool for solving problems
猜你喜欢

Rdkit | molecular similarity based on molecular fingerprint

What is Eureka? What can Eureka do? How does Eureka work?

mysql存储过程中的循环语句怎么写

Horizontal slot, one line of code can directly convert the web page to PDF and save it (pdfkit)

rdkit | 药物分子进行片段分解

Course design of supply chain modeling and simulation based on Flexsim

stm32中定义和声明问题

数学是用于解决问题的工具

卧槽,一行代码就可将网页直接转pdf保存下来(pdfkit)

. Net 4.5 asynchronous programming pilot (async and await)
随机推荐
mysql如何关闭事务
In order to thoroughly understand the problem of garbled code, I dug up the history of the character set in a rage
Market trend report, technical innovation and market forecast of inorganic water treatment chemicals in China
ANSA二次开发 - 外部程序采用socket与ANSA实现通信
RPA (shadow knife) does not need to write code to capture the product information of an East
传输层 TCP首部-序号和确认号
Dynamic addition of prompt information for successful operation
How to view the MySQL installation path
WordPress website security in 2022
Rdkit | topological polarity surface area (TPSA)
企业级开发使用POI踩坑盘点
How to see who developed the applet (see the method of the applet development company)
Analysis of source code encryption products
How do I install the visual studio code editor?
How to optimize MySQL paging query
Cloud native enthusiast weekly: Chaos mesh upgraded to CNCF incubation project
Horizontal slot, one line of code can directly convert the web page to PDF and save it (pdfkit)
Rdkit | compound library based on murcko skeleton clustering
Seat number of Pat grade B 1041 test (15 points)
海思系列量产硬件调试记录