Standalone IronPython and Desktop IronPython

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:

You must end the script with:

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