I have some Named Selections and want to know what type of Geometry scoping each of them has; for example, body, face, edge, or vertex? How can I do this with Mechanical Scripting?
A Named Selection has an .Entities property which includes the GeoWrappers of the scoped geometries. You can check the .Type of each entity and issue a condition to see what type of scoping the Named Selection has. It is sufficient to select the first of the entities listed under the Named Selection, since each Named Selection can only be scoped to a specific type of entity. For example, if 'ns' is a Named Selection object scoped to two faces, then:
>>> ns.Entities [Ansys.ACT.Common.Geometry.GeoFaceWrapper, Ansys.ACT.Common.Geometry.GeoFaceWrapper] >>> ns.Entities[0].Type GeoFace >>> ns.Entities[0].Type.ToString() 'GeoFace'
A script that you can use for all the Named Selections is:
for ns in DataModel.Project.Model.NamedSelections.Children: ns_entitites = ns.Entities if ns_entitites: ns_type = ns_entitites[0].Type # Selecting the 1st NS entity if ns_type.ToString() == 'GeoBody': print('NS '+ ns.Name + ' is a Body.') elif ns_type.ToString() == 'GeoFace': print('NS '+ ns.Name + ' is a Face.') elif ns_type.ToString() == 'GeoEdge': print('NS '+ ns.Name + ' is an Edge.') elif ns_type.ToString() == 'GeoVertex': print('NS '+ ns.Name + ' is a Vertex.') else: print('Not recognized geometry type.') else: print('Not recognized geometry type.')