View Full Version : accessing an MPxLocatorNode's member: worldPosition

02-08-2010, 09:24 AM
Hi, I am writing a custom locator and want to access its worlPosition attribute. This attr is native to the MPxLocatorNode class. It is listed in the class's memberList. When I load my locator node in the connection editor the worldPosition attr is listed.

I wouls like to access this attribute within the locator's compute function. I am not able to access any of the attrs listed in the docs' member list, only the attrs I create.

I've tried using MPlugs:

MObject thisNode = thisMObject();
MFnDagNode dagFn( thisNode );
MPlug worldPosMPlug = dagFn.findPlug( worldPosition, &stat);
MPlug wpxPlug;

double xPos;
wpxPlug = worldPosMPlug.child(worldPositionX, &stat);

//I do this for every axis
//and all I get is zeros

Does anyone know why this is happening?

Robert Bateman
02-08-2010, 12:00 PM
wpxPlug = worldPosMPlug.child(0, &stat);

If you are going to catch all status code with stat, at least check the actual values. That would have directed you to the relevant line immediately...

02-09-2010, 03:32 AM
Thank you for your response, Robert. That would work unfortunately I ran into a new problem with the worldPosition attr. It is an array of compound attrs. It is an array on the chance that the locator is instanced. I guess that makes sense considering it lies beneath a transform node.

If I use the MPlugArray and get the number of elements of, it returns: 0;

The connection editor lists an empty array.

I can only get the 0 index worldPosition if I connect the output of the worldPosition to another attr or call the getAttr command. This initializes the 0 index worldPosition attr.

How do I initialize, a read only attribute within my compute method. I thought of using the postConstructor() but it doesn't change the fact that the worldPosition attribute is read only.

CGTalk Moderation
02-09-2010, 03:32 AM
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.