UNSOLVED Arranging Objects by order of Object Manager

Hi all,
I'd like to arrange a list of objects based on the order they have in the Object Manager.
Is there an efficient way to do that without iterating through all of the objects of the scene?

I've been searching for something like Hierarchical Distance that I could compare with the scene root, or perhaps an index of the object in the Object Manager list, but haven't found something relevant.

Perhaps there is there another idea on how to achieve it?

My guess is that iterating over with enumerate BaseDocument.GetObjects(self) would be efficient enough..?

For example:

all_objs = doc.GetObjects()
for i, obj in enumerate(all_objs):
    # Distance can be whatever float or integer
    your_dist = i * 27
    pos = c4d.Vector(your_dist, 0, 0) 
    obj.SetAbsPos(pos)

@lasselauch Thanks Lasse, that's great advice, GetObjects() should work.

Having tried it out, a problem is the GetObjects() only gives the top objects of the document without their children.
I could make a recursive iteration to go through all of the document's objects but that would slow it down significantly...

I could make a recursive iteration to go through all of the document's objects but that would slow it down significantly...

Yeah, but that's basically the way to go... Not sure if the following yields faster results:

def get_next_element(op):
    if not op:
        return
    if op.GetDown():
        return op.GetDown()
    while (not op.GetNext()) and op.GetUp():
        op = op.GetUp()
    return op.GetNext()

def main():
    obj = doc.GetFirstObject()
        
    while obj:
        # act on obj
        print(obj.GetName())

        obj = get_next_element(obj)

Always wondered what approach would yield faster results...

Feel free to do some testing, would love to hear your results. 🙂

Hi,

I'm not sure to understand what's the goal here. Could you give us more information ? Why you need to be sure the order is the same?

Cheers,
Manuel