August 4, 2021 at 12:26 pm
Subscriber
a couple of things:
It looks like you're trying to use Python to execute the script. HFSS scripts are in IronPython, not Python. IronPython is compiled C# code, not C. It's syntactically identical to Python but with different modules. For example, there's no numpy or scipy in IronPython, but you do have access to the whole .NET framework which is powerful for app development. On the command line make sure you're executing IronPython, which can be found in the AnsysEM install directory: AnsysEM\AnsysEM21.1\Win64\ common\IronPython\ipy64.exe.
When you execute external scripts, make sure you append these 2 locations to your Python path: sys.path.append('path_to_install\\AnsysEM\\AnsysEM21.1\\Win64') and sys.path.append('path_to_install\\AnsysEM\\AnsysEM21.1\\Win64'\\PythonFiles\\DesktopPlugin'). The second location is where ScriptEnv.py is located.
When executing externally you need to include the year version number in the initialization statement.: ScriptEnv.Initialize("Ansoft.ElectronicsDesktop.2021.1"). Executed internally, EM Suite doesn't need the version, ScriptEnv.Initialize("Ansoft.ElectronicsDesktop") suffices, but you do need this in order to run externally.
After calling ScriptEnv.Initialize, you should have the oAnsoftApplication and oDesktop objects in your global scope.
Be sure to call the Shutdown function when your script exits in order to release the COM object. Otherwise your script will lock your instance of EM Suite for about 20 minutes (you won't be able to close the project). Shutdown() releases the COM object, and once it's released, it can't be obtained again by that IronPython process (not even on another thread). You will probably want to copy out the text from ScriptEnv.Shutdown and make your own shutdown function, as the default Shutdown() closes the application, and you don't want that.
It looks like you're trying to use Python to execute the script. HFSS scripts are in IronPython, not Python. IronPython is compiled C# code, not C. It's syntactically identical to Python but with different modules. For example, there's no numpy or scipy in IronPython, but you do have access to the whole .NET framework which is powerful for app development. On the command line make sure you're executing IronPython, which can be found in the AnsysEM install directory: AnsysEM\AnsysEM21.1\Win64\ common\IronPython\ipy64.exe.
When you execute external scripts, make sure you append these 2 locations to your Python path: sys.path.append('path_to_install\\AnsysEM\\AnsysEM21.1\\Win64') and sys.path.append('path_to_install\\AnsysEM\\AnsysEM21.1\\Win64'\\PythonFiles\\DesktopPlugin'). The second location is where ScriptEnv.py is located.
When executing externally you need to include the year version number in the initialization statement.: ScriptEnv.Initialize("Ansoft.ElectronicsDesktop.2021.1"). Executed internally, EM Suite doesn't need the version, ScriptEnv.Initialize("Ansoft.ElectronicsDesktop") suffices, but you do need this in order to run externally.
After calling ScriptEnv.Initialize, you should have the oAnsoftApplication and oDesktop objects in your global scope.
Be sure to call the Shutdown function when your script exits in order to release the COM object. Otherwise your script will lock your instance of EM Suite for about 20 minutes (you won't be able to close the project). Shutdown() releases the COM object, and once it's released, it can't be obtained again by that IronPython process (not even on another thread). You will probably want to copy out the text from ScriptEnv.Shutdown and make your own shutdown function, as the default Shutdown() closes the application, and you don't want that.