0

When using the maya python API to create a new node type, I need to run a "maya.cmds.getAttr" on an attribute immediately after the node is created.

What is the proper way to get a dagPath to the node you just created in the postConstructor method?

stowaway
  • 77
  • 9
  • I'm using API2 but either (or both) would be helpful! – stowaway Aug 20 '15 at 22:20
  • Just a quick note here: unexpected behaviour may be exhibited, sometimes even leaving Maya in an unstable state, if a node tries to do anything to the dagPath. I don't know if querying dagPaths by a node is good practice either. Something to be mindful of. Ideally, a node should be blissfully unaware of its place (or anyone s place) in the dagPath. Such things should preferably be coded into commands. – kartikg3 Aug 20 '15 at 23:20
  • Thanks for the tip! In this specific case I need to compute the input from an array of vectors with a predefined number of input points (8). I'm told that the only way to ensure that the array has the correct number of elements is to run a getAttr on the array index you want to exist. Do you know of a cleaner way? – stowaway Aug 20 '15 at 23:29

1 Answers1

0

When you are in the postConstrutor() method, you can use the 'thisMObject()' reference to access the node instance. From there, you can create the MDagPath and pass it to your getAttr commmand. But you do not need to do this, because you can use the API instead to access the attribute. For example:

thisNode = self.thisMObject()
plug = om.MPlug( thisNode, footPrint.size )
sizeVal = plug.asMDistance()

thisMObject() -> MObject

Returns the MObject associated with this user defined node. This makes it possible to use MFnDependencyNode or to construct plugs to this node's attributes.

cyrille
  • 2,616
  • 1
  • 10
  • 18