More Complex hook_app_launch for Maya / Overriding the Software Entity?

I’m trying to override the default settings.tk-multi-launchapp with a specific entry for maya, e.g. tk-multi-launchmaya.

The problem being that the default behavior, which keys off the software entities, seems to be taking precedence if I have the versions key in my Maya configuration (reproduced below).

settings.tk-multi-launchapp.maya:
engine: tk-maya
versions:
  - 2019
  - 2020
extra:
  rez:
    packages:
      - maya-{version}
      - renderManager
      - nasConfigMaya
    parent_variables:
      - PYTHONPATH
      - MAYA_MODULE_PATH
      - MAYA_SCRIPT_PATH
menu_name: "Maya {version}"
location: "@apps.tk-multi-launchapp.location"
hook_app_launch: "{config}/tk-multi-launchapp/rez_app_launch.py"
linux_path: "maya"
mac_path: "/Applications/Autodesk/maya{version}/Maya.app"
windows_path: "maya.exe"

Perhaps you can see that I’m passing some configuration information to the hook via the extra field. The settings for this should be unique on a per-application basis, which is why I thought have a separate entry per launcher would be correct, rather than trying to do everything within the tk-multi-launchapp default.

Is there a better way to do this? Is there a way to let multi-launchapp use the Software Entities by default, but override with individual entries when desired? What’s the correct approach?

2 Likes

So, I did figure out my first problem, which is that the versions entry there was incorrectly formatted, and should be:

versions: ["2020", "2019"]

But the remainder stands. Is this the best way to implement this, or is there a way to make this run through the Software Entity that’s better practice?

Welcome to the forums and good question!

I think it comes down to preference really. What you’re doing there doesn’t look wrong to me.
However, you could still achieve what you are after using the Software entity as well, and that might possibly make it easier to manage.

If I was to try and do the same thing with the software entity, then I would store the extra information on the Software entity in Shotgun under a custom field or fields. Then in the hook_app_launch hook I would look up the extra information using a find call

class AppLaunch(tank.Hook):
    def execute(
        self, app_path, app_args, version, engine_name, software_entity=None, **kwargs
    ):
        # Look up the Software entity and retrieve the extra launch info from the custom field.
        sw_entity = self.sgtk.shotun.find_one("Software",[["id","is",software_entity["id"]], [sg_extra_launch_info]]
        
        # Now use the extra info. If you stored a json formatted sting, you will need to parse it here.
        sw_entity["sg_extra_launch_info"] ...
1 Like

Thanks, @philip.scadding.

Using fields on the Software Entity was another thought I had. I’m glad to know that what I’m doing in the config isn’t out of expectations.

I think for now I’ll keep it in the config rather than on the Software Entity, because the config is source controlled.

Thanks for replying!

1 Like