def _create_reference(self, path):
        """
        Create an Alias reference.

        :param path: Path to the file.
        """
        if not os.path.exists(path):
            raise Exception("File not found on disk - '%s'" % path)
        alias_api.create_reference(path)
    def _import_file_as_reference(self, path, sg_publish_data):
        """
        Import the file as an Alias reference, converting it on the fly as wref.

        :param path:            Path to the file.
        :param sg_publish_data: ShotGrid data dictionary with all the standard publish fields
        """

        # get the tank of the project the file we're trying to import belongs to
        # this will be useful to manipulate configuration settings and templates
        tk = self.parent.engine.get_tk_from_project_id(
            sg_publish_data["project"]["id"])

        # then, get the reference template and the source template to be able to extract fields and build the path to
        # the translated file
        try:
            reference_template = self.parent.engine.get_reference_template(
                tk, sg_publish_data)
        except AttributeError:
            raise Exception(
                "There is an issue with Pipeline Configurations for the Linked Project<br>"
                " Please see the guidelines <a href=https://github.com/shotgunsoftware/tk-alias/wiki/Loading#import-as-reference-from-another-project><b>here.</b></a>"
            )
            return

        source_template = tk.template_from_path(path)

        # get the path to the reference, using the templates if it's possible otherwise using the source path
        # location
        if reference_template and source_template:
            template_fields = source_template.get_fields(path)
            template_fields["alias.extension"] = os.path.splitext(path)[-1][1:]
            reference_path = reference_template.apply_fields(template_fields)
        else:
            output_path, output_ext = os.path.splitext(path)
            reference_path = "{output_path}_{output_ext}.wref".format(
                output_path=output_path, output_ext=output_ext[1:])

        # if the reference file doesn't exist on disk yet, run the translation
        if not os.path.exists(reference_path):

            framework = self.load_framework(
                "tk-framework-aliastranslations_v0.x.x")
            if not framework:
                raise Exception(
                    "Couldn't find tk-framework-aliastranslations_v0.x.x")
            tk_framework_aliastranslations = framework.import_module(
                "tk_framework_aliastranslations")

            translator = tk_framework_aliastranslations.Translator(
                path, reference_path)
            translator.execute()

        alias_api.create_reference(reference_path)
Exemple #3
0
    def create_reference(self, path, standalone=True):
        """Load a file inside the scene as a reference."""
        self.logger.debug("Creating a reference to {}".format(path))

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

        success, message = alias_api.create_reference(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 creating the reference")

        QtGui.QMessageBox.information(self.get_parent_window(),
                                      "Reference File",
                                      "File referenced successfully.")
    def _import_file_as_reference(self, path):
        """
        Import the file as an Alias reference, converting it on the fly as wref.

        :param path: Path to the file.
        """

        reference_template = self.parent.engine.get_template(
            "reference_template")
        source_template = self.sgtk.template_from_path(path)

        # get the path to the reference, using the templates if it's possible otherwise using the source path
        # location
        if reference_template and source_template:
            template_fields = source_template.get_fields(path)
            template_fields["alias.extension"] = os.path.splitext(path)[-1][1:]
            reference_path = reference_template.apply_fields(template_fields)
        else:
            output_path, output_ext = os.path.splitext(path)
            reference_path = "{output_path}_{output_ext}.wref".format(
                output_path=output_path, output_ext=output_ext[1:])

        # if the reference file doesn't exist on disk yet, run the translation
        if not os.path.exists(reference_path):

            framework = self.load_framework(
                "tk-framework-aliastranslations_v0.x.x")
            if not framework:
                raise Exception(
                    "Couldn't find tk-framework-aliastranslations_v0.x.x")
            tk_framework_aliastranslations = framework.import_module(
                "tk_framework_aliastranslations")

            translator = tk_framework_aliastranslations.Translator(
                path, reference_path)
            translator.execute()

        alias_api.create_reference(reference_path)