Register event callbacks for "new file", "open file", "save file" (hooks?)
-
I'm looking for a way via Cinema4D's Python API to respond to a user creating a new document (to e.g. apply certain default settings) and to respond to file open and file save (preferably a callback before save and after save) to respond with some custom pipeline logic as well.
A google search and search over the SDK didn't get me anywhere. I did see Plugin Messages and Hooks but both didn't point me in the right direction to run python code on any of the mentioned events. At some point I thought
MessageData
was what I was looking for, but I couldn't find what ids it could capture and whether any were related to new document, saving document, opening documents, etc. -
And of course just after I find this Python API: Document Events topic which seems to hit close to this.
However - it seems it requires me to create an ACTUAL object in the scene if I understand correctly - which seems odd. Is there any way that I can make this work - inside the scene file within the pipeline, but have the Cinema4D file itself remain free of this when saved and shared with someone else? (Maybe we can exclude the node from persisting with the scene on saves, or alike?)
Also, that does not allow me to respond to a "new" document being created?
-
Hi @BigRoy, what is described in the post you find is still the actual way. The only change that we did is that now BaseList2D (so any objects, tags, material) can be hashed and this hash is based on the MAXON_CREATOR_ID.
Regarding new document, sadly there is no way to hook into that and the best way would be to have a MessageData, list all doc by calling c4d.documents.GetFirstDocument and then iterating them by calling BaseList2D.GetNext(). Since a document is a BaseList2D you can hash them and therefor know if there is a new document.
With that's said I will have a look into a limited support of SceneHook to it since it's a reasonable request that is often coming. But no promise.
Cheers,
Maxime. -
@m_adam said in Register event callbacks for "new file", "open file", "save file" (hooks?):
Regarding new document, sadly there is no way to hook into that and the best way would be to have a MessageData, list all doc by calling c4d.documents.GetFirstDocument and then iterating them by calling BaseList2D.GetNext(). Since a document is a BaseList2D you can hash them and therefor know if there is a new document.
So that would just be running on a timer then, with the hope that I 'trigger' on it swiftly enough? Doesn't fit my needs so dedicated SceneHooks I can register application wide would be a mad helper for this!
Aside of that - was there still a way to 'add' the python generator object into the scene without it maybe serializing into the saved file? Like have a flag that says "Do not serialize"? (Also, Scene Hooks would still be better)
-
I was just looking for the exact same thing and would second the need for these 3 hooks without the need for a Python Generator object.
It would make the pipeline integration of C4D much more straightforward. @m_adam