ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Script runs correctly when run manually, but it gives an error when run on Start Up

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Gregory Forster
Script runs correctly when run manually, but it gives an error when run on Start Up
on Mar 13, 2019 at 4:05:34 am

I have a script that runs correctly when I load the project and run it myself. However, when I run it on start up by putting it in the StartUp folder it gives me this error:

"Unable to execute script at line 1. After Effects error: Unable to call "item" because of parameter 1. The range has no values"

Thanks,
Greg


Return to posts index

Dan Ebberts
Re: Script runs correctly when run manually, but it gives an error when run on Start Up
on Mar 13, 2019 at 4:17:20 am

It might help if we could see the script.

Dan



Return to posts index

Gregory Forster
Re: Script runs correctly when run manually, but it gives an error when run on Start Up
on Mar 13, 2019 at 4:29:15 am

Oh yeah, that makes sense...

var compToBeOutput = app.project.item(35);
var comp1 = app.project.item(1);
var numGames = 7;
var p = 3;

compToBeOutput.duration = (90*numGames)/30;

compToBeOutput.layers.add(comp1);


for (i = 0; i<numGames-1; i++) {
var newComp = comp1.duplicate();
var newLayer = compToBeOutput.layers.add(newComp);
newLayer.startTime = p;
p = p + 3;
}


Return to posts index


Dan Ebberts
Re: Script runs correctly when run manually, but it gives an error when run on Start Up
on Mar 13, 2019 at 5:30:58 am

My guess is that even when you launch AE by double-clicking a project file, any startup scripts get run after the plugins load, but before the project does. So it won't know what to make of app.project.item(35) because there won't be any items yet.


Dan



Return to posts index

Gregory Forster
Re: Script runs correctly when run manually, but it gives an error when run on Start Up
on Mar 13, 2019 at 5:39:07 am

Yeah I think that's the case. Thanks.

I added a .sleep to the script to make it wait for 10 seconds and the project didn't load until the scripts completed.


Return to posts index

Dan Ebberts
Re: Script runs correctly when run manually, but it gives an error when run on Start Up
on Mar 13, 2019 at 5:51:29 am

I don't know if this will work, but here's what I'd try. Wrap your startup code in a function, make that function part of the app object, and schedule it to run as a task in 5 seconds, like this:


function myInit(){
var compToBeOutput = app.project.item(35);
var comp1 = app.project.item(1);
var numGames = 7;
var p = 3;

compToBeOutput.duration = (90*numGames)/30;

compToBeOutput.layers.add(comp1);

for (i = 0; i<numGames-1; i++) {
var newComp = comp1.duplicate();
var newLayer = compToBeOutput.layers.add(newComp);
newLayer.startTime = p;
p = p + 3;
}
}
app.Init = myInit;
app.scheduleTask("app.Init();",5000,false);



Dan



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]