How can we a create 2 named selections of bodies with and without el. resistivity defined?

Erik Kostson
Erik Kostson Member, Moderator, Employee Posts: 335
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited May 23 in Structures

Say we have some bodies that use material properties that do not have an electrical resistivity, and some that has this property defined (in engineering data). Can we via mechanical scripting create a named selection for all the bodes that have it and one for bodies that do not have any electrical resistivity defined?

Best Answer

  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 335
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited May 23 Answer ✓

    Below is one way of doing this:

    import materials
    Idsthel = []
    Idsth = []
    with Transaction():
        bodies = ExtAPI.DataModel.Project.Model.GetChildren(DataModelObjectCategory.Body,True) # create list with all bodies in the Mechanical tree
        for body in bodies: #  loop on all bodies in Mechanical Tree
            #print(body.Name) #  print body name
            geo_body = body.GetGeoBody() #  get GeoData of this current body
            material = geo_body.Material #  access material class for this geo body
            #print(materials.GetListMaterialProperties(material)) #  print material properties defined for this body
            properties = materials.GetMaterialPropertyByName(material,"Resistivity") #  list values for Elasticity property
            if properties==None:
                Idsth.append(geo_body.Id)
            else:
                Idsthel.append(geo_body.Id)
    
    
    if len(Idsthel)!=0:
        named_selection = Model.AddNamedSelection()
        selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
        selection.Ids = Idsthel
        named_selection.ScopingMethod=GeometryDefineByType.Geometry
        named_selection.Location = selection
    
    
    ExtAPI.SelectionManager.ClearSelection()
    
    
    if len(Idsth)!=0:
        named_selection = Model.AddNamedSelection()
        selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
        selection.Ids = Idsth
        named_selection.ScopingMethod=GeometryDefineByType.Geometry
        named_selection.Location = selection
    
    
This discussion has been closed.