Maxwell
9.10
v15
BasicExercises – BasicExercises – Scripting Scripting ScriptingtheCreatio Scripting theCreationofaMode nofaModelObject lObject Thisexercisewilldiscuss Thisexercisewilldiscusshowtorecord, howtorecord,modifyandrun modifyandrunascriptforautomating ascriptforautomating generationofacircle.Thef generationofacircle.Thefollowingtasks ollowingtaskswillbeperformed: willbeperformed: Recordascriptinwhich Recordascriptinwhichacircleisc acircleiscreated. reated. Modifythescripttochange Modifythescripttochangethecircle’sr thecircle’sradiusandhei adiusandheight. ght. Runthemodifiedscript.
CreateDesign Selectthemenuitem icon
orclickonthe
SaveProject Selectthemenuitem Savethefilewiththename
9.10-‹#› 9.10-‹#›
Maxwell
9.10
v15
BasicExercises – Scripting RecordScript Selectthemenuitem Savethescriptfilewiththename
DrawCircle Selectthemenuitem 1.
Usingthecoordinateentryfields,enterthecenterofcircle X: ,Y: ,Z: ,Pressthe
2.
key
Usingthecoordinateentryfields,entertheradius dX: ,dY: ,dZ: ,Pressthe
key
StopScriptRecording Selectthemenuitem
DeleteCircle Selectthesheet
fromhistorytree
Selectthemenuitem
RuntheScript Selectthemenuitem Browsetothelocationofthescriptfileand Ifsuccessful,theoriginalcircle,
,shouldbeback.
Wecannowexplorethecontentsofthescriptfile.
9.10-‹#›
Maxwell
9.10
v15
BasicExercises – Scripting ScriptContent
LocatethefileontheHardDiskandopenitwithTextEditor(sayTextpad) '---------------------------------------------- 'ScriptRecordedbyAnsoftMaxwellVersion15.0.0 '10:23:17PMDec18,2011 '---------------------------------------------- DimoAnsoftApp DimoDesktop DimoProject DimoDesign DimoEditor DimoModule SetoAnsoftApp=CreateObject("AnsoftMaxwell.MaxwellScriptInterface") SetoDesktop=oAnsoftApp.GetAppDesktop() oDesktop.RestoreWindow SetoProject=oDesktop.SetActiveProject("Ex_9_10_BasicScripting2D") SetoDesign=oProject.SetActiveDesign("Maxwell2DDesign1") SetoEditor=oDesign.SetActiveEditor("3DModeler") 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)
9.10-‹#›
Maxwell
9.10
v15
BasicExercises – Scripting
isthegenericvisualbasicvariabletype. '---------------------------------------------- 'ScriptRecordedbyAnsoftMaxwellVersion15.0.0 '10:23:17PMDec18,2011 '---------------------------------------------- DimoAnsoftApp DimoDesktop DimoProject DimoDesign DimoEditor DimoModule Definedusing
.
SetoAnsoftApp=CreateObject("AnsoftMaxwell.MaxwellScriptInterface") SetoDesktop=oAnsoftApp.GetAppDesktop() oDesktop.RestoreWindow SetoProject=oDesktop.SetActiveProject("Ex_9_10_BasicScripting2D") SetoDesign=oProject.SetActiveDesign("Maxwell2DDesign1") SetoEditor=oDesign.SetActiveEditor("3DModeler")
TheoAnsoftAppobjectprovidesahandleforVBScripttoaccessMaxwell TheoDesktopobjectisusedtoperformdesktop-leveloperations,includingproject management. TheoProjectobjectcorrespondstooneprojectopenintheproduct.Itisusedto manipulatetheprojectanditsdata. TheoDesignobjectcorrespondstoaninstanceofadesignintheproject. TheoEditorobjectcorrespondstoaneditor,suchasthe3DModeler.Thisobjectis usedtoaddandmodifydataintheeditor.
9.10-‹#›
Maxwell
9.10
v15
BasicExercises – Scripting
Alloftheparametersneededtocreatethecirclearedefinedinthislineof code.Herewewillmodifythe ofthecirclebychangingthe appropriatetext. oEditor.CreateCircleArray("NAME:CircleParameters","IsCovered:=",true, "XCenter:=",_"0mm","YCenter:=","0mm","ZCenter:=","0mm", "WhichAxis:=",_"Z","NumSegments:=","0"), Array("NAME:Attributes","Name:=","Circle1","Flags:=",_"","Color:=", "(132132193)","Transparency:=",0.800000011920929, "PartCoordinateSystem:=",_"Global","UDMId:=","","MaterialValue:=","" &Chr(34)&"vacuum"&Chr(34)&"","SolveInside:=",_true)
Locatethelinecontainingthe :
andchangethenumericalvaluesto
"WhichAxis:=",_"Z", "WhichAxis:=",_"Z", SavethefileandreturntoMaxwell.
DeleteCircle Selectthesheet
fromhistorytree
Selectthemenuitem
9.10-‹#›
Maxwell
9.10
v15
BasicExercises – Scripting RuntheScript Selectthemenuitem Browsetothelocationofthescriptfileand Ifsuccessful,theoriginalcircle,
,shouldbeback.
GeneralizethescripttoruninanyProjectandDesign Torunthescriptinordertocreateyourcircleinadifferentproject.Changethe followinglinesinthescript. Set oProject = oDesktop. Set oDesign = oProject. Set oProject = oDesktop. Set oDesign = oProject.
9.10-‹#›