-
[Scripting] What Am I Doing Wrong?
Hey there,
I want to add try and catch functions to several expressions. You know it’s painful to add them manually, so I decided to do that via scripting.
var selComp = app.project.activeItem;
var numSelLay = selComp.selectedLayers.length;
var addExprBeg = "try { \r \r ";
var addExprEnd = ";\r \r} catch(err) { \r \r value; \r \r}";for (i = 1; i <= numSelLay; i++) {
var numSelProp = selComp.selectedLayers[i].selectedProperties.length;
for (x = 1; x <= numSelProp; x++) {
var Express = selComp.selectedLayers[i].selectedProperties[x].expression;
selComp.selectedLayers[i].selectedProperties[x].expression = addExprBeg + Express + addExprEnd;
}
}
I selected the layers and their properties that I wanted to add the try and catch functions to, and ran this code. It added the try and catch functions to the properties of the selected layer #2 only and didn’t touch the rest of the selected layers. What did I do wrong?
If you have another way to do what I’m looking for, feel free to post it. I’m open-minded about new ways of doing things.
Thanks!