def _do_3dsmax_post_publish(self, work_template, progress_cb, user_data): """ Do any 3ds Max 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. """ from Py3dsMax import mxs progress_cb(0, "Versioning up the scene file") # get scene path scene_path = os.path.abspath(os.path.join(mxs.maxFilePath, mxs.maxFileName)) # 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") mxs.saveMaxFile(new_scene_path) progress_cb(100)
def _do_3dsmax_post_publish(self, work_template, progress_cb): """ Do any 3ds Max post-publish work :param work_template: The primary work template used for the publish :param progress_cb: Callback to be used when reporting progress """ from Py3dsMax import mxs progress_cb(0, "Versioning up the scene file") # get scene path scene_path = os.path.abspath(os.path.join(mxs.maxFilePath, mxs.maxFileName)) # 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") mxs.saveMaxFile(new_scene_path) progress_cb(100)
def _do_3dsmax_post_publish(self, work_template, progress_cb, user_data): """ Do any 3ds Max 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. """ from Py3dsMax import mxs progress_cb(0, "Versioning up the scene file") # get scene path scene_path = os.path.abspath( os.path.join(mxs.maxFilePath, mxs.maxFileName)) # 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") mxs.saveMaxFile(new_scene_path) progress_cb(100)
def _save(self): """ Save the current scene """ from Py3dsMax import mxs scene_path = os.path.abspath(os.path.join(mxs.maxFilePath, mxs.maxFileName)) mxs.saveMaxFile(scene_path)
def execute(self, operation, file_path, **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) :returns: Depends on operation: 'current_path' - Return the current scene file path as a String all others - None """ from Py3dsMax import mxs if operation == "current_path": # return the current scene path if not mxs.maxFileName: return "" return os.path.join(mxs.maxFilePath, mxs.maxFileName) elif operation == "open": # open the specified scene mxs.loadMaxFile(file_path) elif operation == "save": # save the current scene: file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName) mxs.saveMaxFile(file_path)
def _do_3dsmax_publish(self, task, work_template, comment, thumbnail_path, sg_task, progress_cb, user_data): """ Publish the main 3ds Max 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 """ from Py3dsMax import mxs progress_cb(0.0, "Finding scene dependencies", task) dependencies = self._3dsmax_find_additional_scene_dependencies() # get scene path scene_path = os.path.abspath( os.path.join(mxs.maxFilePath, mxs.maxFileName)) 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(10.0, "Saving the scene") self.parent.log_debug("Saving the scene...") mxs.saveMaxFile(scene_path) # copy the file: progress_cb(50.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 _save(self): """ Save the current scene """ from Py3dsMax import mxs scene_path = os.path.abspath( os.path.join(mxs.maxFilePath, mxs.maxFileName)) mxs.saveMaxFile(scene_path)
def execute(self, operation, file_path, context, parent_action, **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 :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 scene path if not mxs.maxFileName: return "" return os.path.join(mxs.maxFilePath, mxs.maxFileName) elif operation == "open": # open the specified scene mxs.loadMaxFile(file_path) elif operation == "save": # save the current scene: file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName) mxs.saveMaxFile(file_path) elif operation == "save_as": # save the scene as file_path: mxs.saveMaxFile(file_path) elif operation == "reset": """ Reset the scene to an empty state """ # use the standard Max mechanism to check # for and save the file if required: if not mxs.checkForSave(): return False # now reset the scene: mxs.resetMAXFile(mxs.pyhelper.namify("noPrompt")) return True
def _do_3dsmax_publish( self, task, work_template, comment, thumbnail_path, sg_task, progress_cb, user_data ): """ Publish the main 3ds Max 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 """ from Py3dsMax import mxs progress_cb(0.0, "Finding scene dependencies", task) dependencies = self._3dsmax_find_additional_scene_dependencies() # get scene path scene_path = os.path.abspath(os.path.join(mxs.maxFilePath, mxs.maxFileName)) 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(10.0, "Saving the scene") self.parent.log_debug("Saving the scene...") mxs.saveMaxFile(scene_path) # copy the file: progress_cb(50.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_3dsmax_publish(self, task, work_template, comment, thumbnail_path, sg_task, progress_cb): """ Publish the main 3ds Max scene """ from Py3dsMax import mxs progress_cb(0.0, "Finding scene dependencies", task) dependencies = self._3dsmax_find_additional_scene_dependencies() # get scene path scene_path = os.path.abspath( os.path.join(mxs.maxFilePath, mxs.maxFileName)) 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(10.0, "Saving the scene") self.parent.log_debug("Saving the scene...") mxs.saveMaxFile(scene_path) # copy the file: progress_cb(50.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_3dsmax_publish(self, task, work_template, comment, thumbnail_path, sg_task, progress_cb): """ Publish the main 3ds Max scene """ from Py3dsMax import mxs progress_cb(0.0, "Finding scene dependencies", task) dependencies = self._3dsmax_find_additional_scene_dependencies() # get scene path scene_path = os.path.abspath(os.path.join(mxs.maxFilePath, mxs.maxFileName)) 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(10.0, "Saving the scene") self.parent.log_debug("Saving the scene...") mxs.saveMaxFile(scene_path) # copy the file: progress_cb(50.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 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) p4_fw.util = p4_fw.import_module("util") if operation == "current_path": # return the current scene path if not mxs.maxFileName: return "" return os.path.join(mxs.maxFilePath, mxs.maxFileName) 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 specified scene mxs.loadMaxFile(file_path) elif operation == "save": # save the current scene: file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName) mxs.saveMaxFile(file_path) elif operation == "save_as": # ensure the file is checked out if it's a Perforce file: try: p4 = p4_fw.connection.connect() p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False) except TankError, e: self.parent.log_warning(e) # save the scene as file_path: mxs.saveMaxFile(file_path)
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) p4_fw.util = p4_fw.import_module("util") if operation == "current_path": # return the current scene path if not mxs.maxFileName: return "" return os.path.join(mxs.maxFilePath, mxs.maxFileName) 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 specified scene mxs.loadMaxFile(file_path) elif operation == "save": # save the current scene: file_path = os.path.join(mxs.maxFilePath, mxs.maxFileName) mxs.saveMaxFile(file_path) elif operation == "save_as": # ensure the file is checked out if it's a Perforce file: try: p4 = p4_fw.connection.connect() p4_fw.util.open_file_for_edit(p4, file_path, add_if_new=False) except TankError, e: self.parent.log_warning(e) # save the scene as file_path: mxs.saveMaxFile(file_path)