AE ENHANCERS

Expressions/Scripts/Presets
It is currently Sat May 18, 2013 8:37 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: renderQueueItem.onStatusChanged only called once
PostPosted: Sat May 29, 2010 1:58 am 
Offline

Joined: Fri May 28, 2010 2:55 pm
Posts: 2
Hello,

I'm trying to write a script that does something after each item in the render queue gets rendered. I'm setting the onStatusChanged callback, but it only seems to be calling my function immediately after I set the callback, so that even though the status has not changed, the function gets called. From then on, the function never gets called again, even if I change the status to unqueued immediately after setting onStatusChanged. And it certainly doesn't get called when the status goes from queued to rendering or from rendering to done. Am I doing something wrong (I'm new to AE scripting)? Any help would be greatly appreciated. I'm on CS4 on a Mac 10.6.3. Code is below. Thank you.

- David

Code:
function traverseRenderQueue()
{
   var myProject = app.project;
   var myRQ = myProject.renderQueue;
   var i = 1;

   for (i = 1; i<=myRQ.numItems;i++)
   {
      var currentItem = myRQ.item(i);
      if (currentItem.status == RQItemStatus.QUEUED)
      {
         currentItem.onStatusChanged=statusChange(i);
      }
}
   myRQ.render();
   alert("All Done");
}

function statusChange(index)
{   
   app.project.renderQueue.pauseRendering(true);   
   var currentItem = app.project.renderQueue.item(index);
   
   alert("Status for "+currentItem.comp.name+" changed to: "+currentItem.status); //Only called immediately after setting onStatusChanged
   
   if (currentItem.status == RQItemStatus.DONE)
   {
      alert("I got here"); //Never called         
      
   }
   app.project.renderQueue.pauseRendering(false);
   
   
}


Top
 Profile  
 
 Post subject: Re: renderQueueItem.onStatusChanged only called once
PostPosted: Tue Jun 01, 2010 8:34 pm 
Offline

Joined: Fri May 28, 2010 2:55 pm
Posts: 2
Never mind. Got it working! If anybody else struggles with this, the issue was that the callback function can't have an argument, so the line:

Code:
currentItem.onStatusChanged=statusChange(i);


should have read:

Code:
currentItem.onStatusChanged=statusChange;


And instead of defining the function:

Code:
function statusChange(index)


It should be:

Code:
function statusChange()


You can use the "this" keyword to get the current RenderQueueItem, which is what I was trying to do all along by having the argument in the function call (although I couldn't figure out how to get the item index if I only knew the RenderQueueItem, but I was able to work around that). Maybe this is obvious for long-time javascript-ers (which I'm not), but it would have been nice if there was something in the documentation about that.

Anyway, this is a great site; looking at the archives has been a fantastic resource for delving into AE scripting.

- David


Top
 Profile  
 
 Post subject: Re: renderQueueItem.onStatusChanged only called once
PostPosted: Wed Jun 02, 2010 6:57 pm 
Offline
Enhancement master
User avatar

Joined: Thu Jun 17, 2004 9:27 am
Posts: 456
Location: New York City, NY
If you want to pass an argument to your function you can do it like this:

Code:
currentItem.onStatusChanged= function ()
   {
   statusChange(i);
   }


-Lloyd

_________________
http://aescripts.com


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: No registered users and 1 guest


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