View Full Version : automatically connect to time1.outTime
MatthiasBuehlmann 12-03-2008, 11:30 AM I have a custom locator node (inherited from MPxLocatorNode) with an attribute "currentTime" that should always be connected to the time1.outTime.
Can I wirte some code into my locatorNode such that this connection is automatically created when i create such a node for example using the MEL command
createNode "myLocator"
?
this is my current try, but it's not working because I don't get the pathName:
void DebugLocator::postConstructor()
{
MFnDagNode thisNodeFn;
MObject thisNode = thisMObject();
thisNodeFn.setObject(thisNode);
MString pathName = thisNodeFn.dagPath().fullPathName();
MGlobal::executeCommand("connectAttr time1.outtime " + pathName +".currentTime");
}
thanks
|
|
MatthiasBuehlmann
12-03-2008, 01:27 PM
Now I try it that way:
MFnDependencyNode nodeFn(thisMObject());
MGlobal::selectByName("time1");
MSelectionList selection;
MGlobal::getActiveSelectionList( selection );
MFnDependencyNode time1Fn;
MObject time1Hnd;
stat = selection.getDependNode(0, time1Hnd);
time1Fn.setObject(time1Hnd);
MPlug inPlug = nodeFn.findPlug("currentTime", true, &stat);
MPlug outPlug = time1Fn.findPlug("outTime", true, &stat);
//the code above seems to work, stat is always true
MDGModifier mdgMod;
stat = mdgMod.MDGModifier::connect(outPlug, inPlug);
stat = mdgMod.doIt(); //<- does not succeed
but here i get an error on mdgMod.doIt():
// Error: Connection not made: 'time1.outTime' -> '.currentTime'. Destination node is not in a dependency graph. //
seems the node is not added to the dependency graph during the postConstructor, nor does it have a name yet, so what can I do to create any connections in this phase?
GennadiyKorol
12-03-2008, 03:48 PM
This won't be a good idea, since postConstructor is called for every MPxNode object you derive after it is created. Not the Maya scene object, but C++ runtime class instance.
That means this code will be called when file is opened even if the connection is already made.
Generally I find it simpler to do any initialization in a specially written MPxCommand or simple MEL script that is responsible for creating and initializing your node.
MatthiasBuehlmann
12-03-2008, 04:25 PM
hey GennadiyKorol
Thank you - it's what i did now.
But actually it would still be interesting to know how one could code a node such that it sets up it's necessary connections (like in this case input of scenetime) itself.
thank you
GennadiyKorol
12-03-2008, 07:41 PM
You could setup a global callback for node creation and setup the connections there.
I just requires more labor since all custom nodes are usually created with some MEL written UI/hotkey system and it is easier to setup those connections in that MEL code.
CGTalk Moderation
12-03-2008, 07:41 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.