Script Problem VS Studio AFX

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
formfrei
Posts: 2
Joined: July 16th, 2021, 1:05 am

Hi,

i recently started scripting and wrote a script for After Effects in VS Studio, which works fine when i launch it from Visual Studio. But as soon as i save it and run the script from After Effect it gives me an error message: "unable to execute at line 20..."

which is a function in my script. everything before gets executed.

I have Variables (a,b) in my function because i am looking for several Objects meaning CompItem, FootageItem, Folderitem where I'm looking for specific names as a string.
It is a script for a specific project so all the files will be found.

The Function looks like that:

"
function graballItems (a,b){
//alert("OK");
var proj,curItem,itemTotal,MyItem;
proj = app.project;
itemTotal = proj.numItems;
for (var i =1; i<= itemTotal; i++){
curItem = proj.item(i);
if (curItem instanceof b && curItem.name.indexOf(a) !== -1 ){
return curItem;

}

}
throw new Error("could not find item!");
}

var myCompBeauty = graballItems("CAN_ENDTAG_PRE",CompItem);
//alert("Beauty Comp ="+ myCompBeauty.name);

"

Strange enough when i have the alert line active the script works but when it commented out it doesn't work.

cheers

Martin

User avatar
zlovatt
Posts: 47
Joined: October 31st, 2016, 5:00 pm
Location: Portland
Contact:

Can you post the full error? The part you left to "..." probably tells you exactly what the issue is.

Would also help if you let us know which line of what you pasted is the line 20 that it's talking about.

formfrei
Posts: 2
Joined: July 16th, 2021, 1:05 am

Sorry, i had to do some other stuff and Couzld not response for a long time.

The full Script alert is:
"unable to execute at line 20. Execution halted"

And the Line number changes every now and then sometimes it's 19or 20 or 21. Which is around this part of the script:
for (var i =1; i<= itemTotal; i++){
curItem = proj.item(i);
if (curItem instanceof b && curItem.name.indexOf(a) !== -1 ){

Worth to mention that i call the function several times whith different Parameters for the a,b variable.
It looks like there is the Problem, because seems to me that the function works for the first time but when it calls the function a second time it throws the error. (But as mentioned only when i run it via Afx. When i launch it through VSCode it works all fine)

That's how i call the functions afterwards:

var myCompBeauty = graballItems("ENDTAG_PRE",CompItem);
//alert("Beauty Comp ="+ myCompBeauty.name);

var myCompReflection = graballItems("ENDTAG_4K",CompItem);
//alert("ReflectionComp ="+myCompReflection.name);

var FootageFolder = graballItems("Int_frost",FolderItem);
//alert(FootageFolder.name);

var DelFile = graballItems("Frost_INT_rr",FootageItem);
//alert(DelFile.name);

Thanks and Cheers

Post Reply