PDA

View Full Version : addAttr curve length to curve?


ap77
11-27-2008, 07:23 PM
hi guys,

i want to add an attribute to a curve with the value of its length.
It should be updated, when the length changes by scale, etc.
How can I do this?
addAttr -ln "curveLength" ... ??? ... "curvename";

thanks lois

GiantG
11-28-2008, 08:58 AM
Hi...

you have 2 Possibilities:

Expression:
addAttr -ln "arcLength" -at double |curve1;
setAttr -k on |curve1.arcLength;
addAttr -ln "executer" -at double |curve1;
expression -s "curve1.executer = persp.translateX;\r\ncurve1.arcLength = `arclen`;" -o curve1 -ae 1 -uc all ;


ScriptJob:
addAttr -ln "arcLength" -at double |curve1;
setAttr -k on |curve1.arcLength;
scriptJob -e SelectionChanged "setAttr \"curve1.arcLength\" `arclen curve1`;\r";

Note: The Expression Version only updates, when your Persp Cam is mainpulated or time changes
That's because the Expr. needs to be triggered to calc the arclenght. Is not a direct Connection that updates instantly

NaughtyNathan
11-28-2008, 12:30 PM
while both of those methods will work, neither is really the "correct" way to do it based on Maya's DG architecture. The way you should really tackle it is to create a "curve info" node which you connect to the curve. this way you don't create any new attrs or scriptjobs or expressions, but Maya's internal processing just handles everything properly. Maya is jammed full of these nodes which do everything Maya is designed to do.

The node you want is called "curveInfo" and you would set something up like this:

string $crvInfoNode = `createNode curveInfo`;
connectAttr -f curve1.local ($crvInfoNode + ".inputCurve");

where curve1 is the name of your curve. now, any time you want to know your curve's length, you do:

getAttr ($crvInfoNode + ".arcLength");

of course, you could put this into something else like a scriptjob to print it out in a UI or something, but you probably don't need to.. you could create a numeric particle connected to the curve and the info node to report it dynamically to the viewport... all this stuff can usually be done entirely with nodes and connected attrs...

:nathaN

GiantG
11-28-2008, 01:07 PM
Yes...forgot about the "curveInfo" Node.

As Nathan said, direct Node connections are always the best and fastest solution

ap77
11-28-2008, 02:15 PM
thank you very much for your help :)

@ Guido - the skriptJob doesnīt update in realtime and i get an error message when I make a new file: // Error: line 1: No object matches name: curve1 //
--> restart Maya
@ Nathan - "curfeInfo" works good for me (I tried to use the node before, but I didnīt know how to use it :) ), the only thing is that it doesnīt update when I "scale" the curve. When I move a cv it updates and thatīs what I need, so itīs my favorite.

I also have another solution which works good for me:
arcLengthDimension curve1.u[1] ;
// --> I connect it with the scale of another object.
connectAttr -f arcLengthDimensionShape1.arcLength pCube1.scaleX;
connectAttr ...

best
lois

CGTalk Moderation
11-28-2008, 02:15 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.