-
-
August 28, 2019 at 12:46 pm
Mike3000
Subscriber
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 am
Mike3000
SubscriberMeanwhile, 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 3, 2019 at 2:25 pm
Rob
Ansys EmployeeThanks 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.
-
- You must be logged in to reply to this topic.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- Saving & sharing of Working project files in .wbpz format
- An Unknown error occurred during solution. Check the Solver Output…..
- Understanding Force Convergence Solution Output
- Solver Pivot Warning in Beam Element Model
- Colors and Mesh Display
- How to calculate the residual stress on a coating by Vickers indentation?
- whether have the difference between using contact and target bodies
- What is the difference between bonded contact region and fixed joint
- The solver engine was unable to converge on a solution for the nonlinear problem as constrained.
- User manual
-
2524
-
2066
-
1285
-
1096
-
459
© 2023 Copyright ANSYS, Inc. All rights reserved.