renderQueueItem.onStatusChanged only called once

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
dheidel
Posts: 2
Joined: May 28th, 2010, 2:55 pm

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: Select all

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);
	
	
}
dheidel
Posts: 2
Joined: May 28th, 2010, 2:55 pm

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: Select all

currentItem.onStatusChanged=statusChange(i);
should have read:

Code: Select all

currentItem.onStatusChanged=statusChange;
And instead of defining the function:

Code: Select all

function statusChange(index)
It should be:

Code: Select all

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
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

If you want to pass an argument to your function you can do it like this:

Code: Select all

currentItem.onStatusChanged= function () 
   {
   statusChange(i);
   }
-Lloyd
Post Reply