Solved Get Objects from the Layer?

Hi,

Is it possible to retrieve the objects from the layer? Basically, I"m asking a reverse of GetLayerObject.
I tried GetChildren but it returns None.

Both this thread and this thread suggest that its not possible.

Can somebody confirm if this still holds true in the current documentation?

P.S. No need to create a code for the problem, if its the reverse way
(i.e. get objects then get layer rather than get layer then get objects). I should be able to create a working code based on the threads above.

I'm just confirming it if there is a direct way of doing things.

Thank you.

Hi @bentraje, thanks for reaching out us.

With regard to your request, I confirm there's no "reverse" method allowing you to get all the BaseList2D items being referred by a layer.

Cheers, R

Thanks for the confirmation.
Here is the working code I used

# You can get the layer attached with the object with the obj.GetLayerObject()
# But there is no direct way to do the reverse (i.e. get objects attached in the layer)
# Here is a script that does that. 
# Recursive function was retrieved from https://developers.maxon.net/?p=26


import c4d

def recurse_hierarchy(op):
    count = 0
    obj_dict = {}
    while op:
        obj_dict[op.GetName()] = op.GetLayerObject(doc).GetName()
        op = op.GetNext()
    return obj_dict

if __name__=='__main__':
    obj_dict = recurse_hierarchy(doc.GetFirstObject())
    print obj_dict

No further action required

Hi,

if I am not overlooking something here, the function recurse_hierarchy is neither recursive nor will it retrieve the layers for all objects in the scene. It will retrieve the layers for all siblings of the passed node, that were born after that node.

You probably made a mistake copying your code or misunderstood what is meant by recursive.

Cheers,
zipit

MAXON SDK Specialist
developers.maxon.net