View Full Version : Creating Custom Locator In A Custom Command From The API

01 January 2007, 04:29 PM

OK so you solve one problem and then two rear their ugly heads!!

Im having difficulty with creating my custom locator using one of my custom commands.

Ive had no difficulty in createing my other nodes which are derived from MPxNode using:

MObject oRoadSelect = dgMod.createNode("RoadSelect");
MFnDependencyNode RdSelDepNodeFn(oRoadSelect);

this works fine for all my nodes yet when i use

MObject oCarLocator = dgMod.createNode("CarLocator");
MFnDependencyNode CarDepNodeFn(oCarLocator);

it compiles fine and pluigs in fine yet when i run the command all the nodes but the locator are created but in Maya if i type createNode CarLocator; maya creates my locator nice and simple.

Again having no difficulty creatin connections between the standard attributes using

dgMod.connect(tRoadTransform.findPlug("Speed"), RdSelDepNodeFn.findPlug("Speed"));

this again works for every connection so far however when i try to connect

dgMod.connect(tRoadTransform.findPlug("worldSpace"), RdSelDepNodeFn.findPlug("Road1"));

I get an error message saying

// Error: Connection not made: '' -> 'RoadSelect1.Road1'. Data types of source and destination are not compatible. //

now the worldspace attribute from the a curveShape node is a typed attribute therfore i created my Road1 attribute to be a typed attribute as well. But the realy strange thing is that i can connect them fine using the connection editor in maya but apparently not with the api using the above method.

Completely Stumped on both counts!!

Suggestions to either question or both are warmly accepted!!


01 January 2007, 07:09 PM
you'll probably want to use MDagModifier rather than MDGModifier to create your locator, since you're creating a dag node, not just a node in the dg.


01 January 2007, 11:37 PM
Thanks for the post ive solved that particular problem having messed around with your sugesstion, if anyone has any idea about how to go about the connection problems with the world space im still open to sugestions.

01 January 2007, 02:58 AM
well, it looks as if maya isn't finding the plug "worldSpace" in your node. are you sure the spelling/caps are correct? is world space an array element? are you actually connecting worldSpace[0] when you make the connection in maya?


Robert Bateman
01 January 2007, 06:57 AM
"worldMatrix" is the world space attr on a dag node ?

01 January 2007, 03:45 PM

thanks for the advice but im still gettin no where, i am trying to connect the worldSpace[0] attribute to the geometryPath on the MotionPath node, i building ontop of stuff that is already available in maya, this connection is made when the user trys to make a motion path buy selecting the object and the curve, i can also make the connection in the connection editor and i can do it with mel yet the API is being a pain and wont do it (yet) this is a section of my code.

MSyntax CreateVehicleCmd::newSyntax()


MSyntax syntax;



return syntax;


MStatus CreateVehicleCmd::doIt ( const MArgList &args)


MStatus stat;

MArgDatabase argData(newSyntax(),args,&stat); // create a parser for the arguments.

if(stat != MS::kSuccess) // make sure the arguments were parsed OK


stat.perror("arguments not parsed correctly");

return stat;


MSelectionList selected; //creates MSelectionList

argData.getObjects(selected); //Stroed Objects in list

MDagPath roadDagPath; //creates a dagPath

selected.getDagPath(0,roadDagPath); //stores dagpath of road in roadDagPath

MFnTransform tRoadTransform; //creates an MFnTransform
tRoadTransform.setObject(roadDagPath); //attaches the DagPath to the transform

MObject oMotionPath = dgMod.createNode("motionPath"); //creates The MObject for the motionPath node
MFnDependencyNode MotionPathNodeFn(oMotionPath); //allows access to the Motion Path Attributes

//Make Connection

dgMod.connect(tRoadTransform.findPlug("worldSpace[0]"), MotionPathNodeFn.findPlug("geometryPath"));

return redoIt(), stat;


ive tried variations in the spelling of worldspace, ive tried worldspace, worldSpace, WorldSpace, wolrdSpace[0] etc.

ive tested that objects are being passed in (eg a sphere) correctly as i have connected normal attributes together with the same code (eg.translateX to translateZ)

Realy driving me nuts now!!

Robert Bateman
01 January 2007, 04:29 PM
// Check to makesure status == MS:kSuccess
MPlug p = tRoadTransform.findPlug("worldSpace",&status);

// make sure you check status somewhere after this as well.....
MPlug worldSpace0 = p.elementByLogicalIndex(0,&status);

// again, check the status after the calls.
status = dgMod.connect(worldSpace0 , MotionPathNodeFn.findPlug("geometryPath"));

I will however gently hint that connecting a transform into an attribute of type nurbsCurve is possibly not the way to go ;) (If you have given it say, "nurbsCurveShape1" then MFnTransform.setObject will fail. If you have given it "nurbsCurve1" then the transform node will not have the worldSpace attr....)

You possibly want to make sure the object passed in is actually a curve?
If it is, then use MFnNurbsCurve (or MFnDependencyNode), but definately not MFnTransform.

01 January 2007, 04:50 PM
Thanks for all the help, i hope im not being to much of a pain, it worked after a bit of tampering but better than that i think i understand why it works now!!

CGTalk Moderation
01 January 2007, 04:50 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.