Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
I encountered what I believed was a bug in doc.SetActiveObjects(object, c4d.SELECTION_ADD). The objects that I selected would return a different order than I expected when I used doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER|c4d.GETACTIVEOBJECTFLAGS_CHILDREN).
doc.SetActiveObjects(object, c4d.SELECTION_ADD)
doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER|c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
Here's the bug report I wrote up:
doc.SetActiveObject() does not seem to track object selection order.
"""Name-en-US: Print and Reverse Selection Description-en-US: Prints the names of all objects in the order they were selected. Then attempts to reverse selection order. """ import c4d from c4d import gui def main(): # Get Active Objects active_objects = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER|c4d.GETACTIVEOBJECTFLAGS_CHILDREN) if not active_objects: return # Collect the names of all objects, deselect as you go. names = [] for obj in active_objects: names.append(obj.GetName()) doc.SetActiveObject(obj, c4d.SELECTION_SUB) # Print the name of the objects based on their initial selection order. print names # Reselect the objects in reverse order for obj in reversed(active_objects): doc.SetActiveObject(obj, c4d.SELECTION_ADD) # Let C4D know something has changed c4d.EventAdd() if __name__=='__main__': main()
The console prints: ['a', 'b', 'c']
['a', 'b', 'c']
BUG: The console again prints: ['a', 'b', 'c']
EXPECTED: The console prints the new reverse selection order. ['c', 'b', 'a']
['c', 'b', 'a']
Turns out, it isn't a bug, but is instead a documentation issue. By calling doc.GetActiveObject() after each selection (as described here) you can update the selection caches and the selection order will appropriately update.
doc.GetActiveObject()
# Reselect the objects in reverse order for obj in reversed(active_objects): doc.SetActiveObject(obj, c4d.SELECTION_ADD) # Update selection caches, needed if you want to use SELECTIONORDER # Reference: https://plugincafe.maxon.net/topic/9307/12387_adding-to-document-selection-issue/3 doc.GetActiveObject()
Please add this information to the doc.SetActiveObject, doc.SetSelection, and doc.GetActiveObjects sections of the Python and C++ documentation, and mention it as a possible fix for the Shift Select bug which I've encountered previously.
doc.SetActiveObject
doc.SetSelection
doc.GetActiveObjects
Thank you,
Donovan
Hi @dskeithbuck thanks for reaching us.
In fact, it's written in the C++ BaseDocument - Selection Manual but I agree maybe a note in the function will be welcome.
IN any case, I will add a note for the python doc. Thanks again.
Cheers, Maxime.