Is there a method/way to see what folder an object is in by only looking at the object?

benfielder
benfielder Member Posts: 4
First Comment
**

For example, here is a folder called Strikers. I want to be able to apply a method to one of the beams inside this folder, and for it to tell me the name of the folder that it is in. Is this possible?

Answers

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 202
    50 Answers 100 Comments Photogenic 5 Likes
    ✭✭✭✭
    edited June 28

    Hi

    Do not think there is an inbuilt method, but perhaps this can be done in different ways - one idea that does not use any possible internalobjects, is to get the folders (either geometry or connections folders see code below and change as needed), and then look through them to find the name of the object:

    for connections

    name='beam2' # name of beam object to look for/ change as needed
    folders=ExtAPI.DataModel.Project.Model.Connections.GetChildren(DataModelObjectCategory.TreeGroupingFolder, True)
    for folder in folders:
        for ch in folder.Children:
            if ch.Name.Split(" ")[0]==name:
                print(folder.Name)
    

    for geometry:

    name='sg1' # name of geom. object to look for/ change as needed
    folders=ExtAPI.DataModel.Project.Model.Geometry.GetChildren(DataModelObjectCategory.TreeGroupingFolder, True)
    for folder in folders:
        for ch in folder.Children:
            for ci in ch.Children:
                if ci.Name==name:
                    print(folder.Name)
    

    Perhaps the above is of some help.

  • benfielder
    benfielder Member Posts: 4
    First Comment
    **

    This helps, thank you!

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 202
    50 Answers 100 Comments Photogenic 5 Likes
    ✭✭✭✭

    Thank you for the feedback. Very glad to hear that it helped.
    Erik