Identify bodies in named selections and make dedicated named selections for each

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 741
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

I would like to have named selections for each body from given named selection, how can this be achieved through scripting?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 741
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓

    The following code can be used:

    named_selections=ExtAPI.DataModel.Project.Model.NamedSelections # reference Named Selection section in the tree
    main_NS = ExtAPI.DataModel.GetObjectsByName("main_NS")[0] # Get NS called "main_NS"
    for bodyId in main_NS.Ids: # loop on bodies in main_NS
        new_NS = named_selections.AddNamedSelection() # create new NS
        new_NS.Name = "new_NS_object_" + str(bodyId) # change name of NS
        temp_sel=ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) # define a temporary selection
        temp_sel.Ids = [bodyId] # set Ids for temporary selection
        new_NS.Location = temp_sel # assign temporary selection