Expression (2)

I'm wondering if there is a way to create an expression that runs a procedure (global) everytime an attribute on a cutom node is changed. Basicly a expression that works like a scriptjob. It has to be an expression since it has to be renderable and playable which scriptjobs aren't.

Hello,

I'm not really professional, but as far as I know, expressions can not be triggerd by events. But you can run a script when time changes to check if the attributes value is still the same as before. If not let the script call the procedure.

Well fnank R is a bit worng here.

This exactly what expressions DO, they monitor changes in attribs and mark for trigger! heres a sample of one such thing where i use a expression because a scriptjob wont hack it.

CODE
global proc string[] timecode (int $timeBase)
{
   string $build="",$timecode[];
   int $time,$temp,$times[]={60*60*$timeBase,60*$timeBase,$timeBase};
   $time=currentTime -q;
   for ($each in $times){
   $temp=$time/$each;
   $time=$time-$temp*$each;
   if ($temp<10)
      $build+="0";
   $build+=($temp+":");
   }
   if ($time<10)
     $build+="0";
   $build+=$time;
   $timecode[0]=$build;
   return $timecode;
}

headsUpDisplay -removePosition 0 0; //clear the previous one
headsUpDisplay -section          0
              -block            0
              -blockAlignment   "left"
              -blockSize        "medium"
              -label            ""
              -dataFontSize    "large"
              -command          "timecode(24)" //set your timebase here!!
  -attachToRefresh  
              timecode;
expression -n "hudRefresh"
          -s ("headsUpDisplay"+
            "-refresh timecode;")  
          -o "" -ae 1 -uc al; //make sure it refreshes duirng playback.

But thing is dg does not trigger like a event does! it triggers whenever its asked to do so by soem drawing function, thisones a special case that triggers every time changes becaus ethats what in connected to invisibly, forcedly. BUt thing is in general dg onlt triuggers whenever its asked to do so! which maens only whan something changes, offcourse if theres no change for anything in the scene you wouldnt need the ecxpression either!

In general you dont want to force update. But yeah thsi si basicaly what teh DG was designed to do so personaly i dont se any reason toa sk the question? Unless theres something esotreric you are doing.

Could you enlighten us a biyt more.

Thanks for the replies. The example code helped me alot and i finally got it to work.

oh to add on ething... if you havce problems of eveluating something make a dummy locator that draws a shape realt realyy far away. thisway you will force redraw for the calc but nothing truly spectacular seems to happen.

Its morew then once ive done it thisway whan tehy said it wouldnt work.