Expression evaluation is too late!

Hello. I find a problem with expression.
I'd like to write expression that continuously evaluated as I doing action - such as moving object.

for exaplme, here is a expression.

float $pos[] = getAttr target.translate;
print($pos[0] + " " + $pos[1] + " " + $pos[2] + "n");
obj.tx = $pos[0];
obj.ty = $pos[1];
obj.tz = $pos[2];

I expect that target's translation is printed continuously and obj is follow target's movement as I move target. But when I move target, it didn't. The expression is not evaluated. And when I select other frame in framebar, then the expression is evaluated ( target translation is printed and obj moved. )

I think Maya perfrom some trick in expression for fast evaluation. I think Maya take into account relationship of current change (user input or frame advance) and each expression statement.

For example. I changed some statement as follows:

float $pos[] = getAttr target.translate;
print($pos[0] + " " + $pos[1] + " " + $pos[2] + "n");
obj.tx = $pos[0] + target.tx*0; // add noop sentence
obj.ty = $pos[1];
obj.tz = $pos[2];

I added no operation sentence "+ target.tx*0" which have always zero value to the statement which set obj's X translation. Then this expression perform the same, except when I move target in X direction. When I move target in X direction, expression is evualuated continuously, other directin is not. I think Maya just evaluate statements which contain attribute names depend on current user action (translation or rotation, which direction? etc... ) How do you think about this?

Because of the lack of continuously expression evaluation, I cannot use expression! Is there any way to evaluate expression instantly?

I've had problems like that. I usually add aL

$startFrame = 0//whatever your start frame is

if (frame > $startFrame)
{
float $pos[] = getAttr target.translate;
print($pos[0] + " " + $pos[1] + " " + $pos[2] + "n");
obj.tx = $pos[0];
obj.ty = $pos[1];
obj.tz = $pos[2];
}

Give that a try.

Thank you for your reply. May be that is work in "play" status. Maybe Maya's expression is useful for frame(time)-dependent task.

But what I want to do is not frame-dependent. It must be evaluated continuously at one frame as well as along many frame advances. I want to implement something like constraint - "obj" is moving continuously as I select and drag mouse to move "target".

Maybe it's impossible with expression... ;;; due to the trick(maybe) in expression evaluation in Maya.

Therefore I implemented some constraints using other DG node and MEL functions... But I think using expression is more simple way if possible.

Is there any way to evaluate expression continuouly in one frame...?

What I gave you is not frame dependent. It will force Maya to evaluate the expression at every frame after the start frame.

Well. I cannot explain it well. ^^;
maybe 'frame dependent' is not a good term...

Consider constraint and it's user interface. I talk about maybe user interface.

If there is a constraint, a target and a constrained, good constraint tool support instant user feedback. That is, as the user move target by mouse dragging, the constrained object follow it instantly ( instantly means on dragging not when release button ). This is user interface of feedback which most constraint tool support. And I cannot implement this feedback by expression.

Thanks and more discussin is welcomed.
I'm a programmer and actually I'm newbie at Maya.
I think there are many topics to discussion in MEL/Plugin/Expression... of Maya.

I understand what you want now. What is needed is a manipulator plug-in. Look it up in the devKit. I haven't tried to make one yet, so I wouldn't be of too much help.