Skip to content

Instantly share code, notes, and snippets.

@thebeeland
Last active June 18, 2019 17:09
Show Gist options
  • Save thebeeland/36a4c50815b9229691099ba1ae71d58e to your computer and use it in GitHub Desktop.
Save thebeeland/36a4c50815b9229691099ba1ae71d58e to your computer and use it in GitHub Desktop.

What doesn't (but should) work

If a user wanted to output multiple filetypes from Photoshop via the publish2 app, they should be able to do the following in their config:

core/templates.yml

# Add templates for each file type that they want to output. You're just copy/pasting
# the photoshop_asset_publish template, renaming it, and changing the extension on the
# path. In this case, we're setting up additional templates for png and jpg files.
photoshop_asset_publish:
    definition: '@asset_root/publish/photoshop/{name}.v{version}.psd'
photoshop_asset_publish_png:
    definition: '@asset_root/publish/photoshop/{name}.v{version}.png'
photoshop_asset_publish_jpg:
    definition: '@asset_root/publish/photoshop/{name}.v{version}.jpg'

Once the templates are in place, you just need to create additional instances of publish_document plugin in your config's tk-multi-publish2.yml file:

env/includes/settings/tk-multi-publish2.yml

settings.tk-multi-publish2.photoshop.asset_step:
  collector: "{self}/collector.py:{engine}/tk-multi-publish2/basic/collector.py"
  collector_settings:
      Work Template: photoshop_asset_work
  publish_plugins:
  - name: Publish to Shotgun
    hook: "{self}/publish_file.py"
    settings: {}
  - name: Upload for review
    hook: "{self}/upload_version.py"
    settings: {}
  - name: Begin file versioning
    hook: "{engine}/tk-multi-publish2/basic/start_version_control.py"
    settings: {}
  - name: Publish to Shotgun
    hook: "{self}/publish_file.py:{engine}/tk-multi-publish2/basic/publish_document.py"
    settings:
        Publish Template: photoshop_asset_publish
  - name: Publish PNG to Shotgun
    hook: "{self}/publish_file.py:{engine}/tk-multi-publish2/basic/publish_document.py"
    settings:
        Publish Template: photoshop_asset_publish_png
  - name: Publish JPG to Shotgun
    hook: "{self}/publish_file.py:{engine}/tk-multi-publish2/basic/publish_document.py"
    settings:
        Publish Template: photoshop_asset_publish_jpg
  - name: Upload for review
    hook: "{engine}/tk-multi-publish2/basic/upload_version.py"
    settings: {}
  help_url: *help_url
  location: "@apps.tk-multi-publish2.location"

In the above, you'll find two additional plugin instances defined; Publish PNG to Shotgun and Publish JPG to Shotgun. These plugin definitions reference the new png and jpg templates that were added to templates.yml.

Why that doesn't work

Everything looks like it should work, even when you go into Photoshop and launch the Publish app. You'll see the all three of the publish plugins represented, implying that a PSD, a PNG, and a JPG will be published. When you publish, everything will succeed and you'll find three new PublishedFile entities in Shotgun!

...and then you'll notice that all three of them point to a JPG file.

This is because the Publish plugins are keyed by the file path to the associated .py file, which is .../tk-multi-publish2/basic/publish_document.py in this case. In the Hook class in tk-core, hook instances are stored in memory and reused based on their base class and hook path. We then have the publish2 app passing a list of settings to store as state on the plugin instance it gets back from tk-core. As a result, we're in the situation of "last one wins." Because the JPG instance of the plugin was defined last in the config, ALL instances of the plugin use the JPG template.

This is broken, obviously.

Ways to work around it

Phil has a workaround, but I'm trying it and it isn't working. Looking at code, it seems like it should, so I'm very confused. We might need Phil to chime in early next week to see what I've done wrong. :(

@rob-aitchison
Copy link

I have been trying the workaround and still get the same result.
I have completely segregated every hook:

  - name: Publish to Shotgun
    hook: "{self}/publish_file.py:{engine}/tk-multi-publish2/basic/publish_document.py"
    settings:
        Publish Template: photoshop_asset_publish
  - name: Publish PNG to Shotgun
    hook: "{config}/publish_file_png.py:{config}/publish_document_png.py"
    settings:
        Publish Template: photoshop_asset_publish_png
  - name: Publish JPG to Shotgun
    hook: "{config}/publish_file_jpg.py:{config}/publish_document_jpg.py"
    settings:
        Publish Template: photoshop_asset_publish_jpg

Within those hooks, I have renamed the plugin class as well.

BasicFilePublishPlugin -> BasicFilePublishPluginPhotoshopJPG
BasicFilePublishPlugin -> BasicFilePublishPluginPhotoshopPNG
PhotoshopCCDocumentPublishPlugin -> PhotoshopCCPNGDocumentPublishPlugin
PhotoshopCCDocumentPublishPlugin -> PhotoshopCCJPGDocumentPublishPlugin

I added a folder to templates.yml for the output path as well:

    photoshop_asset_publish:
        definition: '@asset_root/publish/photoshop/{name}.v{version}.psd'
    photoshop_asset_publish_png:
        definition: '@asset_root/publish/photoshop/png/{name}.v{version}.png'
    photoshop_asset_publish_jpg:
        definition: '@asset_root/publish/photoshop/jpg/{name}.v{version}.jpg'

Still get only the single JPG (now in the jpg folder.)
I will also double-check with Phil, just wanted to note exactly what I tried above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment