SceneOperation Hook class call shenanigans

Hello there!

My goal is to write logic so when with File open (tk-multi-workfiles2) a New file is created in a Shading step.

I figured out I need the SceneOperation Hook class.
For maya, I added it to the env/includes/settings/tk-multi-workfiles2
hook_scene_operation: "{config}/tk-multi-workfiles2/maya/scene_operation_tk-maya.py"

I also made it so my implementation of this class will only catch the proper cases:
if operation == "new_file" and context.step['name'] == 'Shading':
In any other cases, the parent class will process the call.

But Iā€™ve got two problems:

  • On first run, the SceneOperation Hookā€™s execute function is not even called at all.
  • On any other run, it is called twice, which is also unfortunate.

What am I missing here?

Thanks in advance!

Not sure what is going on, but some thoughts: on first call, possibly the context is not set, so no step.
On first call, the operation might be ā€œsaveā€ instead of ā€œsave_asā€?

2 Likes
  1. The call of the execute function itself is not Step related. I check it before my condition of course. Without any of my custom codes, I still donā€™t see this function called on first new_file operation.

  2. I added the wrong line of code in my post, ā€˜saveā€™ and ā€˜save_asā€™ is unrelated, Iā€™d like to work with ā€˜new_fileā€™ actually. But you gave me an idea, so I checked the execute functionā€™s arguments and found out that it calls with ā€˜new_fileā€™ twice, once operation set for ā€˜resetā€™, once for ā€˜prepare_newā€™, so I could solve the double call problem by adding the operation to the condition.

2 Likes

Yeah the scene is ā€œresetā€ nefore new file runs

But do you know why the hookā€™s execute is not called on the first New file creation?

Guys, I figured it out!
I added
hook_scene_operation: "{config}/tk-multi-workfiles2/maya/scene_operation_tk-maya.py"
in env/includes/settings/tk-multi-workfiles2, but only for the asset step.
When I start a new maya, itā€™s not in asset step, so my hook isnā€™t registered.
Solved.
Thanks for all your help!

2 Likes