3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

How can I select all surfaces(Faces) that I made script?

    • Jimmy
      Subscriber

      I want to use "select.xxx", or other script to chose all surfaces and extrude them. How can I use "select script" properly? select.SelectAll() doesn't work. 

      Python Script, API Version = V23

      import math

      B_W=Parameters.Block_Width
      B_L=Parameters.Block_Length

      r=Parameters.Block_radius
      thickness=Parameters.Block_extrusion

      circular_radius = MM(r)*1000  
      circle_pitch = MM(r) * 3 * 1000  

      start_x = -B_W/2+circle_pitch/2
      start_z = -B_L/2+circle_pitch/2

      num_circles_x=int(math.ceil(B_W/circle_pitch))
      num_circles_z=int(math.ceil(B_L/circle_pitch))

      surfaces=[]

      for i in range(num_circles_z): 
          for j in range(num_circles_x): 
               circle_x=start_x + j*circle_pitch
               circle_z=start_z + i*circle_pitch
               circle = CircularSurface.Create(r, Direction.DirY,
                                         Point.Create(circle_x, 0, circle_z))
               surfaces.append(circle)

      selection = Selection.Create(FaceSelection.SelectAll())

      options = ExtrudeFaceOptions()
      options.ExtrudeType = ExtrudeType.Add
      result = ExtrudeFaces.Execute(selection, thickness, options)

       

    • mjmiddle
      Ansys Employee

      The format of the following command is incorrect:

      selection = Selection.Create(FaceSelection.SelectAll())

      The FaceSelection() function already creates a selection type, so just do:

      selection = FaceSelection.SelectAll()

      Also, for later use, you'll want to get the DesignBody or DesignFace from the CircularSurface() function:

      circlebody = circle.CreatedBodies[0]

      circleface = circle.CreatedBodies[0].Faces[0]

       

    • Jimmy
      Subscriber

      Thank you very much indeed. But I still have an error message below,

      'Selection must be a Face.' in result = ExtrudeFaces.Execute(selection, thickness, options)

      seclection=FaceSelection.SelectAll() means surface selection as Face? Or is there any method to change surface to Face?

    • mjmiddle
      Ansys Employee

      You can see what you have by running the following:

      for geom in selection.Items:
          print str(geom.GetType())

      It looks the SelectAll() method under the FaceSelection class just selects all objects. It does not just select only DesignFace type. You could loop through all bodies and faces and build a list of faces. But it seems your script is supposed to operate on the circle you just created, so why not just use what the CircularSurface.Create() just created?:

      circle = CircularSurface.Create(r, Direction.DirY, Point.Create(circle_x, 0, circle_z)
      circleface = circle.CreatedBodies[0].Faces[0]
      surfaces.append(circleface)

      Once the loop is done:
      selection = Selection.Create(surfaces)

    • Jimmy
      Subscriber

      Thank you very much indeed. 

Viewing 4 reply threads
  • The topic ‘How can I select all surfaces(Faces) that I made script?’ is closed to new replies.