How can I create groups of groups for the geometry in Mechanical?

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

How can I create groups of groups for the geometry in Mechanical ?

Tagged:

Best Answer

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

    Below is a code sample to illustrate how this can be done.

    First, create a list of bodies that you would like to group:

    bodies = ExtAPI.DataModel.Project.Model.Geometry.GetChildren(DataModelObjectCategory.Body,True)
    folder1 = ExtAPI.DataModel.Tree.Group(bodies)
    folder1.Name = "My folder"
    

    Then, to place this group inside another group, the trick is to grab the folder itself and group it:

    folder2 = ExtAPI.DataModel.Tree.Group([folder1])
    folder2.Name = "My top folder"
    

    Finally, the tree has to be refreshed for the display to update:

    ExtAPI.DataModel.Tree.Refresh()

    Result is as follows:

Answers