Hook after DCC is loaded/template scene is opened

Hi, I am trying to prepare a blank scene once a DCC is opened. The aim is to not require any intervention, so no clicking around menus.

In the first experiment - Nuke. I added a hook nuke_after_load to the engine, which gets called at the end of post_app_init_nuke. However, if that sets global settings on the root node, everything gets overwritten later because Nuke loads a blank scene afterwards.

I could not find a hook for this event - no reset or any scene operation at all. No context change.
Is there a suitable hook for this moment?

Needless to say, I do not want to have this hook added to the engine. Perhaps I should wrap all this logic in tk-nuke-* apps instead?

1 Like

Could you use the engine_init core hook to register a Nuke callback that would be triggered when the script is reset?

Probably. So does engine_init have access to the nuke module? I could not find how it’s fired.
From looking at the engine code, I guess then I’d need nuke.addOnScriptLoad or similar.

Edit: nuke does not seem to have addOnScriptCreate, so this could be difficult to achieve.

engine_init should be fired just after the engine has finished starting. Technically it’s not quite at the end, since there is a quirk where sgtk.platform.current_engine() doesn’t work when called from engine_init. However, it will be run inside of Nuke so you can import the Nuke API.

There are a couple of things to watch out for though, the hook will be called in all engines, so you should check the engine.name first to see if it is tk-nuke before doing Nuke specific stuff. Also the hook will be called everytime the engine is reinitialized, and that could happen multiple times during the life of the Nuke session, so you may need to check if it has been run before.
You could set an env var on first run for this, and check for it, but if you spawn new Nuke instances from the current Nuke instance then this env var will be inherited. Its been a long while since I played around with Nuke callbacks so maybe you could just always try to unregister an existing callback and then reregister it?

The problem seems to be that nuke itself does not have a hook for the said behavior. It only exposes scriptLoad, scriptSave, and scriptClose. Load does not fire when the empty scene is loaded.
We will just fall back to requiring an action from the user - either a scene save, reset, open, or something else.