def doAction(self, target, source): """ This method performs the override action for a given target and source. """ # NOTE: doAction should never add commands in the undo stack shaderPlug = utils.plugSrc(source) if shaderPlug: surfaceShader = shaderPlug.node() shadingEngine = target.node() # Break any connections to old surface shader fnShadingEngine = OpenMaya.MFnDependencyNode(shadingEngine) connections = fnShadingEngine.getConnections() for c in connections: if c.isDestination: fn = OpenMaya.MFnDependencyNode(c.source().node()) nodeClass = OpenMaya.MNodeClass(fn.typeName) if 'shader/surface' in nodeClass.classification: utils.disconnect(c.source(), c) # Make connections to new surface shader connections = ShaderOverride._getNewConnections( surfaceShader, shadingEngine) # Turn reference edits on if restoring the original. with handleRestoringOriginalCtx(): for c in connections: utils.connect(c[0], c[1])
def _transferConnectedPlug(src, dst): if src.isDestination: fromSrc = utils.plugSrc(src) # Turn reference edits on if restoring the original. with handleRestoringOriginalCtx(): utils.connect(fromSrc, dst) elif src.isCompound and dst.isCompound: for idx in range(0, src.numChildren()): transferPlug(src.child(idx), dst.child(idx))
def getPrevious(self): """Return the list item before this one. If there is no previous item, returns None.""" previousPlug = utils.findPlug(self, ListItem.previous) srcPlug = utils.plugSrc(previousPlug) if not srcPlug: return None previousFn = OpenMaya.MFnDependencyNode(srcPlug.node()) return previousFn.userNode()
def _hasOverrideApplied(mplug): # Check if a value override is applied src = utils.plugSrc(mplug) if src and commonUtils.isNodeInstance(src.node(), applyOverride.ApplyOverride): return True # Check if a connection override is applied dst = utils.plugDst(mplug) for d in (dst if dst else []): if commonUtils.isNodeInstance(d.node(), applyOverride.ApplyOverride): return True
def onAttributeChanged(self, msg, plg, otherPlug, clientData): if msg & OpenMaya.MNodeMessage.kAttributeSet: # Plug itself might be overridden, or its parent might be # overridden. plugs = [plg] if plg.isChild: plugs.append(plg.parent()) for p in plugs: # Get rid of uninteresting plugs as quickly as possible. # # 1) Overridden plug is connected, by definition. if not p.isConnected: continue # 2) If plug's node is a render setup node, not interesting. nodeFn = OpenMaya.MFnDependencyNode(p.node()) if typeIDs.isRenderSetupType(nodeFn.typeId): continue # Check if the plug is connected to an apply override node. src = utils.plugSrc(p) if src is None: continue node = OpenMaya.MFnDependencyNode(src.node()).userNode() if not isinstance(node, applyOverride.ApplyOverride): continue # Query the autoKeyer only if a plug is interesting. # Autokeyer should not be listening during undo / redo, # only when the attribute is initially set. if 'autoKeyedAttr' not in locals(): inUndoRedo = OpenMaya.MGlobal.isUndoing() or \ OpenMaya.MGlobal.isRedoing() autoKeyedAttr = set() if inUndoRedo else autoKey.autoKeyed( ) autoKeyed = p.name() in autoKeyedAttr # At this point we know the node can handle the override. # No need to call ApplyValueOverride.canHandleSetOverride # to validate, because that method has been called by # isPassiveOutput, which returned true to allow the # attribute to be changed and therefore end up in this # notification. node.handleSetOverride(p, autoKeyed) # all plugs between override and target plug should never be dirty plug.Plug(p).value break