Set environment = disk location app using hook before_app_launch


I need add path to environment variable HOUDINI_PATH = tk-houdini-my_app.disk_location/houdini. I have custom *.idx presets which I want keep in my app, for this I need HOUDINI_PATH to presets location. How I can getting path to my bundle tk-houdini-my_app in hook hooks\tk-multi-launchapp\

Hi, this is a real excerpt from our hook, which works

class BeforeAppLaunch(sgtk.Hook):
    def execute(self, app_path, app_args, version, engine_name, **kwargs):
        if engine_name == "tk-houdini":
            self.houdini_launch(app_path=app_path, app_args=app_args, version=version, engine_name=engine_name, **kwargs)

    def houdini_launch(self, **kwargs):
        pipeline_path = os.path.join(
        # add project tools to HOUDINI_PATH
        hp = os.environ.get("HOUDINI_PATH", "").replace("^&", "&").split(";&")
        houdini_path = [h_pipeline, "z:/global/houdini", "&"]
        os.environ["HOUDINI_PATH"] = os.path.pathsep.join(hp + houdini_path)

This might not work if pasted directly, though, due to the shortening.

1 Like

Have you set set location of your app in application.yml?

Oh, I see now that you want to base this on the path to a custom app.
Not sure, the engine has not been initialized at this point, otherwise it is easy.
Maybe as Kemot says, you could pull it from the yaml somehow.
In the example above, I set paths relative to the pipeline configuration path (in a centralized config).

Of corse, I setup my app in app_locations.yaml. But app_locations have git paths. I need local path to my bundle_cache/git/tk-houdini-my_app. I don’t know how shotgun forms local paths using its api.

I don’t have an answer, but the source of cache_location might give you some hints
Not even sure if it’s possible to gather all the data needed by cache_location at this point

1 Like

So maybe try to use sgtk descriptor?

import sgtk
from sgtk.descriptor import Descriptor
sg = shotgun

uri = "sgtk:descriptor:app_store?name=tk-multi-workfiles2&version=v0.12.3"    # app name and current version
descriptor_obj = sgtk.descriptor.create_descriptor(sg, Descriptor.CONFIG, uri)
path = descriptor_obj.get_path()