Send command from WB ACT Console to Space Claim ACT Console

IhorL
IhorL Member Posts: 7
Name Dropper First Comment
edited March 17 in 3D Design

Hi :smile:

I faced an issue with how to send commands from Workbench to SpaceClaim.
I want to send a command from the Workbench ACT console to the Space Claim console to build geometry. I am using the next code but nothing is happening in the Space Claim.

staticSys = GetTemplate(TemplateName = "Static Structural", Solver = "ANSYS").CreateSystem()
staticSys.DisplayText = "Model"

geomCont = staticSys.GetContainer(ComponentName = "Geometry")
geomCont.Edit(IsSpaceClaimGeometry = True, Interactive = True)


cmd = """

import clr
clr.AddReference("SpaceClaim.Api.V20")
from SpaceClaim.Api.V20 import *

sectionPlane = Plane.PlaneZX
result = ViewHelper.SetSketchPlane(sectionPlane, Info4)

point = Point2D.Create(MM(0), MM(0))
result = SketchPoint.Create(point)

baseSel = SelectionPoint.Create(CurvePoint2)
targetSel = SelectionPoint.Create(DatumPoint2)

result = Constraint.CreateCoincident(baseSel, targetSel)

mode = InteractionMode.Solid
result = ViewHelper.SetViewMode(mode, Info5)

"""

geomCont.SendCommand(Language = "Python", Command = cmd)

BR Ihor

Comments

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 794
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

    Hi @IhorL , to debug this I would take the following steps:

    • Does the SpaceClaim script work in SpaceClaim?
    • Do you get any error message in the ACT log file when launching the script from WB?
    • Check that cmd string formatting is correct (issues can occur when converting commands to strings".

    I'm also sharing below an example of ACT Wizard that shows two ways of creating the SpaceClaim geometry from WB.

    • .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>
    
    • 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()
    
    • myDemoScript.py file:
    # Python Script, API Version = V17
    ClearAll()
    diameter=[10,30,20,40,60]
    length=[50,75,25,10,60]
    for i in range(len(diameter)):
        myCenterBottom=Point.Create(0,sum(length[:i])-length[0],0)
        myCenterTop=Point.Create(0,sum(length[:i])-length[0]+length[i],0)
        myDragPoint=Point.Create(diameter[i]/2.,sum(length[:i])-length[0]+length[i],0)
        CylinderBody.Create(myCenterBottom,myCenterTop,myDragPoint,ExtrudeType.ForceIndependent)
    ViewHelper.ZoomToEntity()
    

    Hope this helps.

  • IhorL
    IhorL Member Posts: 7
    Name Dropper First Comment
    edited March 15

    Hi @Pernelle Marone-Hitz, yes it works in the SC and I have no error, just nothing is happening. Thank you for the script example I will look into it :smile:

  • IhorL
    IhorL Member Posts: 7
    Name Dropper First Comment
    edited March 15

    Ok, now I understand what is wrong, kek :wink:
    @Pernelle Marone-Hitz thank you for your script. Looking through it I wondered why you have to send commands line by line and then I realized.
    I tried to send commands at once using one sending command, but what I should do is decompose the script by lines and send each line separately.

    Below I put the updated script, the most important part is the two last lines:

    myTemplate = GetTemplate(TemplateName="Static Structural",Solver="ANSYS")
    mySystem = myTemplate.CreateSystem()
    myGeometry = mySystem.GetContainer(ComponentName="Geometry")
    myGeometry.Edit(IsSpaceClaimGeometry=True)

    cmd = """

    selection = BodySelection.Create(GetRootPart().Bodies)
    try:
    result = Delete.Execute(selection)
    except:
    pass

    plane = Plane.PlaneZX
    result = ViewHelper.SetSketchPlane(plane)
    origin = Point2D.Create(MM(0), MM(0))
    result = SketchCircle.Create(origin, MM(20))

    mode = InteractionMode.Solid
    result = ViewHelper.SetViewMode(mode, None)

    selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[0])
    options = ExtrudeFaceOptions()
    options.ExtrudeType = ExtrudeType.Add
    result = ExtrudeFaces.Execute(selection, MM(35), options)

    """

    for line in cmd.splitlines():
    myGeometry.SendCommand(Language="Python", Command=line)

  • IhorL
    IhorL Member Posts: 7
    Name Dropper First Comment
    edited March 17

    @Pernelle Marone-Hitz thank you for the example. I understand what is wrong. I tried to send the whole Space Claime script, but I should decompose it by lines and send lines one by one. You can find below the updated part, the last two lines are the solution.

    myTemplate = GetTemplate(TemplateName="Static Structural",Solver="ANSYS")
    mySystem = myTemplate.CreateSystem()
    myGeometry = mySystem.GetContainer(ComponentName="Geometry")
    myGeometry.Edit(IsSpaceClaimGeometry=True)
    
    cmd = """
    
    selection = BodySelection.Create(GetRootPart().Bodies)
    try:
                  result = Delete.Execute(selection)
    except:
                  pass
    
    plane = Plane.PlaneZX
    result = ViewHelper.SetSketchPlane(plane)
    origin = Point2D.Create(MM(0), MM(0))
    result = SketchCircle.Create(origin, MM(20))
    
    mode = InteractionMode.Solid
    result = ViewHelper.SetViewMode(mode, None)
    selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[0])
    options = ExtrudeFaceOptions()
    options.ExtrudeType = ExtrudeType.Add
    result = ExtrudeFaces.Execute(selection, MM(35), options)
    
    """
    
    for line in cmd.splitlines():
                  myGeometry.SendCommand(Language="Python", Command=line)