def postConstructor(self) :
depNodeFn = OpenMaya.MFnDependencyNode(self.thisMObject())
inputPlug = depNodeFn.findPlug("input")
it = OpenMaya.MItDependencyNodes ( OpenMaya.MFn.kTime)
if not it.isDone() :
time = it.thisNode()
depNodeFn.setObject(time)
outputPlug = depNodeFn.findPlug("outTime")
dgMod = OpenMaya.MDGModifier()
dgMod.connect(outputPlug, inputPlug)
dgMod.doIt()
else :
print "No time node in the scene, no connection done"
Hey Oliver, Thanks for the fast reply. I created a postConstructor
function within my nodes class after the compute function, here's what
i have so far...
----------------------------------------------------------------------------------------------------------------------------------------------------------------
class nmpSineWave(OpenMayaMPx.MPxNode):
# establish INPUT and OUTPUT var's
INPUT = OpenMaya.MObject()
OUTPUT = OpenMaya.MObject()
AMPLITUDE = OpenMaya.MObject()
FREQUENCY = OpenMaya.MObject()
PHASE = OpenMaya.MObject()
RAND = OpenMaya.MObject()
def __init__(self):
OpenMayaMPx.MPxNode.__init__(self)
def compute(self, plug, dataBlock):
...computeShtuff...
def postConstructor(self):
## get current node instance as MObject
nodeObjHandle = self.thisMObject()
depNodeFn = OpenMaya.MFnDependencyNode()
# set function to operate on node MObject
depNodeFn.setObject(nodeObjHandle)
# test and print if node has a ".input" attribute
(prints TRUE)
hasAttr = depNodeFn.hasAttribute("input")
OpenMaya.MGlobal.displayInfo("node has .input Attr =
%s" % (hasAttr))
# find plug to the nodes input attribute
inputPlug = depNodeFn.findPlug("input", 0)
# print nodes name and name of inputs plug (Node =
"") (input = ".input")
OpenMaya.MGlobal.displayInfo("Node Name = %s" %
(depNodeFn.name()))
OpenMaya.MGlobal.displayInfo("inputPlug = %s" %
(inputPlug.name()))
# create string for maya to connect time into
node.input
cmd = "connectAttr \"time1.outTime\" %s" %
( inputPlug.name() )
# execute mel command
OpenMaya.MGlobal.executeCommand(cmd)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
As of now i get an error saying the destination attribute ".input"
could not be found. I used the displayInfo commands there to then test
if the attribute existed on that node and to print out the nodes name
as well as the name of the plug for the "input" attribute. It prints
out True for having an actual ".input" attribute existing in the node
but prints blank for the node name and only prints ".input" for the
inputPlug instead of "nodeName.input".
I cant quite figure out why the node name isn't getting stored/used by
the inputPlug even though it says that depNodeFn does indeed have an
attribute ".input". Im pulling my hairs out in frustration over this :
( What am i missing/overlooking here?? Thanks, Nicklas Puetz
--~--~---------~--~----~------------~-------~--~----~
Best Regards,
Maya-Python Club.
-~----------~----~----~----~------~----~------~--~---
You'll notice the node leaves a unitConversion node when it's deleted as
one is created when the callback connects time to it. If you check in
the MNodeMessage class you could set up a callback the same way to break
the connection / delete the unitConversion node in a cleaner way on a
delete.
Just remember when using callback in plugins that they must be added
after the plugin is initialized/loaded (after the node is registered if
it's a node related callback) and removed before plugin is unloaded
(when node is de-registered). Otherwise you'd crash the next time the
callback is called (in C++) or get duplicate calls of the same callback
when pluging is reloaded (in Python)
Olivier