I have been working on a userdata button that places a preset in the environment, I also wanted to put it inside the end of a joint, my problem is that when performing these steps, when going back the preset is outside the joint, the code generates the preset and then place it inside the board, is there a way to do it directly?
you should start the undo before merging the "preset" you want to add, and add the document to its own undo stack. just like this
res = c4d.documents.MergeDocument(doc,"file",c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS)
By the way you should never use "magic number" instead of flags. In that case SCENEFILTER_OBJECTS | SCENEFILTER_MATERIALS is the same as 3. There's no flag that have the value of 4 so 7 mean nothing more than 3.
If i understand, you have two undo stack? Or must press twice undo to retrieve the document as it was before pressing the button?
sharing some code would help a bit. I'm not sure how you add the object in the scene and how you create your new entry in the undo stack.
in itself the problem is that when performing the complete action when going back the object is outside the father, since it was first created and later placed inside the father
from c4d import documents, plugins
c4d.documents.MergeDocument(doc,"file location",7) #the preset has already been added
child = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_NONE)
for A in child:
A.InsertUnder(father)#the parent would be defined by a link
I did this since when adding the preset it is already selected, use this to place it inside another object
Thank you for solving my question, and thank you very much also for the advice.