Is there a method to easily detect when a project is first created and then modify the document? Same for the moment just after the user has invoked the Save Command but before the document has actually saved?
I'm hoping to apply custom settings on load (tweaking color parameters), and to perform a sanity check on the scene before saving (and possibly interrupt the save process if errors/issues are found).
I'm thinking that some sort of MessageData plugin is the ticket, but I didn't find a message that is called on scene load/save.
Other than that, I'm thinking that we can write custom scripts for loading/saving documents but I don't love that as it will require modifying keyboard shortcuts and still won't fix issues when someone drag & drops in assets to open them.
Some sort of Node Data object might help w/ the saving/loading but we'd have to manually add it to projects.
thank you @dskeithbuck for reaching out to us. There is not much to add for us here. Due to the lack of SceneHookData it is not possible to do what you want to do in Python. You cannot use MessageData, because it is not derived from NodeData and therefore has no Message method, the method to which MSG_DOCUMENTINFO is being broadcasted.
What you could try, is piggy backing onto SceneLoaderData or SceneSaverData as a SceneHookData replacement. I.e, only to use their Message method. But I cannot tell you when these two interfaces will receive messages. PreferencData for example, will only receive messages when the preferences dialog is open. You would have to try yourself if you could abuse them in such way. You should register them then for an extension which does not interfere with existing file formats.
Noteworthy seems also, that 'and possibly interrupt the save process if errors/issues are found' will not be possible, even when you return false for MSG_DOCUMENTINFO_TYPE_SAVE_BEFORE, Cinema will still save the document.
-> Document is about to be written.
-> Document was saved.
I have a plugin that I sell to render farms that does this. You need to develop with C++ and use a scene hook to catch document messages.
My solution allows render farms to call their own Python script immediately after a document is loaded. This allows them to change the paths required by their rendering setup.
If you just want a copy of my plugin instead of developing something yourself then just let me know. You can then modify the Python script to make it do what it is you actually want to do.
@C4DS @kbar @ferdinand - Thank you so much for the in-depth responses.
@kbar I'll see if I can get my employer to pony up for a license for Call Python as that seems like the simplest root. Although, this is potentially a light enough lift that I can finally make the transition into C++ development.
@ferdinand Helpful to know that I won't be able to interrupt the save process (probably a good thing from the user POV).