How to select transform node from kLocator active selection (Maya)

Hey guys and gals,

I have a question about selecting a transform node from a kLocator selection in the Maya API (C++).

Here is some pseudo code for what I am doing:

MSelectionlist selection;
MGlobal::getActiveSelectionList(selection);

for(MItSelectionList sIter(selection, MFn::kLocator); !sIter.isDone(); sIter.next())
{
MDagPath dagPath;
MObject mLocator;
sIter.getDagPath(dagPath, mLocator);

 ...how to select the locators transform here?

}

I would image you would get it via MDagPath, but I am totally blanking on how to achieve this.
Thanks for reading! :):

Once you have the dagPath for the locator, you can do something like the following to get the transform.

MFnDagNode dagFn(dagPath);
MObject transform = dagFn.parent(0);

Not sure if you wanted to just find the transform, or actually select it. If you want to replace the active selection with the locator’s transform, you can then do something like this:

MDagPath xformDagPath;
MDagPath::getAPathTo(transform, xformDagPath);
MSelectionList xformSelection;
xformSelection.add(xformDagPath);
MGlobal::setActiveSelectionList(xformSelection);

Warning: The above code is untested. Hopefully it works, but it probably doesn’t. :):

With MDagPath dp, calling dp.transform() returns the transform node (as an MObject)

Actually, the documentation describes the function as “Returns the last transform node on the path”…

which is not what you want, so the parent(0) would be correct

:):