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()
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
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
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)
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)
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)
def getOriginalPlug(self): original = commonUtils.findPlug(self.thisMObject(), ApplyConnectionOverride.kOriginalLong) if not original.isConnected: self._restoreOriginalPlug(original) return original
def reapply(self, overridden): for node, attrName, nextOvr in overridden: self._createApplyOverride(commonUtils.findPlug(node, attrName), nextOvr) self.update()
def _getChildIndex(self): plug = commonUtils.findPlug(self.getShape(), "childIndex") return plug.asInt() if plug else None
def _setChildIndex(self, value): plug = commonUtils.findPlug(self.getShape(), "childIndex") if plug: plug.setInt(value)
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)
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