3D Design

3D Design

Remove Region Based on python script

    • satri
      Subscriber

      Suppose I have a model like this

      Whose edge IDs are 5,6,7

      suppose i want to remove the region inside edge 6 and edge 7.

      If i use the GUI i would go to Design->Split Body and select edge 6 and click on the region marked as 'X' in the above figure.

      Suppose i want to do that with python script how can i do this?

       

      Note:

      I tried to generate the code inside space claim and i got this

      selection = BodySelection.Create(GetRootPart().Bodies[1])
      result = Combine.RemoveRegions(selection)

      based on the code what i understand is it selected body 1 and deleted the selection.

      suppose i want to just run the code and delete the region of circle 7 i don't think this will work because i don't know the following information

      which edge to pick and which region of the edge do i pick to delete. So i don't know how to achieve this programmatically using the API. Please let me know how to achieve this?

       

       

    • mjmiddle
      Ansys Employee

      I see you are using the Combine tool and seleting a body so edge selection is not involved. The RemoveRegions() method is done as the second part of a Combine operation that intersected some bodies. The is the same as just deleting a body after the intersection. A big challenge with scripting, which determines ultimately whether a process can be scripted or not is whether selections can be done without a graphical interface.

      One way to handle this is to place edge/bodies/faces/vertices into named selections before the script runs, and the script will get entities in the named selections. Another way, which can sometimes get the desired entities in simple models, is to get based on a min/max XYZ value. You can get a bounding box or centroid of faces/edges/bodies and check XYZ values and only use those above or below a value you want. For vertices, you can get exact XYZ locations to check against min/max target values. You already know about the index method for selections, which is a type of selection by ID.

      Also, to make scripting robust, which guarantees the right selection after operations, is to get the return value of an operation and then contnue to operate on it. For the Combine.RemoveRegions() operation that you showed, this always happens after a Combine.Intersect(). So get the result bodies like this:

      targets = BodySelection.Create(GetRootPart().Bodies[0])
      tools = BodySelection.Create(GetRootPart().Bodies[2])
      options = MakeSolidsOptions()
      result = Combine.Intersect(targets, tools, options)
      newBodies = result.CreatedBodies
      selection = BodySelection.Create(newBodies)
      result = Combine.RemoveRegions(selection)

      Of course, you will have to get the original "targets" and "tools" bodies by some other method, such as index, named selection, max/min XYZ, or they may also be the result of a previous operation.

    • mjmiddle
      Ansys Employee

      Another method, when the result on an operation doesn't return anything useful, is to get a list of all bodies before an operation, then get a list after an operation, and loop through items comparing. Any items not in the first list are your new bodies. You can build a list and compare types directly. You don't need IDs. So you can directly compare DesignBody types, or DesignFaces, etc...

    • satri
      Subscriber

      I like the idea of using the named selection but i don't know how to execute that

      I don't think this will work directly because i have only one body

      targets = BodySelection.Create(GetRootPart().Bodies[0])
      tools = BodySelection.Create(GetRootPart().Bodies[2])

      for this to work i believe i need to have two bodies.

      I have a script that can create named selections for the edges.

      so lets say in the above example itself i create a named selection called group5, group6 and group7

      how would i go about this?

      I have only one body.

      I think this will be a clean process

      1. i will split the body based on the named selection of the edge
      2. Using the two bodies created bodies use the above commands you mentioned to remove the second body

      (targets = BodySelection.Create(GetRootPart().Bodies[0])
      tools = BodySelection.Create(GetRootPart().Bodies[2])
      options = MakeSolidsOptions()
      result = Combine.Intersect(targets, tools, options)
      newBodies = result.CreatedBodies
      selection = BodySelection.Create(newBodies)
      result = Combine.RemoveRegions(selection)

      do you think this workflow will enable me to achieve what I am trying to do?

      if this will work then the first question that i have is what commands do i use to split the body based on the named selection of the edges that will enable me to create two bodies. please let me know. 

Viewing 3 reply threads
  • You must be logged in to reply to this topic.