Skip to main content
Participating Frequently
July 14, 2021
Question

AFX Script Problem Visual Studio Code

  • July 14, 2021
  • 2 replies
  • 1979 views

Hi, 

i recently started scripting and wrote a script in VS Studio for After Effects, which works fine when i run it from Visual Studio. But when 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. 

The Function looks like that: 

 

function graballItems(a, b) {
  var proj, curItem, itemTotal, ItemAry;

  proj = app.project;

  itemTotal = proj.numItems;

  ItemAry = new Array();

  for (var i = 1; i <= itemTotal; i++) {
    curItem = proj.item(i);

    if (curItem instanceof b && curItem.name.indexOf(a) !== -1) {
      ItemAry = curItem;
    }
  }
  return ItemAry;
}

// And i use it like that:

var myCompBeauty = graballItems("CAN_ENDTAG_PRE", CompItem);

 

 

But strange though, that it is working from VS Studio. 

Does anybody know why the error message appears? 

 

Cheers 

Martin 

This topic has been closed for replies.

2 replies

Mathias Moehl
Community Expert
Community Expert
July 15, 2021

The line "ItemAry = new Array()" suggests that you want to return an array of the found items. But in the line

ItemAry = curItem;

you replace your array with a single item.

If you want to grab all items, you most likely want to do

ItemAry.push(curItem)

instead.

 

 

 

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
mmueller2Author
Participating Frequently
July 15, 2021

First of all, thank you both for your quick reply. 

I tried to implement the try and catch statement but without any sucess. 

I implemented the push item command but recognized that i only need one item not an array so i changed it to just get the curitem. But still the same error. 

Last thing i wanted to try to set an alert line by line to check where the code breaks exactly. 

Strange enough the script works like that: 

 

function graballItems (a,b){
    alert("OK");
    var proj,curItem,itemTotal,MyItem;
    proj = app.project;
    itemTotal = proj.numItems
    for (var i =1i<= itemTotali++){
        curItem = proj.item(i);
        if (curItem instanceof b && curItem.name.indexOf(a) !== -1  ){
            MyItem = curItem;
            
        }
       
        }
    return MyItem;
    
}
 
But of course i don't want to have an alert 10 times while the script is running. 
 
mmueller2Author
Participating Frequently
July 27, 2021

Yes it seems like there is a problem with the variables. At least wit the second time i use the Compitem variable. 

But i use this function to find folders and footage as well. That's why i used the variable.  

Otherwise i have to write the for loop 3 times 

 

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


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

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

I tried now to replace the funtion and the lines where i call the function with the for loops respectivly. 

So i coded four foor loops without variables and and it gives me the same error message, though.  

Justin Taylor-Hyper Brew
Community Expert
Community Expert
July 14, 2021

Just tested and it works for me after commenting out that line. Try putting it in a try catch and see if you can get any more info on the error.