Creating Named Selection with PyMechanical
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() globals().update(global_variables(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_Location(selection) ns.set_Name("Test NS") ns.Generate() # is this necessary?
Thanks!
Best 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\module_base.py
to force standalone Python to better match what is available in the Mechanical Scripting console.1
Answers
-
Thank you very much!
0