How to merge/combine named selections in Mechanical using scripting?

Erik Kostson
Erik Kostson Member, Moderator, Employee Posts: 257
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited November 18 in Structures

Say we have 2 named selections (called say NS1 and NS2), how can we use scripting to merge them or combine them into one named selection?

Best Answer

  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 257
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited November 18 Answer ✓

    There are many ways of doing this (e.g., using the WS via Mech. Scripting).

    Another possible solution is presented below:

    model = ExtAPI.DataModel.Project.Model
    analysis=model.Analyses[0]
    ns1=ExtAPI.DataModel.GetObjectsByName("NS1")[0]
    ns2=ExtAPI.DataModel.GetObjectsByName("NS2")[0]
    
    nId1=ns1.Location.Ids
    nId2=ns2.Location.Ids
    
    nIdtot=[]
    
    for nd1,nd2 in zip(nId1, nId2):
        nIdtot.append((nd1))
        nIdtot.append((nd2))
    
    ns3=model.AddNamedSelection()
    selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    selection.Ids=nIdtot
    ns3.Location=selection