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