marnixteunissen
Looking around for some CAD
Hi, I am currently trying to implement the batch processing of STEP files through the asi server in python.
So far I have had little success sending commands or reading messages over the UDP server.
I was wondering how the tester tool (http://analysissitus.org/features/features_batch-mode.html) was made, or if the source code is available somewhere
The server class I made for this looks something like this:
So far I have had little success sending commands or reading messages over the UDP server.
I was wondering how the tester tool (http://analysissitus.org/features/features_batch-mode.html) was made, or if the source code is available somewhere
The server class I made for this looks something like this:
Python:
import socket
import subprocess
import signal
from time import sleep
class UDP_Server():
def __init__(self, exe_dir, ip="127.0.0.1", port=6006):
self.exe_dir = exe_dir
self.ip = ip
self.port = port
self.server_proc = subprocess.Popen(f"cd \"{self.exe_dir}\" && asiExeServer.exe "
f"/host={ip} /port={port}", shell=True)
self.socket = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP)
# self.socket.bind((self.ip, self.port))
def send_tcl_command(self, command):
self.socket.sendto(command.encode('utf-8'), (self.ip, self.port))
def receive_message(self):
print('receiving messages:')
message, address = self.socket.recvfrom(1024)
print(message)
def kill_server(self):
killed = False
print("Killing Analysis Situs server executable...")
try:
self.send_tcl_command('exit')
self.server_proc.send_signal(signal.SIGTERM)
while not killed:
if self.server_proc.poll() is None:
print(f'Subprocess not killed yet, waiting ...')
else:
print(f'Succesfully killed server subprocess '
f'with pid: {self.server_proc.pid}')
killed = True
break
sleep(0.5)
except ProcessLookupError:
print(f'Server process not found, assuming it was already killed')