Adding to document selection issue
On 15/01/2016 at 08:48, xxxxxxxx wrote:
I'm having a weird issue. I'm trying to make a custom selection in a specific order, but when using the call doc.SetActiveObject(o, c4d.SELECTION_ADD), it doesn't add properly..
For an example, make 4 objects in your document named "1", "2", "3", and "4". Now run this script.
def main() :
for index, name in enumerate([2,1,4,3]) : # Random order for testing
obj = doc.SearchObject(str(name))
if index == 0:
doc.SetActiveObject(obj, c4d.SELECTION_NEW) # new selection for the first object
newSelection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
print [o.GetName() for o in newSelection] # print new selection. It's wrong
It's just a random order, and not the order I want. Any ideas?
On 18/01/2016 at 02:29, xxxxxxxx wrote:
objects are typically selected in the Object Manager. The Object Manager does take care that certain internal caches are updated when the object selection is changed.
You can force the update of these caches by calling GetActiveObject() while you change the selection:
for index, name in enumerate([4,1,3,2]) : # Random order for testing obj = doc.SearchObject(str(name)) doc.GetActiveObject() if index == 0: doc.SetSelection(obj, c4d.SELECTION_NEW) # new selection for the first object continue doc.SetSelection(obj, c4d.SELECTION_ADD)
On 29/01/2016 at 10:00, xxxxxxxx wrote:
was your question answered?
On 04/09/2016 at 01:53, xxxxxxxx wrote:
I think the question is not completely answered -
your code work but it will not hold the right order of the selection.
this will select the objects from 1-4 but when you call - doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) the order will not be 1-4
On 04/09/2016 at 01:58, xxxxxxxx wrote:
Add 4 Null Objects in a document and run
import c4d from c4d import gui #Welcome to the world of Python def main() : mylist = doc.GetObjects() i=0 print "-save-" for node in mylist: print node.GetName() if i == 0: doc.SetActiveObject(node, mode=c4d.SELECTION_NEW) else: doc.SetActiveObject(node, mode=c4d.SELECTION_ADD) i +=1 c4d.EventAdd() print "-get-" getlist = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER) for node in getlist: print node.GetName() if __name__=='__main__': main()
On 04/09/2016 at 23:49, xxxxxxxx wrote:
as I said and showed in my post above, you have to call GetActiveObject() inside your selection loop.
On 05/09/2016 at 01:31, xxxxxxxx wrote:
sorry - you are absolut right - thanks - that helps alot