SOLVED 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?

One moment later...

hi,

sorry for the delay.

I would use SetDparameter to organize the in/exclude list whenever this list is changed.

Other than that, there's no helper on the API for this task.

Cheers,
Manuel

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

Hello @orestiskon,

without further questions or replies, we will consider this topic as solved by Monday, the 30th and flag it accordingly.

Thank you for your understanding,
Ferdinand

@m_magalhaes Hi Manuel, sorry I missed your message.

I have an Include/Exclude lists of objects, and I would like to iterate on them in a hierarchical order.
If I just go with the order of the list, the user might not have added them in the hierarchical order.

Doing it in the same order they are displayed in the Object Manager is a reliable way of ordering them hierarchically, so I was looking for an efficient way of doing that.

Do you have any other ideas than iterating through all the objects of the project?

One moment later...

hi,

sorry for the delay.

I would use SetDparameter to organize the in/exclude list whenever this list is changed.

Other than that, there's no helper on the API for this task.

Cheers,
Manuel

Hello @orestiskon,

without any further questions, we will consider this topic as solved by Monday, the 25th and flag it accordingly.

Thank you for your understanding,
Ferdinand