How can we create named selections containing the parts that have the same material

Erik Kostson
Member, Moderator, Employee Posts: 287
✭✭✭✭
We have an assembly of parts that have different material assignments. How can we create named selections where every named selection (ns) contains only parts with the same material assignment. So say one ns will have all parts with a Structural Steel assignment, while the another ns will have all parts with a Copper material assignment etc.
0
Comments
-
The sample code below shows one possible way of doing this via mechanical scripting:
model = ExtAPI.DataModel.Project.Model materials=model.Materials.Children Parts = model.Geometry.GetChildren(DataModelObjectCategory.Part,True) selId = [] SlMn = ExtAPI.SelectionManager SlMn.ClearSelection() Sel = SlMn.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) for mat in materials: for Part in Parts: PName = Part.Name print(PName) for Body in Part.Children: Bmatname = Body.Material if mat.Name == Bmatname: BId = Body.GetGeoBody().Id selId.append(BId) Sel.Ids=selId ns=model.AddNamedSelection() ns.Location=Sel ns.Name=mat.Name selId=[] SlMn.ClearSelection()
0
This discussion has been closed.