Ok, this ones easy. You neither need a expression nor variable. this is the educational answer ![]()
The problem is also very clear. Your confusing expressions and mel. Just because the expression language can interpret mel does not mean it is EQUAL to mel. So try to remember MEL is NOT EQUAL the expression language.
Second your confusing the use of mel, which is to build up nodal networks, guis and simple and short brute force algorithms that don't have any speed needs, mel is not a computation language per see.
never ever call anything like this inside a a expression, if you don't know a better method or cant find one then your likely to look at the problem the wrong way around.
$t= xform - Q - ws - T joint1
;
You see it often, especially with the rolling wheel problem does not make it right. (just because all your friends choose to do suicide does not mean you should). In practice xformis never needed, setAttr and getAttr have some very limited uses even so 99% of all cases where you end up seeing them used are not so smart. The problem with this is that it sidesteps the DG and the DG IS THE CALCULATION CORE.
Now to light the matter right way you need to understand that the heart of nodes are forming a computational graph which, works more or less as follows. Node attributes are are built up as a directed instruction set, where each container points in to another, when a upstream container's input is changed all the parts of the outputs that are affected by its result (not all slots necessarily update) are marked as dirty, and their affected are marked dirty, and their affected are marked dirty. It is worth noting no computation took place at this point. It is only when maya gathers information for refresh, that it collects the attributes it needs and instructs them to clean themselves, it is now that maya starts calculating the values, but only those values that affect anything meaningful.
Now enter the misunderstood expression node its syntax is more or less the same as mel's except as follows.
something.something=
is not a assignment only ever $something= is a assignment (this is why mel has $ not because its a batch like language and easier to parse but so not to confuse these two). It is a macro for the expression node that issues it to create a attribute slot and connection at that handle when the expression command sets the expression. More subtly the expression language compiles the expression and marks the affected network to all outputs. Now this means a few things, but most importantly that something.something= must be explicitly known at this point so no dynamic attribute setting.
Now if your really smart you can get the implications of above (stop and think
) they are as follows :
Nodes as in general terms don't need to and should not ever operate on data thats from outside themselves. That would defeat the entire purpose of their design. It is also very dangerous and possibly very slow, because dg no longer computes optimally but in random order, wcih can cause it to evaluate multiple times (this can be desirable in certain super funky situations)Triggers only travel trough real connections. The hardest implication is that any mel is a literal string, but any direct connection isn't. This plays a huge role once you start referencing stuff.Avoids loop as a clean attribute is not re dirtyedNo asking $t=
xform - Q - ws - T joint1
; causes maya to break thise 3 things. Having all their downsides.
Now then how were you supposed to tackle the problem?
Well first theres no problem. if you wish to measure distance between 2 points use distanceBetween jsut plunk the inverse world coordinates to matrices, or easier use a distanceDimShape , if not then you can use all of the following a vectorProduct shading node as well as pointMatrixMult node and surprising point constraint node to convert between the spaces. If you feel need to work out the distance yourself or work on some very funky projection of it.
So if you wished the distance between 2 joints you'd do this:
CODE
{
//lets create some demodata to act on
$start=joint -p -3.089344 0 8.79561
;
joint -p -10.914267 0 0.9471;
joint -e -zso -oj xyz -sao yup joint1;
joint -p -1.948909 0 -2.727247;
joint -e -zso -oj xyz -sao yup joint2;
joint -p 6.136342 0 1.566546;
joint -e -zso -oj xyz -sao yup joint3;
$end=joint -p -0.173659 0 -9.793508
;
//end of demodata
$dist=createNode distanceBetween
;
//note joints dont need positions they always reside in 0 in their own space
connectAttr ($start+".wm") ($dist+".im1" );
connectAttr ($end+".wm") ($dist+".im2" );
//connect ($dist+".d" ) to something
}
now theres several other ways if you want to see the distance use a distanceDimShape instead.
but now i must go and feed my girlfriend. to be continued.