PDA

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


Spireite
01-06-2007, 03:29 PM
Hey,

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

1)
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.

2)
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!!

Thanks

sunit
01-08-2007, 06: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.

-sunit

Spireite
01-08-2007, 10: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.

sunit
01-09-2007, 01: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?

-sunit

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

Spireite
01-09-2007, 02:45 PM
OK,

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;



syntax.setObjectType(MSyntax::kSelectionList);

syntax.useSelectionAsDefault(true);

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-09-2007, 03: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.

Spireite
01-09-2007, 03: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-09-2007, 03: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.