示例#1
0
    def test_save_as_sets_the_render_file_name_for_Assets(self):
        """testing if the save_as sets the render file name correctly
        """

        self.mEnv.save_as(self.version1)

        # check if the path equals to
        expected_path = self.version1.output_path +\
                        "/<Layer>/"+ self.version1.project.code + "_" +\
                        self.version1.base_name +"_" +\
                        self.version1.take_name +\
                        "_<Layer>_<RenderPass>_<Version>"

        image_path = os.path.join(pm.workspace.path,
                                  pm.workspace.fileRules['image']).replace(
                                      "\\", "/")

        expected_path = utils.relpath(
            image_path,
            expected_path,
        )

        dRG = pm.PyNode("defaultRenderGlobals")

        self.assertEqual(expected_path, dRG.getAttr("imageFilePrefix"))
示例#2
0
    def test_save_as_sets_the_render_file_name_for_Assets(self):
        """testing if the save_as sets the render file name correctly
        """
        
        self.mEnv.save_as(self.version1)
        
        # check if the path equals to
        expected_path = self.version1.output_path +\
                        "/<Layer>/"+ self.version1.project.code + "_" +\
                        self.version1.base_name +"_" +\
                        self.version1.take_name +\
                        "_<Layer>_<RenderPass>_<Version>"

        image_path = os.path.join(
            pm.workspace.path,
            pm.workspace.fileRules['image']
        ).replace("\\", "/")

        expected_path = utils.relpath(
            image_path,
            expected_path,
        )

        dRG = pm.PyNode("defaultRenderGlobals")

        self.assertEqual(
            expected_path,
            dRG.getAttr("imageFilePrefix")
        )
示例#3
0
    def set_render_filename(self, version):
        """sets the render file name
        """
        render_output_folder = version.output_path
        base_name = version.base_name
        take_name = version.take_name
        version_string = 'v%03d' % version.version_number
        user_initials = version.created_by.initials

        output_filename = os.path.join(
            render_output_folder, "`$OS`", base_name + "_" + take_name +
            "_`$OS`_" + version_string + "_" + user_initials + ".$F4.exr")

        output_filename = output_filename.replace('\\', '/')

        # compute a $JOB relative file path
        # which is much safer if the file is going to be render in multiple OSes
        # $HIP = the current asset path
        # $JOB = the current sequence path
        #hip = self._asset.path
        #hip = hou.getenv("HIP")
        job = hou.getenv("JOB")
        # eliminate environment vars
        while "$" in job:
            job = os.path.expandvars(job)

        job_relative_output_file_path = "$JOB/" + utils.relpath(
            job, output_filename, "/", "..")

        output_nodes = self.get_output_nodes()
        for output_node in output_nodes:
            # get only the ifd nodes for now
            if output_node.type().name() == 'ifd':
                # set the file name
                try:
                    output_node.setParms(
                        {'vm_picture': str(job_relative_output_file_path)})
                except hou.PermissionError:
                    # node is locked
                    pass

                # set the compression to zips (zip, single scanline)
                output_node.setParms({"vm_image_exr_compression": "zips"})

                # also create the folders
                output_file_full_path = output_node.evalParm('vm_picture')
                output_file_path = os.path.dirname(output_file_full_path)

                flat_output_file_path = output_file_path
                while "$" in flat_output_file_path:
                    flat_output_file_path = os.path.expandvars(
                        flat_output_file_path)

                try:
                    os.makedirs(flat_output_file_path)
                except OSError:
                    # dirs exists
                    pass
示例#4
0
    def reference(self, version):
        """References the given Version instance to the current Maya scene.

        :param version: The desired
          :class:`~oyProjectManager.models.version.Version` instance to be
          referenced.
        """
        # use the file name without extension as the namespace
        namespace = os.path.basename(version.filename)

        repo = Repository()

        workspace_path = pm.workspace.path

        new_version_full_path = version.full_path
        if version.full_path.startswith(workspace_path):
            new_version_full_path = utils.relpath(
                workspace_path,
                version.full_path.replace("\\", "/"), "/", ".."
            )

        # replace the path with environment variable
        new_version_full_path = repo.relative_path(new_version_full_path)

        ref = pm.createReference(
            new_version_full_path,
            gl=True,
            loadReferenceDepth='none',
            namespace=namespace,
            options='v=0'
        )

        # replace external paths
        self.replace_external_paths(1)

        # set the reference state to loaded
        if not ref.isLoaded():
            ref.load()

        # append the referenced version to the current versions references
        # attribute

        current_version = self.get_current_version()
        if current_version:
            current_version.references.append(version)
            current_version.save()

        return True
示例#5
0
    def set_render_fileName(self, version):
        """sets the render file name
        """
        # assert isinstance(version, Version)
        render_output_folder = version.output_path.replace("\\", "/")

        # image folder from the workspace.mel
        image_folder_from_ws = pm.workspace.fileRules['images']
        image_folder_from_ws_full_path = os.path.join(
            os.path.dirname(version.path),
            image_folder_from_ws
        ).replace("\\", "/")

        render_file_full_path = render_output_folder + "/<RenderLayer>/" + \
                                version.project.code + "_"

        if version.type.type_for == "Shot":
            render_file_full_path += version.version_of.sequence.code + "_"

        render_file_full_path += version.base_name + "_" + \
                                 version.take_name + \
                                 "_<RenderLayer>_<RenderPass>_<Version>"

        # convert the render_file_full_path to a relative path to the
        # imageFolderFromWS_full_path
        render_file_rel_path = utils.relpath(
            image_folder_from_ws_full_path,
            render_file_full_path,
            sep="/"
        )

        if self.has_stereo_camera():
            # just add the <Camera> template variable to the file name
            render_file_rel_path += "_<Camera>"

        # defaultRenderGlobals
        dRG = pm.PyNode('defaultRenderGlobals')
        dRG.setAttr('imageFilePrefix', render_file_rel_path)
        dRG.setAttr('renderVersion', "v%03d" % version.version_number)
        dRG.setAttr('animation', 1)
        dRG.setAttr('outFormatControl', 0)
        dRG.setAttr('extensionPadding', 4)
        dRG.setAttr('imageFormat', 7)  # force the format to iff
        dRG.setAttr('pff', 1)

        self.set_output_file_format()
示例#6
0
    def reference(self, version):
        """References the given Version instance to the current Maya scene.

        :param version: The desired
          :class:`~oyProjectManager.models.version.Version` instance to be
          referenced.
        """
        # use the file name without extension as the namespace
        namespace = os.path.basename(version.filename)

        repo = Repository()

        workspace_path = pm.workspace.path

        new_version_full_path = version.full_path
        if version.full_path.startswith(workspace_path):
            new_version_full_path = utils.relpath(
                workspace_path, version.full_path.replace("\\", "/"), "/",
                "..")

        # replace the path with environment variable
        new_version_full_path = repo.relative_path(new_version_full_path)

        ref = pm.createReference(new_version_full_path,
                                 gl=True,
                                 loadReferenceDepth='none',
                                 namespace=namespace,
                                 options='v=0')

        # replace external paths
        self.replace_external_paths(1)

        # set the reference state to loaded
        if not ref.isLoaded():
            ref.load()

        # append the referenced version to the current versions references
        # attribute

        current_version = self.get_current_version()
        if current_version:
            current_version.references.append(version)
            current_version.save()

        return True
示例#7
0
    def set_render_fileName(self, version):
        """sets the render file name
        """
        # assert isinstance(version, Version)
        render_output_folder = version.output_path.replace("\\", "/")

        # image folder from the workspace.mel
        image_folder_from_ws = pm.workspace.fileRules['images']
        image_folder_from_ws_full_path = os.path.join(
            os.path.dirname(version.path),
            image_folder_from_ws).replace("\\", "/")

        render_file_full_path = render_output_folder + "/<RenderLayer>/" + \
                                version.project.code + "_"

        if version.type.type_for == "Shot":
            render_file_full_path += version.version_of.sequence.code + "_"

        render_file_full_path += version.base_name + "_" + \
                                 version.take_name + \
                                 "_<RenderLayer>_<RenderPass>_<Version>"

        # convert the render_file_full_path to a relative path to the
        # imageFolderFromWS_full_path
        render_file_rel_path = utils.relpath(image_folder_from_ws_full_path,
                                             render_file_full_path,
                                             sep="/")

        if self.has_stereo_camera():
            # just add the <Camera> template variable to the file name
            render_file_rel_path += "_<Camera>"

        # defaultRenderGlobals
        dRG = pm.PyNode('defaultRenderGlobals')
        dRG.setAttr('imageFilePrefix', render_file_rel_path)
        dRG.setAttr('renderVersion', "v%03d" % version.version_number)
        dRG.setAttr('animation', 1)
        dRG.setAttr('outFormatControl', 0)
        dRG.setAttr('extensionPadding', 4)
        dRG.setAttr('imageFormat', 7)  # force the format to iff
        dRG.setAttr('pff', 1)

        self.set_output_file_format()
示例#8
0
 def test_save_as_sets_the_render_file_name_for_Shots(self):
     """testing if the save_as sets the render file name correctly
     """
     
     test_seq = Sequence(self.project, "Test Sequence 1")
     test_seq.save()
     
     test_shot = Shot(test_seq, 1)
     test_shot.save()
     
     self.kwargs["type"] = self.shot_vtypes[0]
     self.kwargs["version_of"] = test_shot
     
     self.version1 = Version(**self.kwargs)
     
     self.mEnv.save_as(self.version1)
     
     # check if the path equals to
     expected_path = self.version1.output_path + \
                     "/<Layer>/"+ self.version1.project.code + "_" + \
                     self.version1.version_of.sequence.code + "_" + \
                     self.version1.base_name +"_" + \
                     self.version1.take_name + \
                         "_<Layer>_<RenderPass>_<Version>"
     
     image_path = os.path.join(
         pm.workspace.path,
         pm.workspace.fileRules['image']
     ).replace("\\", "/")
     
     expected_path = utils.relpath(
         image_path,
         expected_path,
     )
     
     dRG = pm.PyNode("defaultRenderGlobals")
     
     self.assertEqual(
         expected_path,
         dRG.getAttr("imageFilePrefix")
     )
示例#9
0
    def test_save_as_sets_the_render_file_name_for_Shots(self):
        """testing if the save_as sets the render file name correctly
        """

        test_seq = Sequence(self.project, "Test Sequence 1")
        test_seq.save()

        test_shot = Shot(test_seq, 1)
        test_shot.save()

        self.kwargs["type"] = self.shot_vtypes[0]
        self.kwargs["version_of"] = test_shot

        self.version1 = Version(**self.kwargs)

        self.mEnv.save_as(self.version1)

        # check if the path equals to
        expected_path = self.version1.output_path + \
                        "/<Layer>/"+ self.version1.project.code + "_" + \
                        self.version1.version_of.sequence.code + "_" + \
                        self.version1.base_name +"_" + \
                        self.version1.take_name + \
                            "_<Layer>_<RenderPass>_<Version>"

        image_path = os.path.join(pm.workspace.path,
                                  pm.workspace.fileRules['image']).replace(
                                      "\\", "/")

        expected_path = utils.relpath(
            image_path,
            expected_path,
        )

        dRG = pm.PyNode("defaultRenderGlobals")

        self.assertEqual(expected_path, dRG.getAttr("imageFilePrefix"))
示例#10
0
 def repPath(path):
     return utils.relpath(self.project_directory, path, "/", "..")
示例#11
0
    def replace_external_paths(self, mode=0):
        """Replaces all the external paths

        replaces:
          references: to a path which starts with $REPO env variable in
                      absolute mode and a workspace relative path in relative
                      mode
          file      : to a path which starts with $REPO env variable in
                      absolute mode and a workspace relative path in relative
                      mode

        Absolute mode works best for now.

        .. note::
          After v0.2.2 the system doesn't care about the mentalrayTexture
          nodes because the lack of a good environment variable support from
          that node. Use regular maya file nodes with mib_texture_filter_lookup
          nodes to have the same sharp results.

        :param mode: Defines the process mode:
          if mode == 0 : replaces with relative paths
          if mode == 1 : replaces with absolute paths
        """
        # TODO: Also check for image planes and replace the path

        logger.debug("replacing paths with mode: %i" % mode)

        # create a repository
        repo = Repository()
        repo_env_key = "$" + conf.repository_env_key

        workspace_path = pm.workspace.path

        # fix for paths like S:/ (ending with a slash) for $REPO
        server_path = os.environ[conf.repository_env_key]
        if server_path.endswith('/'):
            server_path = server_path[:-1]

        # replace reference paths with $REPO
        for ref in pm.listReferences():
            unresolved_path = ref.unresolvedPath().replace("\\", "/")

            if not unresolved_path.startswith("$" + conf.repository_env_key):

                # make it absolute
                if not os.path.isabs(unresolved_path):
                    unresolved_path = os.path.join(workspace_path,
                                                   unresolved_path)

                if unresolved_path.startswith(server_path):
                    new_ref_path = ""

                    if mode:
                        # convert to absolute path
                        new_ref_path = ref.path.replace(
                            server_path, repo_env_key)
                    else:
                        # convert to relative path
                        new_ref_path = utils.relpath(workspace_path, ref.path)

                    logger.info("replacing reference:", ref.path)
                    logger.info("replacing with:", new_ref_path)

                    ref.replaceWith(new_ref_path)

        types_and_attrs = {
            'aiImage': 'filename',
            'aiStandIn': 'dso',
            'file': 'fileTextureName',
            'imagePlane': 'imageName',
            'audio': 'filename',
            'AlembicNode': 'abc_File',
            'gpuCache': 'cacheFileName',
        }

        for node_type in types_and_attrs.keys():
            attr_name = types_and_attrs[node_type]
            for node in pm.ls(type=node_type):
                path = node.getAttr(attr_name)

                if path:
                    path = path.replace("\\", "/")

                logger.info("replacing file texture: %s" % path)

                path = os.path.normpath(os.path.expandvars(path))

                if path:
                    path = path.replace("\\", "/")

                # convert to absolute
                if not os.path.isabs(path):
                    path = os.path.join(workspace_path,
                                        path).replace("\\", "/")

                new_path = ""

                if mode:
                    # convert to absolute
                    new_path = path.replace(server_path,
                                            "$%s" % conf.repository_env_key)
                else:
                    # convert to relative
                    new_path = utils.relpath(workspace_path, path, "/", "..")

                logger.info("with: %s" % new_path)

                node.setAttr(attr_name, new_path)
示例#12
0
    def replace_external_paths(self, mode=0):
        """Replaces all the external paths

        replaces:
          references: to a path which starts with $REPO env variable in
                      absolute mode and a workspace relative path in relative
                      mode
          file      : to a path which starts with $REPO env variable in
                      absolute mode and a workspace relative path in relative
                      mode

        Absolute mode works best for now.

        .. note::
          After v0.2.2 the system doesn't care about the mentalrayTexture
          nodes because the lack of a good environment variable support from
          that node. Use regular maya file nodes with mib_texture_filter_lookup
          nodes to have the same sharp results.

        :param mode: Defines the process mode:
          if mode == 0 : replaces with relative paths
          if mode == 1 : replaces with absolute paths
        """
        # TODO: Also check for image planes and replace the path

        logger.debug("replacing paths with mode: %i" % mode)

        # create a repository
        repo = Repository()
        repo_env_key = "$" + conf.repository_env_key

        workspace_path = pm.workspace.path

        # fix for paths like S:/ (ending with a slash) for $REPO
        server_path = os.environ[conf.repository_env_key]
        if server_path.endswith('/'):
            server_path = server_path[:-1]

        # replace reference paths with $REPO
        for ref in pm.listReferences():
            unresolved_path = ref.unresolvedPath().replace("\\", "/")

            if not unresolved_path.startswith("$" + conf.repository_env_key):

                # make it absolute
                if not os.path.isabs(unresolved_path):
                    unresolved_path = os.path.join(
                        workspace_path,
                        unresolved_path
                    )

                if unresolved_path.startswith(server_path):
                    new_ref_path = ""

                    if mode:
                        # convert to absolute path
                        new_ref_path = ref.path.replace(
                            server_path,
                            repo_env_key
                        )
                    else:
                        # convert to relative path
                        new_ref_path = utils.relpath(
                            workspace_path,
                            ref.path
                        )

                    logger.info("replacing reference:", ref.path)
                    logger.info("replacing with:", new_ref_path)

                    ref.replaceWith(new_ref_path)

        types_and_attrs = {
            'aiImage': 'filename',
            'aiStandIn': 'dso',
            'file': 'fileTextureName',
            'imagePlane': 'imageName',
            'audio': 'filename',
            'AlembicNode': 'abc_File',
            'gpuCache': 'cacheFileName',
        }

        for node_type in types_and_attrs.keys():
            attr_name = types_and_attrs[node_type]
            for node in pm.ls(type=node_type):
                path = node.getAttr(attr_name)

                if path:
                    path = path.replace("\\", "/")

                logger.info("replacing file texture: %s" % path)

                path = os.path.normpath(
                    os.path.expandvars(
                        path
                    )
                )

                if path:
                    path = path.replace("\\", "/")

                # convert to absolute
                if not os.path.isabs(path):
                    path = os.path.join(
                        workspace_path,
                        path
                    ).replace("\\", "/")
                
                new_path = ""

                if mode:
                    # convert to absolute
                    new_path = path.replace(
                        server_path,
                        "$%s" % conf.repository_env_key
                    )
                else:
                    # convert to relative
                    new_path = utils.relpath(
                        workspace_path,
                        path,
                        "/", ".."
                    )

                logger.info("with: %s" % new_path)

                node.setAttr(attr_name, new_path)
示例#13
0
 def repPath(path):
     return utils.relpath(self.project_directory, path, "/", "..")
示例#14
0
    def set_render_filename(self, version):
        """sets the render file name
        """
        render_output_folder = version.output_path
        base_name = version.base_name
        take_name = version.take_name
        version_string = 'v%03d' % version.version_number
        user_initials = version.created_by.initials

        output_filename = os.path.join(
            render_output_folder, "`$OS`",
            base_name + "_" + take_name + "_`$OS`_" +
            version_string + "_" + user_initials + ".$F4.exr"
        )

        output_filename = output_filename.replace('\\', '/')

        # compute a $JOB relative file path
        # which is much safer if the file is going to be render in multiple OSes
        # $HIP = the current asset path
        # $JOB = the current sequence path
        #hip = self._asset.path
        #hip = hou.getenv("HIP")
        job = hou.getenv("JOB")
        # eliminate environment vars
        while "$" in job:
            job = os.path.expandvars(job)

        job_relative_output_file_path = "$JOB/" + utils.relpath(
            job, output_filename, "/", ".."
        )

        output_nodes = self.get_output_nodes()
        for output_node in output_nodes:
            # get only the ifd nodes for now
            if output_node.type().name() == 'ifd':
                # set the file name
                try:
                    output_node.setParms(
                        {'vm_picture': str(job_relative_output_file_path)}
                    )
                except hou.PermissionError:
                    # node is locked
                    pass

                # set the compression to zips (zip, single scanline)
                output_node.setParms({"vm_image_exr_compression": "zips"})

                # also create the folders
                output_file_full_path = output_node.evalParm('vm_picture')
                output_file_path = os.path.dirname(output_file_full_path)

                flat_output_file_path = output_file_path
                while "$" in flat_output_file_path:
                    flat_output_file_path = os.path.expandvars(
                        flat_output_file_path
                    )

                try:
                    os.makedirs(flat_output_file_path)
                except OSError:
                    # dirs exists
                    pass
示例#15
0
    def create_main_saver_node(self, version):
        """creates the default saver node if there is no one created before.
        """
        file_formats = ['exr', 'tga']

        # list all the save nodes in the current file
        saver_nodes = self.get_main_saver_node()

        for file_format in file_formats:
            # check if we have a saver node for this format
            format_saver = None
            format_node_name = '%s_%s' % (self._main_output_node_name,
                                          file_format)
            for node in saver_nodes:
                node_name = node.GetAttrs('TOOLS_Name')
                if node_name.startswith(format_node_name):
                    format_saver = node
                    break

            # create the saver node for this format if missing
            if not format_saver:
                # lock the comp to prevent the file dialog
                self.comp.Lock()

                format_saver = self.comp.Saver

                # unlock the comp
                self.comp.Unlock()

                format_saver.SetAttrs({'TOOLS_Name': format_node_name})

            # set the output path
            file_name_buffer = []
            template_kwargs = {}

            if version.type.type_for == "Shot":
                file_name_buffer.append("%(project_code)s_%(sequence_code)s_")
                template_kwargs.update({
                    'project_code':
                    version.project.code,
                    'sequence_code':
                    version.version_of.sequence.code
                })

            file_name_buffer.append(
                '%(base_name)s_%(take_name)s_%(type_code)s_Output_'
                'v%(version_number)03d_%(initials)s.001.%(format)s')
            template_kwargs.update({
                'base_name': version.base_name,
                'take_name': version.take_name,
                'type_code': version.type.code,
                'version_number': version.version_number,
                'initials': version.created_by.initials,
                'format': file_format
            })

            output_file_name = ''.join(file_name_buffer) % template_kwargs

            # check if it is a stereo comp
            # if it is enable separate view rendering
            output_file_full_path = os.path.join(version.output_path,
                                                 output_file_name).replace(
                                                     '\\', '/')

            # set the path
            format_saver.Clip[0] = 'Comp: %s' % os.path.normpath(
                utils.relpath(os.path.dirname(version.full_path),
                              output_file_full_path, "/", "..")).encode()

            # create the path
            try:
                os.makedirs(os.path.dirname(output_file_full_path))
            except OSError:
                # path already exists
                pass
示例#16
0
    def create_main_saver_node(self, version):
        """creates the default saver node if there is no one created before.
        """
        file_formats = ['exr', 'tga']

        # list all the save nodes in the current file
        saver_nodes = self.get_main_saver_node()

        for file_format in file_formats:
            # check if we have a saver node for this format
            format_saver = None
            format_node_name = '%s_%s' % (self._main_output_node_name,
                                          file_format)
            for node in saver_nodes:
                node_name = node.GetAttrs('TOOLS_Name')
                if node_name.startswith(format_node_name):
                    format_saver = node
                    break

            # create the saver node for this format if missing
            if not format_saver:
                # lock the comp to prevent the file dialog
                self.comp.Lock()

                format_saver = self.comp.Saver

                # unlock the comp
                self.comp.Unlock()

                format_saver.SetAttrs(
                    {'TOOLS_Name': format_node_name}
                )

            # set the output path
            file_name_buffer = []
            template_kwargs = {}

            if version.type.type_for == "Shot":
                file_name_buffer.append("%(project_code)s_%(sequence_code)s_")
                template_kwargs.update({
                    'project_code': version.project.code,
                    'sequence_code': version.version_of.sequence.code
                })

            file_name_buffer.append(
                '%(base_name)s_%(take_name)s_%(type_code)s_Output_'
                'v%(version_number)03d_%(initials)s.001.%(format)s'
            )
            template_kwargs.update({
                'base_name': version.base_name,
                'take_name': version.take_name,
                'type_code': version.type.code,
                'version_number': version.version_number,
                'initials': version.created_by.initials,
                'format': file_format
            })

            output_file_name = ''.join(file_name_buffer) % template_kwargs

            # check if it is a stereo comp
            # if it is enable separate view rendering
            output_file_full_path = os.path.join(
                version.output_path,
                output_file_name
            ).replace('\\', '/')

            # set the path
            format_saver.Clip[0] = 'Comp: %s' % os.path.normpath(
                utils.relpath(
                    os.path.dirname(version.full_path),
                    output_file_full_path,
                    "/",
                    ".."
                )
            ).encode()

            # create the path
            try:
                os.makedirs(os.path.dirname(output_file_full_path))
            except OSError:
                # path already exists
                pass