Example project page wizard to create geometry
Is there an demo extension of a project page wizard that creates create geometry in SpaceClaim?
Best Answer
-
An example extension is available in the post below.
This extension illustrates how to add a "Static Structural" component system to the WB project schematic and to define the geometry in SpaceClaim through script. This example has two steps to illustrate two possible methods of sending the python script to SpaceClaim:
In step 1, an assembly of several cylinders is created. This is done by calling function onupdateSCDM1(). In this function, RunScript() to send a Python script to SpaceClaim: myGeometry.RunScript(ScriptFile=myScriptGeometry, GeometryContainer="Geometry", useAsMacro="false") and myScriptGeometry is defined in the main.py as: myScriptGeometry = myInstallDir + "\geometry\myDemoScript.py"
In step 2,two cubes and a sphere are created. This is done by calling function onupdateSCDM2(). In this function, SendCommand() is used to send the python commands as strings to SpaceClaim.
2
Answers
-
Here is the code:
- For the .xml file:
<extension name="DemoWizardCreateGeometry" icon="images/demo_01.png" version="1"> <script src="main.py" /> <wizard name="demoWizardGeometry" caption="demoWizardGeometry" version="1" context="Project"> <step name="Geometry1" version="0" caption="SCDM - 1"> <property control="float" name="myDummyParameter" caption="myDummyParameter" default="1.0" /> <callbacks> <onupdate>onupdateSCDM1</onupdate> </callbacks> </step> <step name="myGeometry2" version="0" caption="SCDM - 2"> <property control="float" name="height" caption="height" default="0.4 [m]" unit="Length" /> <callbacks> <onupdate>onupdateSCDM2</onupdate> </callbacks> </step> </wizard> </extension>
- For the main.py file
myInstallDir = ExtAPI.Extension.InstallDir myScriptGeometry = myInstallDir + "\\geometry\\myDemoScript.py" def onupdateSCDM1(step): myTemplate = GetTemplate(TemplateName="Static Structural",Solver="ANSYS") mySystem = myTemplate.CreateSystem() myGeometry = mySystem.GetContainer(ComponentName="Geometry") myGeometry.Edit(IsSpaceClaimGeometry=True) myGeometry.RunScript(ScriptFile=myScriptGeometry, GeometryContainer="Geometry", useAsMacro="false") myGeometry.Exit() def myBlock(x1,x2,y1,y2,z1,z2): myCommand="""result = BlockBody.Create(Point.Create("""+str(x1)+""","""+str(y1)+""","""+str(z1)+"""), Point.Create("""+str(x2)+""","""+str(y2)+""","""+str(z2)+"""), ExtrudeType.ForceIndependent)""" return myCommand def onupdateSCDM2(step): myTemplate = GetTemplate(TemplateName="Static Structural",Solver="ANSYS") mySystem = myTemplate.CreateSystem() myGeometry = mySystem.GetContainer(ComponentName="Geometry") myGeometry.Edit(IsSpaceClaimGeometry=True) cmd=myBlock(-2,-1,-2,-1,-2,-1) myGeometry.SendCommand(Language="Python", Command=cmd) cmd=myBlock(0,1,0,1,0,step.Properties["height"].Value) myGeometry.SendCommand(Language="Python", Command=cmd) cmd="""myParameter=0.25""" myGeometry.SendCommand(Language="Python", Command=cmd) cmd="""SphereBody.Create(Point.Create(0,0,0), Point.Create(0,0,myParameter), ExtrudeType.ForceIndependent)""" myGeometry.SendCommand(Language="Python", Command=cmd) myGeometry.Exit()
0