Exemple #1
0
def bs_sanityCheckNamespaces():
    """
    @ get all namespaces in the scene.
    Returns:
            namespaces (list).
    """
    return pm.listNamespaces()
    def create_reference(self, sid_ref):
        """
            create a reference to the scene defined by sid_ref on the current scene.
        """
        import pymel.core as pm

        cur_sid = self.get_sid()

        task_name = sid_ref.get("task")
        task_name = task_name.split("_")[-1]

        if sid_ref.is_shot():
            # create the namespace based on the sid
            file_namespace = "{0}_{1}_{2}".format(sid_ref.get("seq"),
                                                  sid_ref.get("shot"),
                                                  task_name)

        else:
            # create the namespace based on the sid
            file_namespace = "{0}_{1}".format(sid_ref.get("name"), task_name)

        namespace_list = pm.listNamespaces(
        )  # get the namespace list of all references
        counter = self.make_counter(
            file_namespace, namespace_list)  # return a formatted counter
        file_namespace += "__" + counter
        # create the reference
        pm.createReference(sid_ref.path, namespace=file_namespace)
Exemple #3
0
 def test_noop_if_namespace_already_exists(self):
     pm.namespace(set=':')
     ns_foo = self.create_namespace('foo')
     namespaceutils.add_namespace_to_root('foo')
     expected = [ns_foo]
     result = pm.listNamespaces(recursive=True)
     self.assertListEqual(expected, result)
Exemple #4
0
 def test_not_root_with_leading_colon(self):
     pm.namespace(set=':')
     ns_bar = self.create_namespace('bar')
     pm.namespace(set=':bar')
     ns = namespaceutils.add_namespace_to_root(':foo')
     expected = [':bar', ':foo']
     result = [str(x) for x in pm.listNamespaces(recursive=True)]
     self.assertListEqual(expected, result)
Exemple #5
0
def delete_all_namespaces():
    """
    Delete all the namespaces in the scene and merge them with the root.
    """
    namespaces = pm.listNamespaces(recursive=True, internal=False)
    for ns in reversed(namespaces):
        pm.namespace(removeNamespace=ns, mergeNamespaceWithRoot=True)

    print('{} name spaces removed'.format(len(namespaces)))
Exemple #6
0
    def fix(self):
        """@brief Delete the namespace in the scene.
        """
        for namespace in pm.listNamespaces():
            for elem in namespace.ls():
                elem.rename(elem.split(":")[-1])
            namespace.remove()

        self.run()
Exemple #7
0
    def namespace_deleter(cls):
        """the legendary namespace deleter from Mehmet Erer

        finds and deletes unused namespaces
        """
        all_namespaces = pm.listNamespaces()
        ref_namespaces = [ref.namespace for ref in pm.listReferences()]
        missing_namespaces = []

        from anima.ui.progress_dialog import ProgressDialogManager
        if len(all_namespaces) > 0:
            pdm = ProgressDialogManager()
            pdm.close()

            caller = pdm.register(len(all_namespaces),
                                  'Locating Unused Namespaces...')
            for nsa in all_namespaces:
                i = 0
                for nsr in ref_namespaces:
                    i += 1
                    if nsr == nsa:
                        break
                    if i == len(ref_namespaces):
                        missing_namespaces.append(nsa)
                caller.step()

        if len(missing_namespaces) > 0:
            caller = pdm.register(len(missing_namespaces),
                                  'Deleting Unused Namespaces...')
            for ns in missing_namespaces:
                ns_info = pm.namespaceInfo(ns, lon=1, fn=1, r=1)
                if len(ns_info) > 0:
                    nsc = ns_info[len(ns_info) - 1]
                    nsc_array = nsc.split(':')
                    if len(nsc_array) > 0:
                        for del_nsc in nsc_array:
                            pm.namespace(rm=del_nsc, mnr=1)
                else:
                    pm.namespace(rm=ns, mnr=1)
                print('Deleted -> :' + ns)
                caller.step()
        else:
            pm.warning(
                'There are no first-level unused namespaces in this scene.'
            )

        if len(ref_namespaces) == 0 and len(all_namespaces) > 0:
            for ns in all_namespaces:
                pm.namespace(rm=ns, mnr=1)
                print('Deleted -> : %s' % ns)
            pm.warning(
                'There are no references in this scene. All empty namespaces '
                'are deleted.'
            )
Exemple #8
0
def exportAnimation(path=None):
    """
    Bakes and exports animation on a rig in the scene.
    
    Args:
        path(str): An destination fbx path to export. 
    """
    if path is None:
        path = pmc.sceneName()
    path = path.replace('.ma', '.fbx')

    # Get the root joint
    root = None
    namespace = None
    for namespace in pmc.listNamespaces():
        root = getRootJoint(namespace)
        if root is not None:
            namespace = namespace
            break
    if root is None:
        raise RootJointException('Could not find a root in the scene with a namespace.')

    try:
        pmc.undoInfo(openChunk=True)

        # Create a duplicate root joint
        dupRoot = pmc.duplicate(root)[0]
        pmc.rename(dupRoot, root.nodeName().split(':')[-1])

        # Copy animation tags
        copyTagAttribiutes(root, dupRoot)

        # Bind skeleton
        constraints = []
        exportJoints = [dupRoot] + getBindSkeleton()
        for joint in [dupRoot] + getBindSkeleton():
            source = pmc.PyNode('%s:%s' % (namespace, joint.nodeName()))
            constraints.append(pmc.parentConstraint(source, joint))

        # Bake animation and remove constraints
        bakeAnimation(exportJoints)
        pmc.delete(constraints)

        # Export animation and convert to hkx
        exportFbx([dupRoot] + getBindSkeleton(), path=path, animation=True)
        ckcmd.importanimation(
            getSceneSkeletonHkx(legacy=True), path,
            getSceneAnimationDirectory(), cache_txt=getSceneCacheFile(),
            behavior_directory=getSceneBehaviorDirectory()
        )

        # TODO copy cache file to correct directory
    finally:
        pmc.undoInfo(closeChunk=True)
Exemple #9
0
def get_namespace_as_pynode(namespace_string):
    namespace = None
    try:
        namespace = pm.Namespace(namespace_string)
    except ValueError:
        for ns in pm.listNamespaces(recursive=True):
            if ns.endswith(namespace_string):
                namespace = ns
                break
    if namespace:
        return namespace
    raise ValueError("Namespace '{}' does not exist.".format(namespace_string))
Exemple #10
0
def delete_empty_namespaces():
    ''' 
    Remove all empty namespaces from bottom up to remove children namespaces first
    '''
    namespace_list = []
    for ns in pm.listNamespaces( recursive  =True, internal =False):
        namespace_list.append(ns)

    # Reverse Iterate through the contents of the list to remove the deepest layers first
    for ns in reversed(namespace_list):
        if not pm.namespaceInfo(ns, ls=True):
            pm.namespace(removeNamespace = ns, mergeNamespaceWithRoot = True)
Exemple #11
0
def delete_empty_namespaces():
    """checks and deletes empty namespaces
    """
    # only allow namespaces with DAG objects in it and no child namespaces
    empty_namespaces = [
        ns for ns in pm.listNamespaces(recursive=True)
        if len(pm.ls(ns.listNodes(), dag=True, mat=True)) == 0
        and len(ns.listNamespaces()) == 0
    ]

    # remove all empty
    for ns in empty_namespaces:
        pm.namespace(rm=ns, mnr=1)
Exemple #12
0
def delete_empty_namespaces():
    """checks and deletes empty namespaces
    """
    # only allow namespaces with DAG objects in it and no child namespaces
    empty_namespaces = [
        ns for ns in pm.listNamespaces(recursive=True)
        if len(pm.ls(ns.listNodes(), dag=True, mat=True)) == 0
        and len(ns.listNamespaces()) == 0
    ]

    # remove all empty
    for ns in empty_namespaces:
        pm.namespace(rm=ns, mnr=1)
Exemple #13
0
def set_namespace(namespace, start_at_root=False):
    if start_at_root:
        pm.namespace(set=':')
    try:
        pm.namespace(set=namespace)
    except RuntimeError as missing_namespace_error:
        check_name = namespace
        if not check_name.startswith(':'):
            check_name = ':{}'.format(check_name)
        current_ns = pm.namespaceInfo(currentNamespace=True)
        nested_ns = pm.listNamespaces(root=current_ns,
                                      recursive=True,
                                      internal=False)
        for ns in nested_ns:
            if ns.endswith(check_name):
                pm.namespace(set=ns)
                return ns
        all_ns = pm.listNamespaces(root=None, recursive=True, internal=False)
        for ns in all_ns:
            if ns.endswith(check_name):
                pm.namespace(set=ns)
                return ns
        raise missing_namespace_error
Exemple #14
0
def ar_removeNamespace(namespaceName):
    """
    @ remove namespace of passed argument.
    Args:
        namespaceName (str): namespace without colon ex (MSH).

    Returns:
            bool.
    """
    allNameSpaces = pm.listNamespaces()
    for each in allNameSpaces:
        if each == ':' + namespaceName:
            pm.namespace(rm=each[1:], mnr=True)
    ar_qui.ar_displayMessage('success', 'namespace successfully removed.')
    return True
Exemple #15
0
    def check(self):
        """@brief Check if there is some namespace in the scene.
        """
        BadNamespaces = list()

        for namespace in pm.listNamespaces():
            BadNamespaces.append(namespace)

        if not BadNamespaces:
            self.status = "OK"
        else:
            self.status = self.errorMode
            self.errorNodes = namespace
            for namespace in BadNamespaces:
                self.addError("namespace %s exist" % namespace)
            self.errorMessage = "%s namespace" % (len(BadNamespaces))
Exemple #16
0
def removeNamespace(namespaceSelected):
    """ !@Brief
    Remove Namespace to selected garments, namespace will generate error otherwise
    @param namespaceSelected: List, a list of namespace
    """

    namespacesInScene = []
    for ns in pm.listNamespaces(recursive=True, internal=False):
        namespacesInScene.append(ns)

    namespaces = []

    for namespace in namespaceSelected:
        if namespace in namespacesInScene:
            namespaces.append(namespace)

    for ns in reversed(namespaces):
        currentSpace = ns
        pm.namespace(removeNamespace=ns, mergeNamespaceWithRoot=True)
Exemple #17
0
 def _removeNamespace(self):
     allNameSpaces = pm.listNamespaces()
     for each in allNameSpaces:
         if each == ':' + self.namespaceName:
             pm.namespace(rm=each[1:], mnr=True)
Exemple #18
0
def check_no_namespace():
    """there should be no namespaces in a model file
    """
    if len(pm.listNamespaces()):
        raise PublishError(
            'There should be no <b>Namespaces</b> in a <b>Model</b> scene.')
Exemple #19
0
 def test_root_current_namespace(self):
     pm.namespace(set=':')
     ns = namespaceutils.add_namespace_to_root('foo')
     expected = [ns]
     result = pm.listNamespaces(recursive=True)
     self.assertListEqual(expected, result)