Maya API How-To #16 | ||
| ||
How can I name a newly created MPxLocatorNode-derived object so its transform is "myNode" and its shape is "myNodeShape"?When you create a node that is defined in a MPxLocatorNode-derived class, Maya will automatically create a transform (assuming you haven't specified one): createNode "myNodeType"; This results in a DAG of: myNodeType1 Or: createNode "myNodeType" -name useThisName; useThisName For my own nodes, I prefer to have the transform name correspond to the node's type, and the shape node to identify itself as the shape. What I want is this: myNodeTypeShape1 You can use the MPxLocatorNode::postConstructor() method to name the newly created node. void myMPxLocatorNode::postConstructor() { MFnDependencyNode nodeFn(thisMObject()); nodeFn.setName("myNodeType#"); } This results in the same thing we saw above: createNode "myNodeType"; myNodeType1 The key is the use of the term "Shape" in the name you specify for your new node. Maya will use this as a hint when generating a name for its associated transform. void myMPxLocatorNode::postConstructor() { MFnDependencyNode nodeFn(thisMObject()); nodeFn.setName("myNodeTypeShape#"); } The result is: myNodeTypeShape1 The hash ("#") here works the same as in MEL - Maya will replace it with a numeric suffix to guarantee a unique name for the new node, generating successive nodes with the names "myNodeTypeShape1", "myNodeTypeShape2", etc. This leaves one quirk still lingering, however. createNode "myNodeType" -name useThisName; useThisName In this case the name provided on the command line overrides the name the
plug-in wants to assign in its postContructor method. When specifying the ‘ createNode "myNodeType" -name useThisNameShape; useThisNameShape This works even if the MPxLocatorNode::postConstructor() method has not been overridden to provide the behavior described in this How-To. Makes one consider that this whole exercise was rather pointless, doesn't it? Acknowledgements
| ||
Copyright ©2005 by Bryan Ewert, maya@ewertb.com Maya is a Registered Trademark of Alias |