예제 #1
0
    def on_plugin_init(self):
        """
        A callback happening when the Alias Shotgun plugin is initialized. It happens once and only once when Alias
        starts.
        """

        path = os.environ.get("SGTK_FILE_TO_OPEN", None)
        if path:
            alias_api.open_file(path)
예제 #2
0
    def import_file(self, path, create_stage=False, standalone=True):
        """Import a file into the current scene."""
        self.logger.debug(
            "Importing the file {}, and the create stage: {}".format(
                path, create_stage))

        if not os.path.exists(path):
            raise Exception("File not found on disk - '%s'" % path)

        if create_stage:
            success, message = alias_api.open_file(
                path, self.OPEN_FILE_TARGET_NEW_STAGE)
        else:
            success, message = alias_api.import_file(path)

        self.logger.debug("Result: {}, Message: {}".format(success, message))

        if not standalone:
            message_type = "information" if success else "warning"
            return dict(
                message_type=message_type,
                message_code=message,
                publish_path=path,
                is_error=False if success else True,
            )

        if not success:
            raise Exception("Error import the file")

        QtGui.QMessageBox.information(self.get_parent_window(), "Import File",
                                      "File imported successfully.")
예제 #3
0
    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()
예제 #4
0
    def open_file(self, path):
        """
        Convenience function to call the Alias Python API to open a file and ensure
        the context is saved for the current stage.

        :param path: the file path to open.
        :type path: str
        """

        status = alias_api.open_file(path)
        if status != int(alias_api.AlStatusCode.Success):
            self.logger.error(
                "Alias Python API Error: open_file('{}') returned non-success status code {}"
                .format(path, status))

        # Save context for the current stage that was updated
        self.save_context_for_stage()
예제 #5
0
    def open_file(self, path, target=None):
        """Open a file in the scene."""
        self.logger.debug("Opening file {}".format(path))

        # Check if the file is locked
        if not self.can_open_file(path):
            self.logger.debug("Open file aborted because the file is locked")
            return

        if not target:
            target = self.OPEN_FILE_TARGET_NEW_SCENE

            # Scene is empty: open the file in the current stage
            if self.is_pristine():
                target = self.OPEN_FILE_TARGET_CURRENT_STAGE
            else:
                self.logger.debug(
                    "Asking user for deleting the scene or creating a new stage"
                )
                answer = self._can_delete_current_objects()

                if answer == QtGui.QMessageBox.Cancel:
                    self.logger.debug("Open file aborted by the user")
                    return

                if answer == QtGui.QMessageBox.No:
                    target = self.OPEN_FILE_TARGET_NEW_STAGE

            if target == self.OPEN_FILE_TARGET_NEW_SCENE:
                self.current_file_closed()

        ctx = self._engine.context
        success, message = alias_api.open_file(path, target)
        self.logger.debug("Result: {}, Message: {}".format(success, message))

        if not success:
            raise Exception("Error opening the file {}".format(path))

        self._engine.save_context_for_path(path=path, ctx=ctx)
        self._engine.save_context_for_stage_name(ctx=ctx)
예제 #6
0
    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)