Hello World for the Autodesk Robot Structural Analysis Pro API using Python
RSA Pro with python.
Let’s start with pywin32. Install into a virtual environment:
pip install pywin32
The script:
import win32com.client as win32
rsa = win32.gencache.EnsureDispatch("Robot.Application")
print("Hello, World")
print(rsa.__module__)
rsa.Visible = True
_ = input("Press ENTER to quit:")
rsa.Quit(0)
The rundown:
The API for Autodesk Robot Structural Analysis Professional is based on COM. Thus, for this example we import the win32com.client module and use win32.gencache.EnsureDispatch("Robot.Application") to create the application object. I forget the details at the moment, but there are two approaches to generating the Python code to wrap the COM object: dynamic and static. I think this is the dynamic approach as pywin32 created the IRobotApplication.py file in C:\Users\<user_name>\AppData\Local\Temp\gen_py\3.11\F3A37BD0-AA2D-11D2-9844-0080C86BE4DFx0x1x0. More to come on all this as I research it all again.
The print(rsa.__module__) line outputs win32com.gen_py.F3A37BD0-AA2D-11D2-9844-0080C86BE4DFx0x1x0.IRobotApplication
RSA Pro is launched, but not visible. rsa.Visible = True renders the application to the screen.
The console may very well close automatically, so the _ = input("Press ENTER to quit:") allows us to pause and admire our work.
Finally, calling rsa.Quit(0) closes the application. An IRobotQuitOption, despite its name, is required. The API documentation lists three options. The enums are self-explanatory:
I_QO_DISCARD_CHANGES = 0
I_QO_PROMPT_TO_SAVE_CHANGES = 1
I_QO_SAVE_CHANGES = 2
Resources:
[https://pypi.org/project/pywin32/] [https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Where-can-be-found-SDK-package-for-Robot-Structural-Analysis-2021.html]