Sample Q3D Extractor Script
Following is an example Q3D Extractor script. It includes comment lines, preceded by either an apostrophe or the word REM, that offer explanations for each preceding line or lines. VBScript keywords appear in bold.
Dim oAnsoftApp
Dim oDesktop
Dim oProject
Dim oDesign
Dim oEditor
Dim oModule
REM Dim is used to declare variables and means dimension. In VBScript you can use Dim, REMPublic, or Private to declare variables. As VBScript has no built-in data types (like REMinteger, string, etc.), all variables are treated as variants, which can store any type of REM information. In this example, the three variables will be used as objects. When REM recording scripts in Q3D Extractor, variants that will be used as objects always begin with 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 and it ’ returns an object. The object is assigned to the variable oDesktop.
oDesktop.NewProject
’ In VBScript, a Sub procedure is a procedure that is called by name, can 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 "Q3D Extractor", "Q3DDesign1", "", ""
’ In a Sub or Function procedure call, you can group the input parameters inside ’ parentheses or without parentheses. Here the four strings are the input parameters of ’ the Sub procedure InsertDesign of the object oProject.
Set oDesign = oProject.SetActiveDesign("Q3DDesign1")
Set oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.CreateBox Array("NAME:BoxParameters", "XPosition:=", _
"0mm", "YPosition:=", "0mm", "ZPosition:=", "0mm", _
"XSize:=", "1.6mm", "YSize:=", "1.2mm", "ZSize:=", _
"0.8mm"), Array("NAME:Attributes", "Name:=", "Box1", "Flags:=", _
"", "Color:=", "(132 132 193)", "Transparency:=", _
0.400000005960464, "PartCoordinateSystem:=", _
"Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
’ oEditor.CreateBox is a Sub procedure that takes two array variables as input. The ’ first array is for the box’s geometric parameters, and the second array is for the box’s ’ attributes. You can modify the italicized entries to create a different box. In VBScript, ’ Array is a function that returns a variant containing an array. The underscore ’ character ( _ ) here indicates that the statement continues to the next line. The ’ underscore character must be placed outside of string constants, or else VBScript ’ recognizes the character as part of the string constant rather than an indication that the ’ string continues on the next line. Following is an example of proper use of the underscore ’ character:
’ Msgbox("Please include units when creating variables " & _
’ "that require dimensions."
’ Following is an example of improper use of the underscore character:
’ Msgbox("Please include units when creating variables _
’ that require dimensions."
For additional Ansys Electronics Desktop script examples, see Example Scripts.