def _session_path(): """ Return the path to the current session :return: """ return alias_api.get_current_path()
def get_current_path(self): """Get current opened file path.""" self.logger.debug("Getting current path") current_path = alias_api.get_current_path() self.logger.debug("Result: {}".format(current_path)) return current_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 """ self.parent.engine._stop_watching = True try: if operation == "current_path": return alias_api.get_current_path() elif operation == "open": open_in_current_stage = self.parent.engine.open_delete_stages_dialog() if open_in_current_stage == QtGui.QMessageBox.Cancel: return elif open_in_current_stage == QtGui.QMessageBox.No: self.parent.engine.execute_api_ops_and_defer_event_callbacks( [ ( "open_file", None, # indicate this ia function of the api module [file_path], {"new_stage": False, "delete_current": True}, ), ], alias_api.AlMessageType.StageActive, ) else: self.parent.engine.execute_api_ops_and_defer_event_callbacks( [ ("reset", None, [], {}), ("open_file", None, [file_path], {"new_stage": False},), ], alias_api.AlMessageType.StageActive, ) elif operation == "save": alias_api.save_file() finally: self.parent.engine._stop_watching = False if operation in ["open", "save"]: self.parent.engine.save_context_for_stage()
def process_current_session(self, settings, parent_item): """ Analyzes the current scene open in a DCC and parents a subtree of items under the parent_item passed in. :param dict settings: Configured settings for this collector :param parent_item: Root item instance """ publisher = self.parent # get the path to the current file path = alias_api.get_current_path() # determine the display name for the item if path: file_info = publisher.util.get_file_path_components(path) display_name = file_info["filename"] else: display_name = "Current Alias Session" # create the session item for the publish hierarchy session_item = parent_item.create_item("alias.session", "Alias Session", display_name) # get the icon path to display for this item icon_path = os.path.join(self.disk_location, os.pardir, "icons", "alias.png") session_item.set_icon_from_path(icon_path) # add a new item for Alias translations to separate them from the main session item translation_item = session_item.create_item( "alias.session.translation", "Alias Translations", "All Alias Translations") # if a work template is defined, add it to the item properties so # that it can be used by attached publish plugins work_template_setting = settings.get("Work Template") if work_template_setting: work_template = publisher.engine.get_template_by_name( work_template_setting.value) # store the template on the item for use by publish plugins. we # can't evaluate the fields here because there's no guarantee the # current session path won't change once the item has been created. # the attached publish plugins will need to resolve the fields at # execution time. session_item.properties["work_template"] = work_template translation_item.properties["work_template"] = work_template self.logger.debug("Work template defined for Alias collection.") self.logger.info("Collected current Alias file")
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 """ self.parent.engine._stop_watching = True try: if operation == "current_path": return alias_api.get_current_path() elif operation == "open": open_in_current_stage = self.parent.engine.open_delete_stages_dialog( ) if open_in_current_stage == QtGui.QMessageBox.Cancel: return elif open_in_current_stage == QtGui.QMessageBox.No: alias_api.open_file(file_path, new_stage=False, delete_current=True) else: alias_api.reset() alias_api.open_file(file_path, new_stage=False) elif operation == "save": alias_api.save_file() finally: self.parent.engine._stop_watching = False if operation in ["open", "save"]: self.parent.engine.save_context_for_stage()
def execute(self, operation, file_path, context=None, parent_action=None, file_version=None, read_only=None, **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 """ self.parent.engine._stop_watching = True try: if operation == "current_path": return alias_api.get_current_path() elif operation == "open": # if the current file is an empty file, we can erase it and open the new file instead if alias_api.is_empty_file(): alias_api.open_file(file_path, new_stage=False) # otherwise, ask the use what he'd like to do else: open_in_current_stage = ( self.parent.engine.open_delete_stages_dialog()) if open_in_current_stage == QtGui.QMessageBox.Cancel: return elif open_in_current_stage == QtGui.QMessageBox.No: alias_api.open_file(file_path, new_stage=True) else: alias_api.reset() alias_api.open_file(file_path, new_stage=False) elif operation == "save": alias_api.save_file() elif operation == "save_as": alias_api.save_file_as(file_path) elif operation == "reset": # do not reset the file if we try to open another one as we have to deal with the stages an resetting # the current session will delete all the stages if parent_action == "open_file": return True if alias_api.is_empty_file() and len( alias_api.get_stages()) == 1: alias_api.reset() return True else: open_in_current_stage = self.parent.engine.open_delete_stages_dialog( new_file=True) if open_in_current_stage == QtGui.QMessageBox.Cancel: return False elif open_in_current_stage == QtGui.QMessageBox.No: stage_name = uuid.uuid4().hex alias_api.create_stage(stage_name) else: alias_api.reset() return True finally: self.parent.engine._stop_watching = False if operation in ["save_as", "prepare_new", "open"]: self.parent.engine.save_context_for_stage(context)