Hello! My script relies on selection order and works fine. however, when I undo and run the script again immediately, the selection order is changed (somewhat reversed), and it toggles the reversal consistently. Why is it doing this? And is there a way to make sure the selection order stays constant when re-invoking the script?
You can see a clearer explanation of my problem:
in this brief screen recording
import c4d from c4d import gui def main(): doc.StartUndo() selected = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) #print order of object names to console print ("start:") names =  for obj in selected: names.append(obj.GetName()) print (names) #distribute objects for idx, ob in enumerate(selected): doc.AddUndo(c4d.UNDOTYPE_CHANGE, ob) print (ob.GetName()) ob[c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_X] = 0 ob[c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_Y] = 0 ob[c4d.ID_BASEOBJECT_GLOBAL_POSITION,c4d.VECTOR_Z] = 0 + (idx * 1000) c4d.EventAdd() doc.EndUndo() if __name__=='__main__': main() c4d.EventAdd()