PDA

View Full Version : API: simple enough I think?


redpawFX
09-18-2009, 08:25 PM
I have what seems like a trivial question.. but I'm just hacking my way to learning still.. :-)

I have an MObject attribute created on a custom locator node

in maya I want to connect another nodes output to it (say translate from a sphere)
so I do a connectAttr blah blah blah..

within the API I want to traverse to the connected node (the sphere's translate )
and be able to run a set value command on the sphere's translate directly..

how do I get from the MObject attr on my locator to an MObject attr on the connected sphere?

any help would be much appreciated. thinking I could just use api calls to listConnections mel commands if I needed to , but that seems kinda sloppy.. is there a "list connections" equiv in the API?

thanks

-johnc

Keilun
09-18-2009, 09:16 PM
You'd want to use MPlug.

You need to keep clear the understanding that the MObject attribute is just a structure that defines the attribute characteristics across all nodes of that type. Eg. "All nodes of this type will have an attribute called 'myData'."

In order to look at an instance of that attribute on a specific node, you would use MPlug. Eg. To access, "myNode1.myData", you create an MPlug.

So you want to get an MObject to the instance of the node that you want to query, say myNode1, and then pass in which attribute on that node you're looking for:

MObject myNodeObj;
MObject myDataAttr;

// Retrieve the node you're looking for, be it by the active selection list, or name.
// You should hopefully already have a static MObject on your node class to get the myDataAttr.

// Create an MPlug
MPlug myDataPlug( myNodeObj, myDataAttr );

// Check for connections with the plug as a destination
// connectedTo( connections, asDest, asSource )
//
MPlugArray connections;
myDataPlug.connectedTo( connections, true, false );

// Now, parse the MPlugArray connections, and look at the plugs in that array.
// Search for the one with the matching transform node and .translate attribute.
// And you can do a plug.setValue() from there.
//

CGTalk Moderation
09-18-2009, 09:16 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.