AE ENHANCERS

Expressions/Scripts/Presets
It is currently Mon May 20, 2013 12:24 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: how to make value persistent
PostPosted: Fri May 23, 2008 8:21 am 
Offline

Joined: Mon Jan 16, 2006 12:08 pm
Posts: 18
Hi! I made an expression (applied on timeRemap of a sequence) that displays a specific frame of a sequence based on the position of a guide layer. If the guide layer (called "temoin" in the following code) is over a certain reference layer (in "targetComp" in the code), it then displays a specific frame based on the reference layer index. The problem is that by default it always resets to 1. I would like it to keep the last valid value. Is there a a way to achieve this?

Thanks,
Louis

Code:
targetComp = comp("as_claydog");
temoin = thisComp.layer("temoin");
curClosestIndex = null;
previousFrame = timeRemap;

for (var i = 1; i <= targetComp.numLayers; i++)
{
   layerPos   = targetComp.layer(i).position;
   layerWidth   = targetComp.layer(i).width/2*(targetComp.layer(i).scale[0]/100);
   layerHeight= targetComp.layer(i).height/2*(targetComp.layer(i).scale[1]/100);
   minX      = layerPos[0] - (layerWidth);
   maxX      = layerPos[0] + (layerWidth);
   minY      = layerPos[1] - (layerHeight);
   maxY      = layerPos[1] + (layerHeight);
   curPos   = temoin.position;
   if ( curPos[0] > minX && curPos[0] < maxX)
   {
      if ( curPos[1] > minY && curPos[1] < maxY)
      {
         curClosestIndex = i;
      }
   }
}

if (curClosestIndex != null)
{
   frames = curClosestIndex -1;
   fps = 1.0 / thisComp.frameDuration;
   timeRemap = framesToTime(frames, fps );
} else {
   timeRemap = previousFrame;
}


Top
 Profile  
 
 Post subject: Re: how to make value persistent
PostPosted: Sat May 24, 2008 10:32 am 
Offline

Joined: Wed Jul 20, 2005 12:07 am
Posts: 139
You need to create another loop that forces the expression to evaluate for every frame while(x < thisComp.duration){}.

Mylenium

_________________
[Pour Mylène, ange sur terre]


Top
 Profile  
 
 Post subject: Re: how to make value persistent
PostPosted: Thu Jun 05, 2008 7:46 am 
Offline

Joined: Mon Jan 16, 2006 12:08 pm
Posts: 18
Thank you, it worked perfectly. Here is the final script.
Code:
targetComp      = comp("as_claydog");
temoin            = thisComp.layer("temoin");
curClosestIndex   = null;
timeIndex         = time;
fps               = 1.0 / thisComp.frameDuration;

while (curClosestIndex == null && timeIndex > temoin.startTime)
{
   curClosestIndex = evalPos(targetComp, temoin, timeIndex);
   timeIndex = timeIndex - framesToTime(1, fps );
}

frames      = curClosestIndex -1;
timeRemap   = framesToTime(frames, fps );


function evalPos(targetComp, temoin, timeIndex)
{
   for (var i = 1; i <= targetComp.numLayers; i++)
   {
      layerPos      = targetComp.layer(i).position.valueAtTime(timeIndex);
      layerWidth   = targetComp.layer(i).width/2*(targetComp.layer(i).scale.valueAtTime(timeIndex)[0]/100);
      layerHeight   = targetComp.layer(i).height/2*(targetComp.layer(i).scale.valueAtTime(timeIndex)[1]/100);
      minX         = layerPos[0] - (layerWidth);
      maxX         = layerPos[0] + (layerWidth);
      minY         = layerPos[1] - (layerHeight);
      maxY         = layerPos[1] + (layerHeight);
      curPos         = temoin.position.valueAtTime(timeIndex);
      if ( curPos[0] > minX && curPos[0] < maxX)
      {
         if ( curPos[1] > minY && curPos[1] < maxY)
         {
            return(i);
         }
      }
   }
   return(null);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group