Standalone IronPython
In general, it is easier to run a script directly from Electronics Desktop. Standalone IronPython does not implement all the functionality available when a script is run from Electronics Desktop. It only implements full support for COM functions.
Running Standalone IronPython
Standalone IronPython uses COM to get the handle to the AnsysEDT app. To run standalone IronPython, you’ll need to call the IronPython interpreter ipy64.exe.
It is located in:
\\<AnsysEDTInstallationPath>\common\IronPython\ipy64.exe
For example, to run myScript.py, type the following in the command line:
"C:\Program Files\AnsysEM\v242\Win64\common\IronPython\ipy64.exe" "<filePath>\myScript.py"
You can set the interpreter to be the default program when double-clicking the .py script. You can use any recorded script as the basis for a standalone script and simply add an installation-internal path to the python module search path (as shown below) and end the script with a new shutdown call.
Using a Recorded Script
A python script recorded in AnsysEDT already has the required lines to be run as a standalone, except for the first two lines (path settings) and the final Shutdown() call. See the example script below.
Creating an External Script
When creating a script outside of Electronics Desktop, the following lines should be included at the beginning of your script:
import sys# Imports the sys module containing system-specific functions native to IronPython.
sys.path.append("<InstallationPath>")# Adds the Electronics Desktop installation path to the list of directories Python searches for modules and files.
sys.path.append("<InstallationPath>/PythonFiles/DesktopPlugin")# Adds the PythonFiles/DesktopPlugin subfolder to the list of directories Python searches for modules and files.
import ScriptEnv# This imports ScriptEnv.py from the installation path specified above. ScriptEnv.py performs an operating system check and defines functions used in Electronics Desktop scripts. See the annotations in the ScriptEnv.py file for more information.
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")or
ScriptEnv.InitializeNew(NonGraphical=True)#
InitializeandInitializeNeware functions within ScriptEnv.py. The first option launches Electronics Desktop. The second allows you to run a script without launching Electronics Desktop. See the annotations in the ScriptEnv.py file for more information.
You must end the script with:
ScriptEnv.Shutdown()# This stops ScriptEnv.py. If you are running multiple scripts, include this only at the end of the last script.
Example Script
import sys
sys.path.append(r"C:\Program Files\AnsysEM\v242\Win64")
sys.path.append(r"C:\Program Files\AnsysEM\v242\Win64\PythonFiles\DesktopPlugin")
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()
oProject.InsertDesign("HFSS", "HFSSDesign1", "DrivenModal", "")
oDesign = oProject.SetActiveDesign("HFSSDesign1")
oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.CreateRectangle(
[
"NAME:RectangleParameters",
"IsCovered:= ", True,
"XStart:= ", "-0.2mm",
"YStart:= ", "-3mm",
"ZStart:= ", "0mm",
"Width:= ", "0.8mm",
"Height:= ", "1.2mm",
"WhichAxis:= ", "Z"
],
[
"NAME:Attributes",
"Name:= ", "Rectangle1",
"Flags:= ", "",
"Color:= ", "(132 132 193)",
"Transparency:= ", 0,
"PartCoordinateSystem:=", "Global",
"UDMId:= ", "",
"MaterialValue:= ", "\"vacuum\"",
"SolveInside:= ", True
])
oDesign.SetDesignSettings(['NAME:Design Settings Data', 'Allow Material Override:=', True, 'Calculate Lossy Dielectrics:=', True])
oEditor.SetModelUnits(['NAME:Units Parameter', 'Units:=', 'mil', 'Rescale:=' , False ])
ScriptEnv.Shutdown()