Exemplo n.º 1
0
    def connectToByPlug(self, sourcePlug, node, nodeAttributeName=None):
        nodeAttributeName = nodeAttributeName or "metaNode"
        dep = om2.MFnDependencyNode(node)
        if not dep.hasAttribute(nodeAttributeName):
            destinationPlug = dep.findPlug(
                nodes.addAttribute(node, nodeAttributeName, nodeAttributeName,
                                   attrtypes.kMFnMessageAttribute).object(),
                False)
        else:
            destinationPlug = dep.findPlug(nodeAttributeName, False)
            plugs.disconnectPlug(destinationPlug)

        with plugs.setLockedContext(sourcePlug):
            destIsLock = False
            sourceIsLock = False
            if destinationPlug.isLocked:
                destinationPlug.isLocked = False
                destIsLock = True
            if sourcePlug.isLocked:
                sourcePlug.isLocked = False
                sourceIsLock = True
            plugs.connectPlugs(sourcePlug, destinationPlug)
            if sourceIsLock:
                sourcePlug.isLocked = True
            if destIsLock:
                destinationPlug.isLocked = True
        return destinationPlug
Exemplo n.º 2
0
def unlockedAndDisconnectConnectedAttributes(mobject):
    """Unlcoks and disocnnects all attributes on the given node

    :param mobject: MObject respresenting the DG node
    :type mobject: MObject
    """
    for thisNodeP, otherNodeP in iterConnections(mobject, source=False, destination=True):
        plugs.disconnectPlug(thisNodeP)
Exemplo n.º 3
0
    def disconnectFromNode(self, node):
        """

        :param node: The destination node to disconnect from this meta node
        :type node: om2.MObject
        :return: success value
        :rtype: bool
        """
        metaObj = self.mobject()
        for source, destination in nodes.iterConnections(node, False, True):
            if source.node() != metaObj:
                continue
            plugs.disconnectPlug(source, destination)
            if source.isLocked:
                source.isLocked = False
            cmds.deleteAttr(destination.name())
            self.removeAttribute(source.name())
            return True
        return False
Exemplo n.º 4
0
    def connectTo(self, attributeName, node, nodeAttributeName=None):
        """Connects one plug to another by attribute name

        :param attributeName: the meta attribute name to connect from, if it doesn't exist it will be created
        :type attributeName: str
        :param node: the destination node
        :type node: MObject
        :param nodeAttributeName: the destination node attribute name, if one doesn't exist one will be created
        :type nodeAttributeName: str
        :return: the destination plug
        :rtype: om2.MPlug
        """
        nodeAttributeName = nodeAttributeName or "metaNode"
        dep = om2.MFnDependencyNode(node)
        self.disconnectFromNode(node)
        if not dep.hasAttribute(nodeAttributeName):
            destinationPlug = dep.findPlug(
                nodes.addAttribute(node, nodeAttributeName, nodeAttributeName,
                                   attrtypes.kMFnMessageAttribute).object(),
                False)
        else:
            destinationPlug = dep.findPlug(nodeAttributeName, False)
            plugs.disconnectPlug(destinationPlug)

        if self._mfn.hasAttribute(attributeName):
            # we should have been disconnected from the destination control above
            sourcePlug = self._mfn.findPlug(attributeName, False)
        else:
            newAttr = self.addAttribute(attributeName, None,
                                        attrtypes.kMFnMessageAttribute)
            if newAttr is not None:
                sourcePlug = newAttr
            else:
                sourcePlug = self._mfn.findPlug(attributeName, False)
        with plugs.setLockedContext(sourcePlug):
            if destinationPlug.isLocked:
                destinationPlug.isLocked = False
            plugs.connectPlugs(sourcePlug, destinationPlug)
            destinationPlug.isLocked = True
        return destinationPlug
Exemplo n.º 5
0
 def test_disconnect(self):
     node2 = cmds.createNode("transform")
     node3 = cmds.createNode("transform")
     plugSource = plugs.asMPlug(node2 + ".translate")
     plugMid = plugs.asMPlug(self.node + ".translate")
     plugDest = plugs.asMPlug(node3 + ".translate")
     plugs.connectPlugs(plugSource, plugMid)
     plugs.connectPlugs(plugMid, plugDest)
     plugSource.isLocked = True
     plugMid.isLocked = True
     plugDest.isLocked = True
     self.assertTrue(plugs.disconnectPlug(plugMid))
     self.assertFalse(plugSource.isSource)
     self.assertFalse(plugMid.isSource)
     self.assertFalse(plugDest.isSource)
     self.assertFalse(plugDest.isDestination)