Using asiExeServer as subprocess

marnixteunissen

CAD practitioner
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:

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')
 

Quaoar

Administrator
Staff member
That was a C# code given to me by a friend. Seems like I don't have it on my working laptop, but I could try to find it on another machine in the evening (once I get home). Will keep you posted.
 

marnixteunissen

CAD practitioner
Thanks! looking forward to it.
Is there any more documentation on how to interact with the asi server apart from the documentation on batch processing?
 

Quaoar

Administrator
Staff member
Thanks! looking forward to it.
Is there any more documentation on how to interact with the asi server apart from the documentation on batch processing?
Not really. The documentation is not the strongest part of the project as you can already see. Actually, this server thing was employed to build the following small demo (it was not me who did it): https://ascad.net/

I guess this UDP server might require some improvement and polishing at `asiExeServer` side. The thing is that I use the UI/SDK deliverables most of the time, so I'm not a good tester for this part of the project.
 

marnixteunissen

CAD practitioner
Thanks! The tool you sent works indeed, in a very similar way to what I made in python.
Since I want to do some batch processing I guess this would be the most simple way to interact with Analysis Situs.
right now I am trying to send TCL commands over the UDP server, if I wanted to access more information than the TCL functions return in the logger, where would you suggest I can look?
I want for example to create a mesh of a step file and find a list of all the facets and which face in the step file they were created from.
 

Quaoar

Administrator
Staff member
Thanks! The tool you sent works indeed, in a very similar way to what I made in python.
Since I want to do some batch processing I guess this would be the most simple way to interact with Analysis Situs.
right now I am trying to send TCL commands over the UDP server, if I wanted to access more information than the TCL functions return in the logger, where would you suggest I can look?
I want for example to create a mesh of a step file and find a list of all the facets and which face in the step file they were created from.
Are you feeling comfortable with C++? I would suggest adding the missing functionality as Tcl commands right in C++. In Analysis Situs, you can prepare a plugin dll/so that would add the necessary commands (especially if you don't want to make them open-sourced). The DLLs are loaded from the `asi-plugins` subdirectory located in the installation folder of Analysis Situs.
 
Top