Hi @Shhlife,
You can do this by setting up your own publish plugin. The publisher api documentation has a lot of information on how to set up custom publishers, but here’s a quick proof of concept as well. I was able to publish PNGs by doing the following:
- Updating the template to use the “.png” extension
photoshop_asset_publish:
definition: '@asset_root/publish/photoshop/{name}.v{version}.png'
- Subclassing tk-photoshopcc’s
publish_document.py
hook and overwriting the_copy_work_to_publish
method to do the save correctly. The hook is saved in<config_dir>/hooks/tk-multi-publish2/basic/publish_document.py
import os
import traceback
import sgtk
from sgtk.util.filesystem import ensure_folder_exists
HookBaseClass = sgtk.get_hook_baseclass()
class PhotoshopCCPNGDocumentPublishPlugin(HookBaseClass):
def _copy_work_to_publish(self, settings, item):
'''
Overwrites the method from the publish_document hook in the PS CC engine to
save the file with a new extension instead of just copying the work file
'''
# ---- ensure templates are available
work_template = item.properties.get("work_template")
if not work_template:
self.logger.debug(
"No work template set on the item. "
"Skipping file save to publish location."
)
return
publish_template = self.get_publish_template(settings, item)
if not publish_template:
self.logger.debug(
"No publish template set on the item. "
"Skipping file save to publish location."
)
return
work_file = item.properties.path
work_fields = work_template.get_fields(work_file)
missing_keys = publish_template.missing_keys(work_fields)
if missing_keys:
self.logger.warning(
"Work file '%s' missing keys required for the publish "
"template: %s" % (work_file, missing_keys)
)
return
publish_file = publish_template.apply_fields(work_fields)
try:
publish_folder = os.path.dirname(publish_file)
ensure_folder_exists(publish_folder)
engine = self.parent.engine
document = item.properties["document"]
# If you want to be able to save to other formats by updating the extension in the template
# you will need more robust logic here to figure out the correct SaveOptions class
save_options = engine.adobe.PNGSaveOptions()
# You may want to add these as settings for the publisher plugin instead of hard-coding them here
save_options.compression = 2
save_options.interlaced = False
document.saveAs(engine.adobe.File(publish_file), save_options, True)
except Exception:
raise Exception(
"Failed to save work file '%s' to '%s'.\n%s"
% (work_file, publish_file, traceback.format_exc())
)
self.logger.debug(
"Saved work file '%s' to publish file '%s'."
% (work_file, publish_file)
)
- Setting up a publisher plugin to point to my new hook
settings.tk-multi-publish2.photoshop.asset_step:
...
- name: Publish to Shotgun
hook: "{self}/publish_file.py:{engine}/tk-multi-publish2/basic/publish_document.py:{config}/tk-multi-publish2/basic/publish_document.py"
settings:
Publish Template: photoshop_asset_publish
NOTE: I overwrite an internal method
_copy_work_to_publish
in order to keep the amount of code posted here to a minimum. You cannot rely on the method being called with the same arguments or it might not even be called at all in future releases. The best way to do this would be to define thepublish
method instead. You would need to combine the publish methods from tk-photoshopcc and tk-multi-publish2 and update it to use the save logic from above.