How to list all UnderDefined objects in the Model Tree?

Tasos
Tasos Member, Employee Posts: 11
Name Dropper 5 Likes First Comment Photogenic
✭✭✭
edited January 8 in Structures

How can I identify which objects in the model tree are marked as underdefined using scripting?

Best Answer

  • Tasos
    Tasos Member, Employee Posts: 11
    Name Dropper 5 Likes First Comment Photogenic
    ✭✭✭
    Answer ✓

    Building on Landon's post: Using Mechanical scripting, how do I search for objects in the tree? — Community Forum, the appended script searches the Model Tree for objects in "UnderDefined" state.

    Note that this script will find and list every object with this status. For example, in the case of the tree in the screenshot below, the script will list:
    [Connections, Contacts, Contact Region, Static Structural, Solution]

    If the user wants to limit the search to specific items, they will need to further filter the "underdefined_objects" list according to their criteria.

    # Define a function to check if an object is underdefined:
    def is_underdefined(myobj):
        return myobj.ObjectState == ObjectState.UnderDefined
    
    # Find all underdefined objects in the tree:
    underdefined_objects = ExtAPI.DataModel.Tree.Find(func=is_underdefined)
    
    # Print the names of the invalidated objects:
    for myobj in underdefined_objects:
        print(myobj.Name)