def _do_photoshop_post_publish(self, work_template, progress_cb): """ Do any Photoshop post-publish work :param work_template: The primary work template used for the publish :param progress_cb: Callback to be used when reporting progress """ import photoshop progress_cb(0, "Versioning up the scene file") # get the current scene path: doc = photoshop.app.activeDocument if doc is None: raise TankError("There is no currently active document!") scene_path = doc.fullName.nativePath # increment version and construct new file name: progress_cb(25, "Finding next version number") fields = work_template.get_fields(scene_path) next_version = self._get_next_work_file_version(work_template, fields) fields["version"] = next_version new_scene_path = work_template.apply_fields(fields) # log info self.parent.log_debug("Version up work file %s --> %s..." % (scene_path, new_scene_path)) # rename and save the file progress_cb(50, "Saving the scene file") import photoshop photoshop.save_as(doc, new_scene_path) progress_cb(100)
def _do_photoshop_publish(self, task, work_template, comment, thumbnail_path, sg_task, progress_cb, user_data): """ Publish the main Photoshop scene :param task: The primary task to publish :param work_template: The primary work template to use :param comment: The publish description/comment :param thumbnail_path: The path to the thumbnail to associate with the published file :param sg_task: The Shotgun task that this publish should be associated with :param progress_cb: A callback to use when reporting any progress to the UI :param user_data: A dictionary containing any data shared by other hooks run prior to this hook. Additional data may be added to this dictionary that will then be accessible from user_data in any hooks run after this one. :returns: The path to the file that has been published """ import photoshop doc = photoshop.app.activeDocument if doc is None: raise TankError("There is no currently active document!") # get scene path scene_path = doc.fullName.nativePath if not work_template.validate(scene_path): raise TankError( "File '%s' is not a valid work path, unable to publish!" % scene_path) # use templates to convert to publish path: output = task["output"] fields = work_template.get_fields(scene_path) fields["TankType"] = output["tank_type"] publish_template = output["publish_template"] publish_path = publish_template.apply_fields(fields) if os.path.exists(publish_path): raise TankError("The published file named '%s' already exists!" % publish_path) # save the scene: progress_cb(0.0, "Saving the scene") self.parent.log_debug("Saving the scene...") photoshop.save_as(doc, scene_path) # copy the file: progress_cb(25.0, "Copying the file") try: publish_folder = os.path.dirname(publish_path) self.parent.ensure_folder_exists(publish_folder) self.parent.log_debug("Copying %s --> %s..." % (scene_path, publish_path)) self.parent.copy_file(scene_path, publish_path, task) except Exception, e: raise TankError("Failed to copy file from %s to %s - %s" % (scene_path, publish_path, e))
def _do_photoshop_publish( self, task, work_template, comment, thumbnail_path, sg_task, progress_cb, user_data ): """ Publish the main Photoshop scene :param task: The primary task to publish :param work_template: The primary work template to use :param comment: The publish description/comment :param thumbnail_path: The path to the thumbnail to associate with the published file :param sg_task: The Shotgun task that this publish should be associated with :param progress_cb: A callback to use when reporting any progress to the UI :param user_data: A dictionary containing any data shared by other hooks run prior to this hook. Additional data may be added to this dictionary that will then be accessible from user_data in any hooks run after this one. :returns: The path to the file that has been published """ import photoshop doc = photoshop.app.activeDocument if doc is None: raise TankError("There is no currently active document!") # get scene path scene_path = doc.fullName.nativePath if not work_template.validate(scene_path): raise TankError("File '%s' is not a valid work path, unable to publish!" % scene_path) # use templates to convert to publish path: output = task["output"] fields = work_template.get_fields(scene_path) fields["TankType"] = output["tank_type"] publish_template = output["publish_template"] publish_path = publish_template.apply_fields(fields) if os.path.exists(publish_path): raise TankError("The published file named '%s' already exists!" % publish_path) # save the scene: progress_cb(0.0, "Saving the scene") self.parent.log_debug("Saving the scene...") photoshop.save_as(doc, scene_path) # copy the file: progress_cb(25.0, "Copying the file") try: publish_folder = os.path.dirname(publish_path) self.parent.ensure_folder_exists(publish_folder) self.parent.log_debug("Copying %s --> %s..." % (scene_path, publish_path)) self.parent.copy_file(scene_path, publish_path, task) except Exception, e: raise TankError("Failed to copy file from %s to %s - %s" % (scene_path, publish_path, e))
def _do_photoshop_post_publish(self, work_template, progress_cb, user_data): """ Do any Photoshop post-publish work :param work_template: The primary work template used for the publish :param progress_cb: Callback to be used when reporting progress :param user_data: A dictionary containing any data shared by other hooks run prior to this hook. Additional data may be added to this dictionary that will then be accessible from user_data in any hooks run after this one. """ import photoshop progress_cb(0, "Versioning up the scene file") # get the current scene path: doc = photoshop.app.activeDocument if doc is None: raise TankError("There is no currently active document!") scene_path = doc.fullName.nativePath # increment version and construct new file name: progress_cb(25, "Finding next version number") fields = work_template.get_fields(scene_path) next_version = self._get_next_work_file_version(work_template, fields) fields["version"] = next_version new_scene_path = work_template.apply_fields(fields) # log info self.parent.log_debug("Version up work file %s --> %s..." % (scene_path, new_scene_path)) # rename and save the file progress_cb(50, "Saving the scene file") import photoshop photoshop.save_as(doc, new_scene_path) progress_cb(100)
def _do_legacy_photoshop_post_publish(self, work_template, progress_cb, user_data): """ Do any Photoshop post-publish work :param work_template: The primary work template used for the publish :param progress_cb: Callback to be used when reporting progress :param user_data: A dictionary containing any data shared by other hooks run prior to this hook. Additional data may be added to this dictionary that will then be accessible from user_data in any hooks run after this one. """ import photoshop progress_cb(0, "Versioning up the scene file") # get the current scene path: doc = photoshop.app.activeDocument if doc is None: raise TankError("There is no currently active document!") scene_path = doc.fullName.nativePath # increment version and construct new file name: progress_cb(25, "Finding next version number") fields = work_template.get_fields(scene_path) next_version = self._get_next_work_file_version(work_template, fields) fields["version"] = next_version new_scene_path = work_template.apply_fields(fields) # log info self.parent.log_debug("Version up work file %s --> %s..." % (scene_path, new_scene_path)) # rename and save the file progress_cb(50, "Saving the scene file") import photoshop photoshop.save_as(doc, new_scene_path) progress_cb(100)
def execute(self, operation, file_path, context, parent_action, file_version, read_only, **kwargs): """ Main hook entry point :operation: String Scene operation to perform :file_path: String File path to use if the operation requires it (e.g. open) :context: Context The context the file operation is being performed in. :parent_action: This is the action that this scene operation is being executed for. This can be one of: - open_file - new_file - save_file_as - version_up :file_version: The version/revision of the file to be opened. If this is 'None' then the latest version should be opened. :read_only: Specifies if the file should be opened read-only or not :returns: Depends on operation: 'current_path' - Return the current scene file path as a String 'reset' - True if scene was reset to an empty state, otherwise False all others - None """ p4_fw = self.load_framework(TK_FRAMEWORK_PERFORCE_NAME) if operation == "current_path": # return the current script path doc = self._get_active_document() if doc.fullName is None: # new file? path = "" else: path = doc.fullName.nativePath return path elif operation == "open": # check that we have the correct version synced: p4 = p4_fw.connection.connect() if read_only: pass ## just sync the file: ## (TODO) - move this to the framework #path_to_sync = file_path #if file_version: # # sync specific version: # path_to_sync = "%s#%s" % (path_to_sync, file_version) #try: # p4.run_sync(path_to_sync) #except P4Exception, e: # raise TankError("Failed to sync file '%s'" % path_to_sync) else: # open the file for edit: #p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False, version=file_version) p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False) # open the file f = photoshop.RemoteObject('flash.filesystem::File', file_path) photoshop.app.load(f) elif operation == "save": # save the current script: doc = self._get_active_document() doc.save() elif operation == "save_as": doc = self._get_active_document() # and check out the file for edit: p4 = p4_fw.connection.connect() p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False) photoshop.save_as(doc, file_path) elif operation == "reset": # do nothing and indicate scene was reset to empty return True elif operation == "prepare_new": # file->new. Not sure how to pop up the actual file->new UI, # this command will create a document with default properties photoshop.app.documents.add()
def execute(self, operation, file_path, context, parent_action, file_version, read_only, **kwargs): """ Main hook entry point :param operation: String Scene operation to perform :param file_path: String File path to use if the operation requires it (e.g. open) :param context: Context The context the file operation is being performed in. :param parent_action: This is the action that this scene operation is being executed for. This can be one of: - open_file - new_file - save_file_as - version_up :param file_version: The version/revision of the file to be opened. If this is 'None' then the latest version should be opened. :param read_only: Specifies if the file should be opened read-only or not :returns: Depends on operation: 'current_path' - Return the current scene file path as a String 'reset' - True if scene was reset to an empty state, otherwise False all others - None """ if operation == "current_path": # return the current script path doc = self._get_active_document() if doc.fullName is None: # new file? path = "" else: path = doc.fullName.nativePath return path elif operation == "open": # open the specified script f = photoshop.RemoteObject('flash.filesystem::File', file_path) photoshop.app.load(f) elif operation == "save": # save the current script: doc = self._get_active_document() doc.save() elif operation == "save_as": doc = self._get_active_document() photoshop.save_as(doc, file_path) elif operation == "reset": # do nothing and indicate scene was reset to empty return True elif operation == "prepare_new": # file->new. Not sure how to pop up the actual file->new UI, # this command will create a document with default properties photoshop.app.documents.add()