Maya - userSetup.py

Hi,

I want to have control over userSetup.py when users launch tk-maya.
I want all workstations to read the same unique userSetup.py inside of sgtk config, so that users can customize their own userSetup.py files if they want.

I see there is already install\app_store\tk-maya\v0.9.7\startup\userSetup.py that looks excatly like what I want, but I don’t understand how the file is linked to sgtk config as I can’t find any hook key associated to this file in tk-maya.

I imagine I can also use tk-multi-launchapp\before_app_launch.py, but trying to add settings.tk-multi-launchapp.tk-maya to tk-multi-launchapp breaks my whole config as I don’t know what windows_path, linux_path and mac_path keys are supposed to be.

Can you point me to the right direction here? Using userSetup.py would be the best option I think.

Thanks.

2 Likes

Hi Ben

So first thing to say, is you shouldn’t modify the install\app_store\tk-maya\v0.9.7\startup\userSetup.py file. This is there purely for Toolkit to handle bootstrapping of the engine. You should use your own separate userSetup.py.

The before_app_launch.py hook sounds like the right way to go. You can add the path to your chosen userSetup.py file, by appending it to the PYTHONPATH.

You can use the following utility method to append a path to the env var:

sgtk.util.append_path_to_env_var("PYTHONPATH", path_to_your_usersetup_file)

If you’re bundling your custom userSetup.py file in with the config, you can access the hooks folder in the config by running the following from the hook:

self.disk_location

https://developer.shotgunsoftware.com/tk-core/core.html#sgtk.Hook.disk_location
Then you could modify that path to get to a different folder if needed.

Best
Phil

1 Like

Hi Philip,
Thanks for your answer.

I wouldn’t dare modify a file in the install/ folder! That’s my exact problem: I did not know how to telle sgtk to load {config}/tk-maya/userSetup.py

I’ll try appending userSetup.py path to PYTHONPATH. I did not know maya would launch any userSetup.py in this environment variable at startup.

Is
sgtk.util.append_path_to_env_var("PYTHONPATH", path_to_your_usersetup_file)
the exact same thing as
os.environ["PYTHONPATH"] or is this a sgtk special PYTHONPATH?


Concerning before_app_launch.py, I’m currently trying to make this work but have problems with implementing the settings in tk-maya:

:diamonds: copy before_app_launch.py to {config}/tk-multi-launchapp/before_app_launch.py
:diamonds: add those lines to tk-multi-launchapp.yml:

settings.tk-multi-launchapp.maya:
engine: tk-maya
location: "@apps.tk-multi-launchapp.location"
hook_before_app_launch: "{config}/tk-multi-launchapp/before_app_launch.py"

:diamonds: add tk-multi-launchapp: "@settings.tk-multi-launchapp.tk-maya" to the apps part of your different environments in tk-maya.yml

I’m not exactly sure I’m right there as this gives me errors when launching SG Desktop, but I think that’s the logic here?

TankError: Include error. Could not resolve references for L:\_tech\sgtk_sandbox\config\env\.\includes\settings\tk-maya.yml: Undefined Reference settings.tk-multi-launchapp.tk-maya!

2 Likes

Yes, it’s the same env var, it’s just a convenience method, for taking the current PYTHONPATH value and adding a new string to the end of it separated by the path separator. It runs this code essentially:


You could do it your self, but just make sure you don’t overwrite the current PYTHONPATH value as Toolkit won’t bootstrap, you must append to it.

I’m guessing you created the settings.tk-multi-launchapp.maya: block? You shouldn’t normally need to do this. I posted on the other thread you replied to with the instructions on how to add the hook:

Though technically the error you are getting is that your tk-maya.yml doesn’t know where to find the settings.tk-multi-launchapp.maya: settings block, as you probably haven’t included the tk-multi-launchapp.yml in the includes section of the file. However I think this is the wrong approach anyway, so I would follow the steps in the other post and see if that works for you. (And remove changes you made to the tk-maya.yml and tk-multi-launchapp.yml.)

Hope that helps, let me know if anything is not clear and I’ll try to clarify!
Cheers
Phil

2 Likes

Works perfectly! Thanks Philip

If anyone need help, here’s what I did with Philip advices:

:diamonds: created hooks in tk-multi-launchapp.yml under settings.tk-multi-launchapp and settings.tk-multi-launchapp.shotgun (not sure what this second one is doing)

hook_before_app_launch: "{config}/tk-multi-launchapp/before_app_launch.py"

:diamonds: created my methods in {config}/tk-multi-launchapp/before_app_launch.py. The first method I call makes sur PYTHONPATH is setuped as I want.

:diamonds: also added userSetup.py’s folder path to PYTHONPATH through a method that only execute if engine_name == ‘tk-maya’

2 Likes

That sounds spot on!

FYI the second settings.tk-multi-launchapp.shotgun block is used purely by the tk-shotgun engine. In other words those are the settings it will use if you launch a software via the browser integration. I’m not totally sure why the browser integration needed skip_engine_instances: ["tk-nukestudio"] specifically, but that is the difference.

2 Likes