Anda di halaman 1dari 6

9.

10

Maxwell v15

Basic Exercises Scripting


Scripting the Creation of a Model Object
This exercise will discuss how to record, modify and run a script for automating
generation of a circle. The following tasks will be performed:
Record a script in which a circle is created.
Modify the script to change the circles radius and height.
Run the modified script.

Create Design
To Create Design
Select the menu item Project > Insert Maxwell 2D Design, or click on the
icon

Save Project
To Save Project
Select the menu item File > Save
Save the file with the name Ex_9_10_BasicScripting2D.mxwl

ANSYS Maxwell 2D Field Simulator v15 Users Guide

9.10-#

9.10

Maxwell v15

Basic Exercises Scripting


Record Script
To Start Script Recording
Select the menu item Tools > Record Script To File
Save the script file with the name Ex_9_10_BasicScripting2D.vbs

Draw Circle
To Draw a Circle
Select the menu item Draw > Circle
1. Using the coordinate entry fields, enter the center of circle
X: 0, Y: 0, Z: 0, Press the Enter key
2. Using the coordinate entry fields, enter the radius
dX: 1, dY: 0, dZ: 0, Press the Enter key

Stop Script Recording


To Stop the Script Recording
Select the menu item Tools > Stop Script Recording

Delete Circle
To Delete the Circle
Select the sheet Circle1 from history tree
Select the menu item Edit > Delete

Run the Script


To Run Recorded Script
Select the menu item Tools > Run Script
Browse to the location of the script file and Open it
If successful, the original circle, Circle1, should be back.
We can now explore the contents of the script file.

ANSYS Maxwell 2D Field Simulator v15 Users Guide

9.10-#

Maxwell v15

9.10
Basic Exercises Scripting

Script Content
To open the Script in Editor
Locate the file on the Hard Disk and open it with Text Editor (say Textpad)
' ---------------------------------------------' Script Recorded by Ansoft Maxwell Version 15.0.0
' 10:23:17 PM Dec 18, 2011
' ---------------------------------------------Dim oAnsoftApp
Dim oDesktop
Dim oProject
Dim oDesign
Dim oEditor
Dim oModule
Set oAnsoftApp = CreateObject("AnsoftMaxwell.MaxwellScriptInterface")
Set oDesktop = oAnsoftApp.GetAppDesktop()
oDesktop.RestoreWindow
Set oProject = oDesktop.SetActiveProject("Ex_9_10_BasicScripting2D")
Set oDesign = oProject.SetActiveDesign("Maxwell2DDesign1")
Set oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.CreateCircle
Array("NAME:CircleParameters",
"IsCovered:=",
true,
"XCenter:=", _ "0mm", "YCenter:=", "0mm", "ZCenter:=", "0mm", "Radius:=",
"1mm", "WhichAxis:=", _ "Z", "NumSegments:=", "0"), Array("NAME:Attributes",
"Name:=", "Circle1", "Flags:=",
_
"", "Color:=", "(132 132 193)",
"Transparency:=", 0.25, "PartCoordinateSystem:=", _ "Global", "UDMId:=", "",
"MaterialValue:=", "" & Chr(34) & "vacuum" & Chr(34) & "", "SolveInside:=", _
true)

ANSYS Maxwell 2D Field Simulator v15 Users Guide

9.10-#

Maxwell v15

9.10
Basic Exercises Scripting

Definition of environment variables


Dim is the generic visual basic variable type.
' ---------------------------------------------' Script Recorded by Ansoft Maxwell Version 15.0.0
' 10:23:17 PM Dec 18, 2011
' ---------------------------------------------Dim oAnsoftApp
Dim oDesktop
Dim oProject
Dim oDesign
Dim oEditor
Dim oModule
Reference defined environment variables
Defined using Set.
Set oAnsoftApp = CreateObject("AnsoftMaxwell.MaxwellScriptInterface")
Set oDesktop = oAnsoftApp.GetAppDesktop()
oDesktop.RestoreWindow
Set oProject = oDesktop.SetActiveProject("Ex_9_10_BasicScripting2D")
Set oDesign = oProject.SetActiveDesign("Maxwell2DDesign1")
Set oEditor = oDesign.SetActiveEditor("3D Modeler")
oAnsoftApp
The oAnsoftApp object provides a handle for VBScript to access Maxwell
oDesktop
The oDesktop object is used to perform desktop-level operations, including project
management.
oProject
The oProject object corresponds to one project open in the product. It is used to
manipulate the project and its data.
oDesign
The oDesign object corresponds to an instance of a design in the project.
oEditor
The oEditor object corresponds to an editor, such as the 3D Modeler. This object is
used to add and modify data in the editor.

ANSYS Maxwell 2D Field Simulator v15 Users Guide

9.10-#

9.10

Maxwell v15

Basic Exercises Scripting


Circle Creation
All of the parameters needed to create the circle are defined in this line of
code. Here we will modify the Radius of the circle by changing the
appropriate text.
oEditor.CreateCircle Array("NAME:CircleParameters", "IsCovered:=", true,
"XCenter:=", _ "0mm", "YCenter:=", "0mm", "ZCenter:=", "0mm",
"Radius:=", "1mm", "WhichAxis:=", _ "Z", "NumSegments:=", "0"),
Array("NAME:Attributes", "Name:=", "Circle1", "Flags:=", _ "", "Color:=",
"(132 132 193)", "Transparency:=", 0.800000011920929,
"PartCoordinateSystem:=", _ "Global", "UDMId:=", "", "MaterialValue:=", ""
& Chr(34) & "vacuum" & Chr(34) & "", "SolveInside:=", _ true)

Modify Script
Locate the line containing the Radius and change the numerical values to
5mm:
"Radius:=", "1mm", "WhichAxis:=", _ "Z",
"Radius:=", 5mm", "WhichAxis:=", _ "Z",
Save the file and return to Maxwell.

Delete Circle
To Delete the Circle
Select the sheet Circle1 from history tree
Select the menu item Edit > Delete

ANSYS Maxwell 2D Field Simulator v15 Users Guide

9.10-#

9.10

Maxwell v15

Basic Exercises Scripting


Run the Script
To Run Recorded Script
Select the menu item Tools > Run Script
Browse to the location of the script file and Open it
If successful, the original circle, Circle1, should be back.

Generalize the script to run in any Project and Design


To run the script in order to create your circle in a different project. Change the
following lines in the script.
Set oProject = oDesktop.SetActiveProject("scripting_example")
Set oDesign = oProject.SetActiveDesign("MaxwellDesign1")
Set oProject = oDesktop.GetActiveProject()
Set oDesign = oProject.GetActiveDesign()

ANSYS Maxwell 2D Field Simulator v15 Users Guide

9.10-#

Anda mungkin juga menyukai