How do I track the application version that was used to create a published file?

When viewing a published file in shotgun, it offers a 'Open in Associated Application' Action, which defaults to whatever the associated hook (shotgun_launch_publish.py) decides to use, but I would need more control over the application chosen.

So I think I could change the launch_publish hook, but I wouldn't have any way to decide which application to open other than the path. However it would be good to know if it needs nukex instead of nuke, or maya 2014 instead of 2013... 

Is there a way to record the exact application that was used for a publish and get that information back from shotgun when loading the published file through shotgun? Or some other, easier way to achieve the same goal?


  • 0
    Manne Öhrström

    Great Question and interesting use case!

    There is a core hook called before_register_publish.py, which lets you modify the publish data that toolkit has set up, just before it creates the actual entity in Shotgun. Customizing this would allow you to create additional publish metadata, either as tags on the publish or perhaps a new custom field that you add to your publish entity? You could get the currently running engine by using stgk.platform.current_engine(), however keep in mind that most engines don't really know how they were bootstrapped and which version of an application they are running inside. So you may have to do some custom hook logic, perhaps something along these lines: 

    class BeforeRegisterPublish(Hook):
        def execute(self, shotgun_data, context, **kwargs):
            Gets executed just before a new publish entity is created in Shotgun.
            :param shotgun_data: All the data which will be passed to the shotgun create call
            :param context: The context of the publish
            :returns: return (potentially) modified data dictionary
            # find out which engine we are running
            e = sgtk.platform.current_engine()
            # special cases for each engine
            if e.name == "tk-nuke":
               import nuke
               # find out nuke app version here...
               app_version = "Nuke XYZ"
            elif e.name == "tk-maya":
               # maya specific logic here...
               app_version = "Maya XYZ"
               app_version = "unknown"
            # add our app version custom field to the publish dict
            shotgun_data["sg_app_version"] = app_version   
            # and return our modified data to toolkit so it can be published
            return shotgun_data

    Once each publish has  a custom field with information about which application it came from, you can use this in the hook inside the launch publish app to make sure that you are launching the right application! Note that the hook currently only passes path, context and associated_entity as its parameters, so you may have look up further publish data using a shotgun lookup based on the path via the sgtk.util.find_publish() helper method!

    One other (similar) approach would be to somehow encode the application that was used in the published file type. Depending on the pipeline setup, this may or may not make sense - these type fields are used to group the published data in many places, and it may not always be desirable to group application that created them!



  • 0
    Fabian Dittrich

    Cool, didn't know about that hook, that's exactly what I need, thanks! :)

Please sign in to leave a comment.