Esempio n. 1
0
def rem_ref_edits():
    logger.debug("Removing Reference Edits")
    parameters = ('.translate', '.rotate', '.scale')

    success = True

    for ref in pmc.iterReferences():
        was_loaded = ref.isLoaded()
        if was_loaded:
            ref.unload()

        for edit in ref.getReferenceEdits():
            if any(s in edit for s in parameters):
                try:
                    pmc.ReferenceEdit(edit,
                                      fileReference=ref).remove(force=True)
                except RuntimeError as e:
                    logger.error("Could not remove edit: {}".format(edit))
                    logger.error(e)
                    success = False

        if was_loaded:
            ref.load()

    return success
Esempio n. 2
0
 def test_iterRefs_breadth(self):
     # Test that each subsequent ref is has a recursive depth >= the
     # previous ref
     refDepth = 0
     for ref in pm.iterReferences(recursive=True, recurseType='breadth'):
         splitNS = ref.fullNamespace.split(':')
         thisDepth = len(splitNS)
         self.assertTrue(thisDepth >= refDepth)
         refDepth = thisDepth
Esempio n. 3
0
 def test_iterRefs_breadth(self):
     # Test that each subsequent ref is has a recursive depth >= the
     # previous ref
     refDepth = 0
     for ref in pm.iterReferences(recursive=True, recurseType='breadth'):
         splitNS = ref.fullNamespace.split(':')
         thisDepth = len(splitNS)
         self.assertTrue(thisDepth >= refDepth)
         refDepth = thisDepth
Esempio n. 4
0
    def test_iterRefs_depth(self):
        # Test that each subsequent ref is either a child of the previous ref,
        # or the sibling of of some ref higher in the stack'''
        refStack = []
        for ref in pm.iterReferences(recursive=True):
            splitNS = ref.fullNamespace.split(':')
            if len(splitNS) <= len(refStack):
                refStack = refStack[:len(splitNS) - 1]

            self.assertEqual(splitNS[:-1], refStack)
            refStack.append(ref.namespace)
Esempio n. 5
0
 def test_iterRefs_depth(self):
     # Test that each subsequent ref is either a child of the previous ref,
     # or the sibling of of some ref higher in the stack'''
     refStack = []
     for ref in pm.iterReferences(recursive=True):
         splitNS = ref.fullNamespace.split(':')
         if len(splitNS) <= len(refStack):
             refStack = refStack[:len(splitNS) - 1]
         
         self.assertEqual(splitNS[:-1], refStack)
         refStack.append(ref.namespace)
Esempio n. 6
0
def import_refs():
    logger.debug("Importing all References")
    success = True

    for ref in pmc.iterReferences():
        try:
            ref.importContents()
        except RuntimeError as e:
            logger.error("Could not import ref: {}".format(ref.namespace))
            logger.error(e)
            success = False

    return success
Esempio n. 7
0
def deref_shading_lightset():
    logger.debug("Removing Shading Lightset")

    for ref in pmc.iterReferences():
        if "shadingSetup" in ref.namespace:
            try:
                ref.remove()
                return True
            except RuntimeError as e:
                logger.error(e)
                return False

    # If the loop runs trough and no lightset is found, consider it an error
    return False
def listReferences(**kwargs):

    bSelected = kwargs.pop("selected", kwargs.pop("sl", False))
    bLocked = kwargs.pop("locked", None)
    bLoaded = kwargs.pop("loaded", None)
    bTopRef = kwargs.pop("topReference", kwargs.pop("top", True))
    excludeFunc = kwargs.pop("exclude", None)

    if bSelected:
        searchList = mc.ls(sl=True, dag=True, referencedNodes=True)
        sRefNodeList = mc.ls(sl=True, type="reference")
        if sRefNodeList:
            searchList.extend(sRefNodeList)
    else:
        searchList = pm.iterReferences(recursive=(not bTopRef))

    sRefNodeList = []
    oFileRefList = []

    for each in searchList:

        oFileRef = None
        if bSelected:
            sRefNode = mc.referenceQuery(each, referenceNode=True, topReference=bTopRef)
        else:
            sRefNode = each.refNode.name()
            oFileRef = each

        if sRefNode in sRefNodeList:
            continue

        sRefNodeList.append(sRefNode)

        if bLocked is not None:
            if mc.getAttr(sRefNode + ".locked") != bLocked:
                continue

        if bLoaded is not None:
            if mc.referenceQuery(sRefNode, isLoaded=True) != bLoaded:
                continue

        if not oFileRef:
            oFileRef = pm.FileReference(sRefNode)

        if excludeFunc and excludeFunc(oFileRef):
            continue

        oFileRefList.append(oFileRef)

    return oFileRefList
Esempio n. 9
0
def rem_unloaded_refs():
    logger.debug("Removing unloaded References")

    success = True
    for ref in pmc.iterReferences():
        if not ref.isLoaded():
            try:
                ref.remove()
            except RuntimeError as e:
                logger.error("Could not remove ref: {}".format(ref.namespace))
                logger.error(e)
                success = False

    return success
Esempio n. 10
0
def listReferences(**kwargs):

    bSelected = kwargs.pop("selected", kwargs.pop("sl", False))
    bLocked = kwargs.pop("locked", None)
    bLoaded = kwargs.pop("loaded", None)
    bTopRef = kwargs.pop("topReference", kwargs.pop("top", True))
    excludeFunc = kwargs.pop("exclude", None)

    if bSelected:
        searchList = mc.ls(sl=True , dag=True, referencedNodes=True)
        sRefNodeList = mc.ls(sl=True, type="reference")
        if sRefNodeList:
            searchList.extend(sRefNodeList)
    else:
        searchList = pm.iterReferences(recursive=(not bTopRef))

    sRefNodeList = []
    oFileRefList = []

    for each in searchList:

        oFileRef = None
        if bSelected:
            sRefNode = mc.referenceQuery(each, referenceNode=True, topReference=bTopRef)
        else:
            sRefNode = each.refNode.name()
            oFileRef = each

        if sRefNode in sRefNodeList:
            continue

        sRefNodeList.append(sRefNode)

        if bLocked is not None:
            if (mc.getAttr(sRefNode + ".locked") != bLocked):
                continue

        if bLoaded is not None:
            if (mc.referenceQuery(sRefNode, isLoaded=True) != bLoaded):
                continue

        if not oFileRef:
            oFileRef = pm.FileReference(sRefNode)

        if excludeFunc and excludeFunc(oFileRef):
            continue

        oFileRefList.append(oFileRef)

    return oFileRefList
Esempio n. 11
0
def is_mdl_referenced():
    logger.debug("Check for MDL Reference")
    asset_base = pmc.sceneName().parent.parent
    asset_name = scene_control.get_instance().meta.asset.replace("_SHD", "")
    mdl_ref_path = asset_base + "/" + asset_name + "_MDL_REF.ma"

    print(mdl_ref_path)
    print("\n")

    mdl_ref_found = False

    for ref in pmc.iterReferences():
        if ref.path == mdl_ref_path:
            mdl_ref_found = True
            break

    return mdl_ref_found
Esempio n. 12
0
def rem_all_refs():
    logger.debug("Removing all References")

    error_counter = 0

    for ref in pmc.iterReferences():
        logger.info("Removing Reference: {}".format(ref.refNode))
        try:
            ref.remove()
        except RuntimeError as e:
            logger.error("Could not remove Reference {}".format(ref.refNode))
            logger.error(e)
            error_counter += 1

    if error_counter == 0:
        return True
    else:
        return False
Esempio n. 13
0
def check_subref_dep():
    logger.debug("Checking if all SubReferences are SHD files")

    faulty_refs = []

    for ref in pmc.iterReferences():
        # # Check top nodes aswell
        # ref_name_trimmed = str(ref.refNode)
        # if "MDL" in ref_name_trimmed:
        #     faulty_refs.append(ref.refNode)

        for subref in ref.subReferences():
            subref_name_trimmed = "".join(subref.split(":")[1:])
            if "MDL" in subref_name_trimmed:
                faulty_refs.append(subref)

    if len(faulty_refs) == 0:
        return True
    else:
        logger.error("The following Refs seems to be faulty:")
        for ref in faulty_refs:
            logger.error(ref)
        return False
Esempio n. 14
0
def switch(curr_dep, new_dep, replace=True, grouped=False):
    curr_dep = curr_dep.upper()
    new_dep = new_dep.upper()

    error_counter = 0

    for ref in pmc.iterReferences():
        if ref.isLoaded():
            logger.debug("now processing... " + ref.refNode)

            # Get Path
            old_path = ref.path

            # Generate new Path
            if new_dep == "ASS":
                # Skip if already ASS
                if old_path.endswith("_SHD_REF.ass"):
                    continue

                new_path = old_path.replace("_{}_REF.ma".format(curr_dep),
                                            "_SHD_REF.ass")
            elif curr_dep == "ASS":
                new_path = old_path.replace("_SHD_REF.ass".format(curr_dep),
                                            "_{}_REF.ma".format(new_dep))
            else:
                new_path = old_path.replace("_{}_REF.ma".format(curr_dep),
                                            "_{}_REF.ma".format(new_dep))

            # Continue with next element if the wanted department could not be found
            if not os.path.isfile(new_path):
                logger.warning("no file for new department found")
                continue

            namespace = new_path.split(".")[0].split("/")[-1]

            if grouped:
                top_grps = pmc.ls(str(ref.refNode) + "group")
                if len(top_grps) == 0:
                    logger.warning(
                        "could not find the top_grp for the current ref: {}".
                        format(ref.refNode))
                    error_counter += 1
                    continue
                else:
                    top_grp = top_grps[0]

            if replace:
                # Replace file+namespace+grpname Workflow

                # ref.load(new_path)
                ref.replaceWith(new_path)
                ref.refNode.unlock()

                ref.namespace = namespace
                pmc.rename(ref.refNode,
                           str(ref.refNode).replace(curr_dep, new_dep))

                if grouped:
                    top_grp.unlock()
                    pmc.rename(top_grp,
                               str(top_grp).replace(curr_dep, new_dep))

                ref.refNode.lock()
            else:
                if not grouped:
                    logger.error("not implemented")
                    return False

                # ASS Workflow
                new_ref = pmc.createReference(new_path,
                                              namespace=namespace,
                                              groupReference=True)
                new_grp = pmc.ls(new_ref.refNode + "group")[0]

                for node in pmc.listRelatives(new_grp, children=True):
                    pmc.parent(node, top_grp, relative=True)

                # Set StandIn Preview to Polywire (2) / Shaded (6) / BoundingBox (0)
                standin = pmc.ls(
                    str(new_ref.namespace) + ":ArnoldStandInShape")[0]
                standin.mode.set(2)

                pmc.delete(new_grp)
                ref.remove()

    if error_counter == 0:
        return True
    else:
        return False