Facing Issues When Importing a Python script into the Main Python Script
I am new to programming and I am creating an app using ANSYS ACT.
My ExportImage script works well when I connect it directly to the XML file. However, if I run the same ExportImage.py file through MainScript.py, and MainScript is connected to the XML, then I encounter the following error.
Error when invoking function 'exportimage'.
Traceback (most recent call last):
File "C:\Users\AppData\Roaming\Ansys\v212\ACT\extensions\report\MainScript.py", line 14, in exportimage
File "C:\Users\AppData\Roaming\Ansys\v212\ACT\extensions\report\ExportImage.py", line 25, in exportimage
StandardError: Exception has been thrown by the target of an invocation.
Traceback (most recent call last):
File "C:\Users\AppData\Roaming\Ansys\v212\ACT\extensions\report\MainScript.py", line 14, in exportimage
File "C:\Users\AppData\Roaming\Ansys\v212\ACT\extensions\report\ExportImage.py", line 25, in exportimage
NameError: global name 'Ansys' is not defined
Also, same connectivity I verified with using by message box and it is working fine.
Please help me resolve this error.
Thank you in advance.
Answers
-
Option 1:
from __main__ import *
But this may cause overwrites of local variables in ExportImage.py
Althernatively, you may need to copy the contents from (or otherwise run) \Addins\ACT\apisMechanical.py
For example:
C:\Program Files\ANSYS Inc\v241\Addins\ACT\apis\Mechanical.pyIn your case, you may just need the contents of Mechanical_Lite.py in the same directory.
0 -