A Sample Circuit Script
Following is an example of a Circuit script. It includes comment lines, which are preceded by either an apostrophe ( ’ ) or the word REM, that offer explanations for each preceding line or lines. VBScript keywords appear in bold font.
Dim oAnsoftApp
Dim oDesktop
Dim oProject
Dim oDesign
Dim oEditor
Dim oModule
REM Dim is used to declare variables. Dim means dimension. In VBScript you can use Dim,
REM Public, or Private to declare variables. As VBScript has no built-in data types (like,
REM integer, string, etc.) all variables are treated as variants, which can store any type of
REM information. In this example, the variables will be used as objects. When recording
REM scripts in the Ansys Electronics Desktop application, variants that will be used as objects always begin with
REM the letter o.
Set oAnsoftApp = CreateObject("Ansoft.ElectronicsDesktop")
You can use Set to assign an object reference to a variable. A copy of the object is ‘not created for that variable. Here, CreateObject is a function that takes a string as input and returns an object. The object is assigned to the variable oAnsoftApp.
Set oDesktop = oAnsoftApp.GetAppDesktop()
‘GetAppDesktop is a function of oAnsoftApp. This function does not take an input
‘but returns an object that is then assigned to the variable oDesktop.
oDesktop.RestoreWindow
oDesktop.NewProject
‘In VBScript a Sub procedure is a procedure that is called by name, can optionally
‘receive arguments, and can perform a specific task with a group of statements.
‘Here the Sub procedure NewProject of the object oDesktop is called.
‘This Sub does not take an input.
Set oProject = oDesktop.GetActiveProject
oProject.InsertDesign "HFSS 3D Layout", "HFSS 3D Layout1", _
"C:\Program Files\ANSYS Inc\v251\AnsysEM\syslib\PCB - SingleSided.asty", ""
‘In a Sub or Function procedure call, you can group the input parameters inside
‘parentheses or without parentheses. Here the four strings are input parameters
‘of the Sub procedure InsertDesign of the object oProject.
Set oDesign = oProject.SetActiveDesign("HFSS 3D Layout1")
Set oEditor = oDesign.SetActiveEditor("Layout")
oEditor.CreateRectangle Array("NAME:Contents", "rectGeometry:=", Array("Name:=", _
"rect_1", "LayerName:=", "Top", "lw:=", "0mm", "Ax:=", "-22mm", "Ay:=", "20mm", "Bx:=", _
"29mm", "By:=", "-4mm", "ang:=", "0deg"))
‘oEditor.CreateRectangle is a Sub procedure that takes an array variable
‘as an argument. This array variable contains two string variables and an array
‘containing the geometric parameters of the rectangle. You can use variables to
‘modify the geometric parameters of the rectangle.
‘In VBScript Array is a function that returns a variant containing an array. The
‘underscore character (_) here indicates that the statement continues on the next line.
‘The underscore character must be placed outside of string constants, or else VBScript
‘will recognize the character as part of the string constant rather than an indication that the
‘string continues on the next line.
‘The following is an example of proper use of the underscore character. An ampersand (&) is used to concatenate two strings into one larger string:
‘ MsgBox("Please include units when creating variables" & _
‘ "that require dimensions.")
‘The following is an example of improper use of the underscore character. A single string cannot be split across two lines:
‘ MsgBox("Please include units when creating variables _
‘ that require dimensions.")
oProject.SaveAs "C:\Program Files\ANSYS Inc\v251\AnsysEM\Examples\test.adsn", true