Esempio n. 1
0
    def refresh(self, imposeRefresh):
        node = commonUtils.nameToNode(RS_DEFAULT_RENDER_GLOBALS)
        self.startFrame = commonUtils.findPlug(node,
                                               RS_START_FRAME).asMTime().value
        self.endFrame = commonUtils.findPlug(node,
                                             RS_END_FRAME).asMTime().value
        self.animation = commonUtils.findPlug(node, RS_ANIMATION).asBool()

        if self.callback is 0:
            self.callback = OpenMaya.MNodeMessage.addAttributeChangedCallback(
                node, self.defaultRenderGlobalsChanged, None)
        if imposeRefresh:
            self.emitDataChanged()
Esempio n. 2
0
    def __init__(self, plugOrNode, attrName=None):
        """ Constructors:
             Plug(MPlug)
             Plug(string (full plug name))
             Plug(MObject, MObject)
             Plug(MObject, string (attribute name))
             Plug(string (node name), string (attribute name))
        """
        if isinstance(plugOrNode, OpenMaya.MPlug):
            # Plug(MPlug)
            self._plug = plugOrNode
        elif attrName is None:
            self._plug = commonUtils.nameToPlug(plugOrNode)
        else:
            self._plug = commonUtils.findPlug(plugOrNode, attrName)

        if self._plug is not None:
            # There is no consistency around the node name (i.e. child node names)
            # and the attribute name (i.e. long vs. short names and compound names)
            # between the various API methods. To avoid different names, Plug is now always using
            # the same API methods.
            self._nodeName = commonUtils.nodeToLongName(self._plug.node())
            self._attributeName = self._plug.partialName(
                includeInstancedIndices=True, useLongNames=True)
            self._name = self._nodeName + '.' + self._attributeName

        self._type = None if self._plug else Plug.kInvalid
Esempio n. 3
0
def getExpandedState(node):
    """ Retrieves the expanded state attribute of the node """

    plugRef = commonUtils.findPlug(node, kExpandedStateString)

    # If the attribte doesn't exist, just return False
    return plugRef.asBool() if plugRef is not None else False
Esempio n. 4
0
 def _restoreOriginalPlug(self, original):
     # If the original shading engine was in a referenced file, the
     # connection to it may have been broken.  To deal with this
     # case, we also stored the shading engine name as a string.
     originalStr = commonUtils.findPlug(
         self.thisMObject(), MaterialOverride.kShadingEngineNameLong)
     if originalStr is not None:
         originalNode = commonUtils.nameToNode(originalStr.asString())
         if not originalNode.isNull():
             fnEngine = OpenMaya.MFnDependencyNode(originalNode)
             enginePlug = fnEngine.findPlug('message', False)
             utils.connect(enginePlug, original)
Esempio n. 5
0
    def iter_override_targets(override):
        try:
            for target in override._targets():
                yield target
        except AssertionError:
            # Workaround: There is a bug where the private `_targets()` method
            #             fails on some attribute plugs. For example overrides
            #             to the defaultRenderGlobals.endFrame
            #             (Tested in Maya 2020.2)
            print("Workaround for %s" % override)
            from maya.app.renderSetup.common.utils import findPlug

            attr = override.attributeName()
            if isinstance(override, UniqueOverride):
                node = override.targetNodeName()
                yield findPlug(node, attr)
            else:
                nodes = override.parent().selector().nodes()
                for node in nodes:
                    if cmds.attributeQuery(attr, node=node, exists=True):
                        yield findPlug(node, attr)
Esempio n. 6
0
def setExpandedState(node, value):
    """ Sets an attribute on the node storing the expanded state of
    this node in the view. Creates it if it doesn't exist """

    # Get the plug associated with the expanded state attribute
    plugRef = commonUtils.findPlug(node, kExpandedStateString)
    if plugRef is None:
        # If it doesn't exist, we create it. It's a Plug object, Python side
        plugRef = plug.Plug.createAttribute(node, kExpandedStateString,
                                            kExpandedStateString, {
                                                'type': 'Bool',
                                                'connectable': False
                                            }, plug.kNotUndoable)
        plugRef.value = value
    else:
        # If it already exists, we set its value. It's a MPlug object, OpenMaya side
        plugRef.setBool(value)
Esempio n. 7
0
 def getOriginalPlug(self):
     original = commonUtils.findPlug(self.thisMObject(),
                                     ApplyConnectionOverride.kOriginalLong)
     if not original.isConnected:
         self._restoreOriginalPlug(original)
     return original
Esempio n. 8
0
 def reapply(self, overridden):
     for node, attrName, nextOvr in overridden:
         self._createApplyOverride(commonUtils.findPlug(node, attrName),
                                   nextOvr)
     self.update()
Esempio n. 9
0
	def _getChildIndex(self):
		plug = commonUtils.findPlug(self.getShape(), "childIndex")
		return plug.asInt() if plug else None
Esempio n. 10
0
	def _setChildIndex(self, value):
		plug = commonUtils.findPlug(self.getShape(), "childIndex")
		if plug:
			plug.setInt(value)
Esempio n. 11
0
	def _setPrivateValue(self, attrName, value):
		""" Utility method to set the value of a private attribute. 
		An attribute that is only used internally and cannot have overrides on it. """
		plug = commonUtils.findPlug(self.getShape(), attrName)
		if plug:
			self._setPlugValue(plug, value)
Esempio n. 12
0
	def attributeType(self, column):
		attr = self.attributes.findAttributeByIndex(column)
		if not attr:
			return plugModule.Plug.kInvalid
		plug = commonUtils.findPlug(self.getShape(), attr.name)
		return plugModule.Plug(plug).type if plug else plugModule.Plug.kInvalid