Beispiel #1
0
    def getTrackManagerNode(cls, trackSetNode =None, createIfMissing =False):
        """ Returns the name of the track manager nodeName for the current
            Cadence scene.

            trackSetNode: The track set nodeName on which to find the track
            manager nodeName.  If no nodeName is specified the method will look
            it up internally.

            createIfMissing: If true and no track manager nodeName is found one
            will be created and connected to the track set nodeName, which will
            also be created if one does not exist. """

        if not trackSetNode:
            trackSetNode = cls.getTrackSetNode(createIfMissing=createIfMissing)

        connects = cmds.listConnections(
                trackSetNode + '.usedBy',
                source=True,
                destination=False)
        if connects:
            for node in connects:
                if cmds.nodeType(node) == 'trackManager':
                    return node

        if createIfMissing:
            node = cmds.createNode('trackManager')
            cmds.connectAttr(
                node + '.trackSet', trackSetNode + '.usedBy', force=True)
            return node

        return None
Beispiel #2
0
    def run(self):
        """Doc..."""

        #-------------------------------------------------------------------------------------------
        # GET SELECTED OBJECTS
        #       Get a list of select objects. If no objects are selected then return an error.
        #       Because objects are list based on components, shape nodes are generally returned
        #       instead of transform nodes. In those cases the transform node must be found from
        #       the shape node name
        objectSelection = cmds.ls(selection=True, objectsOnly=True)
        if not objectSelection:
            self.putErrorResult(u'Nothing selected')
            return

        targets = dict()
        for obj in objectSelection:

            # Check for shape nodes, and get transform node name if a shape is found
            nodeTypes = cmds.nodeType(obj, inherited=True)
            if u'shape' in nodeTypes:
                obj = obj.rsplit(u'|', 1)[0]

            targets[obj] = []

        #-------------------------------------------------------------------------------------------
        # SORT SELECTED FACES
        #       Use a component selection to get the selected faces and add them to the target
        #       list for their object.
        for comp in cmds.ls(selection=True, flatten=True):
            parts = comp.split(u'.')
            if len(parts) < 2 or parts[0] not in targets:
                continue

            targets[parts[0]].append(int(parts[1].lstrip(u'f[').rstrip(u']')))

        #-------------------------------------------------------------------------------------------
        # EXTRACT & SEPARATE
        #       For each object in the targets list extract the selected faces by chipping them off
        #       and then separating the mesh into the separated pieces.
        results = dict()
        selects = []
        for obj,faces in DictUtils.iter(targets):
            if not faces:
                continue

            faces.sort()
            comps = []
            for f in faces:
                comps.append(u'%s.f[%s]' % (obj, f))

            cmds.polyChipOff(*comps, duplicate=False, keepFacesTogether=True)
            separateOut = cmds.polySeparate(obj)
            out = []
            for node in separateOut:
                if MayaNodeUtils.isTransformNode(node):
                    out.append(node)
                    selects.append(node)

            results[obj] = out

        cmds.select(*selects, replace=True)
        self.put('extracts', results)
Beispiel #3
0
 def getNodeTypes(cls, nodeName):
     return cmds.nodeType(nodeName, inherited=True)
Beispiel #4
0
 def getNodeTypes(cls, nodeName):
     return cmds.nodeType(nodeName, inherited=True)
Beispiel #5
0
    def run(self):
        """Doc..."""

        #-------------------------------------------------------------------------------------------
        # GET SELECTED OBJECTS
        #       Get a list of select objects. If no objects are selected then return an error.
        #       Because objects are list based on components, shape nodes are generally returned
        #       instead of transform nodes. In those cases the transform node must be found from
        #       the shape node name
        objectSelection = cmds.ls(selection=True, objectsOnly=True)
        if not objectSelection:
            self.putErrorResult(u'Nothing selected')
            return

        targets = dict()
        for obj in objectSelection:

            # Check for shape nodes, and get transform node name if a shape is found
            nodeTypes = cmds.nodeType(obj, inherited=True)
            if u'shape' in nodeTypes:
                obj = obj.rsplit(u'|', 1)[0]

            targets[obj] = []

        #-------------------------------------------------------------------------------------------
        # SORT SELECTED FACES
        #       Use a component selection to get the selected faces and add them to the target
        #       list for their object.
        for comp in cmds.ls(selection=True, flatten=True):
            parts = comp.split(u'.')
            if len(parts) < 2 or parts[0] not in targets:
                continue

            targets[parts[0]].append(int(parts[1].lstrip(u'f[').rstrip(u']')))

        #-------------------------------------------------------------------------------------------
        # EXTRACT & SEPARATE
        #       For each object in the targets list extract the selected faces by chipping them off
        #       and then separating the mesh into the separated pieces.
        results = dict()
        selects = []
        for obj, faces in DictUtils.iter(targets):
            if not faces:
                continue

            faces.sort()
            comps = []
            for f in faces:
                comps.append(u'%s.f[%s]' % (obj, f))

            cmds.polyChipOff(*comps, duplicate=False, keepFacesTogether=True)
            separateOut = cmds.polySeparate(obj)
            out = []
            for node in separateOut:
                if MayaNodeUtils.isTransformNode(node):
                    out.append(node)
                    selects.append(node)

            results[obj] = out

        cmds.select(*selects, replace=True)
        self.put('extracts', results)