Creating Named Selection with PyMechanical

srorf Member Posts: 2
Name Dropper First Comment

I'm trying to create a named selection in Ansys Mechanical. The face id's are given. But I don't know how to use the CreateSelectionInfo Method. According to API Documentation I should pass SelectionTypeEnum.GeometryEntities but I don't know how to import this Enum. How is the workflow to create a named selection with pyansys?

# Initialize the Mechanical app
app = App()

ExtAPI = app.ExtAPI
model = ExtAPI.DataModel.Project.Model
selection_manager = ExtAPI.SelectionManager

selection = selection_manager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) # Here is my problem because I can't import SelectionTypeEnum... 

selection.Ids = [1,2,3,4] # id's are given.

# create named selection. Not sure if this is correct.
ns = model.AddNamedSelection()
ns.set_Name("Test NS")
ns.Generate() # is this necessary? 


Best Answer

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 215
    First Answer First Comment 5 Likes First Anniversary
    edited May 22 Answer ✓

    Use the full path for GeometryEntities :
    selection = selection_manager.CreateSelectionInfo(Ansys.ACT.Interfaces.Common.SelectionTypeEnum.GeometryEntities)

    You can determine the full path in the Mechanical Scripting window by using the GetType() method:

    Alternatively, you could the run import statements (lines 17-42) from
    {Ansys installation folder}\aisol\DesignSpace\DSPages\Python\
    to force standalone Python to better match what is available in the Mechanical Scripting console.