-
-
August 28, 2019 at 12:46 pmMike3000Subscriber
What is the best way to assign items to a named selection in ACT?
I know how to browse through items (parts, bodies, etc.) in the structure tree. But it seems to me that it is not possible to assign an item, for example a body directly to a named selection. An intermediate step seems to be to gather items in a selection and then assign the contents of the selection to a named selection.
However, I do not manage to add the items to a selection programmatically. The methods NewSelection as well as AddSelection need an input argument of type ISelectionInfo but I do not know how to obtain this from the Items I am browsing.
Below is an example where I have tried to assign each part to a named selection.
#Model
model = ExtAPI.DataModel.Project.Model
# Get parts
Parts = model.Geometry.GetChildren(DataModelObjectCategory.Part,True)
# The procedure will be included in a loop later. Just using first part in test.
MyPart = Parts[0]
# Selection
SlMn = ExtAPI.SelectionManager
SlMn.ClearSelection()
#
>>> Missing part: Adding "MyPart" to current selection <<<
# SlMn.NewSelection()
# Create named selection
NSn = model.NamedSelections
MyNS = NSn.AddNamedSelection()
MyNS.Name = "Part0"
MyNS.Location = SlMn.CurrentSelection -
September 3, 2019 at 10:46 amMike3000Subscriber
Meanwhile, I created a solution myself. It creates named selections for every part and assigns the part name to the corresponding named selection.
# Selection
SlMn = ExtAPI.SelectionManager
SlMn.ClearSelection()
Sel = SlMn.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
#Model
model = ExtAPI.DataModel.Project.Model
# Get parts
Parts = model.Geometry.GetChildren(DataModelObjectCategory.Part,True)
print("Listing properties of Items:")
with Transaction(): Â Â Â Â Â Â Â Â Â # Suppress GUI update until finish to improve speed
   for Part in Parts:
      PName = Part.Name
      # print("Part name: ",PName)
     Â
      tmp_ls = []
      for Body in Part.Children:
         BName = Body.Name
         BId = Body.GetGeoBody().Id
         #print("Body name: "+BName+" ,BId: "+str(Id))
         tmp_ls.append(BId)                           # Collect all body Ids in temporary list
      # ExtAPI.SelectionManager.NewSelection(Sel)
      Sel.Ids = tmp_ls
      print("Sel.Ids: ",Sel.Ids)
      # Sel.Entities = [Body.GetGeoBody()]
      # Create named selection
      NSn = model.NamedSelections
      MyNS = NSn.AddNamedSelection()
      MyNS.Name = Part.Name
      MyNS.Location = Sel-
September 27, 2023 at 3:55 pma_l_oSubscriber
Hi Mike,
Thank you so much for your script! It helped me a lot, cheers to you for posting it.
Greets! a-l-o
-
-
September 3, 2019 at 2:25 pmRobForum Moderator
Thanks for posting the solution: we're very limited in how much coding support we're allowed to provide so always useful when users (and the wider community) can post answers.Â
-
September 28, 2023 at 7:40 amErik KostsonAnsys Employee
Thank you - closing this post.
Erik
-
- The topic ‘ACT Script: Assign items to a named selection’ is closed to new replies.
- Problem with access to session files
- Ayuda con Error: “Unable to access the source: EngineeringData”
- At least one body has been found to have only 1 element in at least 2 directions
- Error when opening saved Workbench project
- Geometric stiffness matrix for solid elements
- How to apply Compression-only Support?
- How to select the interface delamination surface of a laminate?
- Timestep range set for animation export
- Image to file in Mechanical is bugged and does not show text
- SMART crack under fatigue conditions, different crack sizes can’t growth
-
1216
-
543
-
523
-
225
-
209
© 2024 Copyright ANSYS, Inc. All rights reserved.