How to get the object newly added in current scene?
-
Hi plugincafe~
I want to get the object newly added in to current scene in my Dialog plugin and update something in my dialog.For example:
Add something in the scene(like a null object), how do i get this object? and how to get this Message?I find
c4d.EVMSG_CHANGE
in SDK and i can get some document changed message inCoreMessage
. But I don't know what to do next. -
-
@dunhou
Cool man ! That's what i want !
I actually thought about traverse everything in the scene, but I felt it would be a waste. for example, if there were a lot of objects in the scene, so I think if there was another way to do that. But based on your post, that's the only way to do.
Anyway , thank you and @ferdinand
Cheers~ -
Hello @gheyret,
thank you for reaching out to us and thank you @Dunhou for providing an answer. Yes, in the end you might have to track things over their UUID. This is however usually only the case when you must associate data with the newly added things. If not, it is often cheaper to just rebuild your GUI on every
EVMSG_CHANGE
. Helpful might here be also:- Dynamic Dialog GUI: What you probably want to do entails rebuilding a dialog dynamically. This example demonstrates how to do this in a simplified manner.
- Narrow down EVMSG_CHANGE events: Often it is desirable to narrow down
EVMSG_CHANGE
events to cases where actually something meaningful has changed. The topic shows this at the example of material states being cached. This demonstrates also the usage uf UUID to identify cache contents as well as storing GUI data abstractly so that it persists over reallocation boundaries.
Cheers,
Ferdinand -
Hi @ferdinand , thanks to your reply.
There is another quession; the basic property (like Name, Viewport visibility, Enabled, e.t.c) of object is not in the data container? I mean thec4d.BaseContainer
returned byc4d.BaseList2D.GetData()
-
Hey @gheyret,
The name of a node is certainly contained in the data container, when it comes to visibility, I assume you mean render/viewport visibility, and they are also parameters. With "Enabled" i assume you mean the green check-mark of generators, and this is also a parameter.
>>> Cube[c4d.ID_BASELIST_NAME] 'Cube' >>> Cube[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] 2 >>> Cube[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] 2 >>> Cube[c4d.ID_BASEOBJECT_GENERATOR_FLAG] 1
Remember that you can simply drag and drop parameters to the console to find out their ID. All these parameters can be found in the "Basic" tab.
When you mean the NBIT flags for hiding things, as for exampleNBIT_OHIDE
to hide an object or tag in the Object Manager, they are indeed not part of the data container because they are flags.Cheers,
Ferdinand -
@ferdinand
I mean i Get the Object Data usingBaseList2D.GetData()
andSetData
to another object, it's only change the parameter of "Object" Tab in Attributes Manager.
Hera is a exmaple:from typing import Optional import c4d doc: c4d.documents.BaseDocument # The active document op: Optional[c4d.BaseObject] # The active object, None if unselected def main() -> None: new = doc.GetFirstObject() old = new.GetNext() old.SetData(new.GetData()) c4d.EventAdd() if __name__ == '__main__': main()
Before run the script
After run the script
As you can see, the object name, visibilitys and display color is not changed by
SetData
-
Hello @gheyret,
my apologies, yes, these parameters are not part of the
BaseContainer
data container, your initial question was quite clear about that, I just quickly answered the question before I left yesterday and overlooked that aspect.But you could create a tuple to copy these parameters over because other than in the C++ layer, we do not have to worry much about data types with
__get/setitem__
, i.e., the bracket syntax.Cheers,
FerdinandResult:
Code:
from typing import Optional import c4d doc: c4d.documents.BaseDocument # The active document PID_COLLECTION: tuple[int] = ( c4d.ID_BASELIST_NAME, c4d.ID_BASEOBJECT_VISIBILITY_EDITOR, c4d.ID_BASEOBJECT_VISIBILITY_RENDER, c4d.ID_BASEOBJECT_GENERATOR_FLAG, c4d.ID_BASEOBJECT_USECOLOR, c4d.ID_BASEOBJECT_COLOR, ) def main() -> None: """ """ new = doc.GetFirstObject() old = new.GetNext() old.SetData(new.GetData()) for pid in PID_COLLECTION: new[pid] = old[pid] c4d.EventAdd() if __name__ == '__main__': main()
-
Hi @ferdinand , I get it ! Thanks again to your reply!