Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Need Script help – How to remove string from condition

  • Need Script help – How to remove string from condition

    Posted by Crystal Goh on August 28, 2020 at 8:42 am

    For simplicity 1st, heres the issue I have but with 2 lines:

    I have something like this:
    var a = app.project.activeItem."numLayer"
    alert(a);

    theres the string quotation marks causing the error, how do I remove it so that it can work?
    ——————–
    the full script I have atm is this
    its a script that gets the full path of the selected Property and tries to insert an expression into it
    will need it as this will go into a bigger script where if you have several selected layers, you can apply the expressions to all of them with this selected property without digging through the layers.

    var comp = app.project.activeItem;
    var selProp = comp.selectedProperties;
    var selLay = comp.selectedLayers;
    var curProp = selProp[1];
    var ary = [];
    if(comp.selectedProperties == null || comp.selectedProperties!== PropertyType.INDEXED_GROUP){
    alert("Select an Effect Property");
    }else{
    while (curProp.parentProperty !== null){
    ary.push(".property(\""+curProp.name+"\")");
    curProp = curProp.parentProperty;
    }
    }
    var lay = comp.layer("\""+selLay[0].name+"\"")+ary.reverse().join("");
    lay.expression = "test"; //PROBLEMATIC
    }

    when executed, var lay can’t give the expression because of the quotation marks, theres why I have issue

    so far
    function looseJsonParse(obj){
    return Function('"use strict";return (' + obj + ')')();

    isn’t helping and idk if i should use eval()?

    Crystal Goh replied 6 years ago 2 Members · 2 Replies
  • 2 Replies
  • Filip Vandueren

    August 29, 2020 at 5:38 pm

    You don’t need the quotes as far as I can tell.

    I think you’re better off just making an array of actual properties instead of an array of the
    names of properties.
    Similarly with the layers: just make a copy of selectedLayers() instead of getting their names, and then referencing to them by name (which is possibly not unique anyway)

    But I might be missing something in what exactly you’re trying to achieve with the script.

  • Crystal Goh

    August 30, 2020 at 3:51 am

    Thats a good fix actually, but yea thats not the intent of the script sadly.

    Managed to fix it yesterday though
    I think the problematic area was at
    layer("\""+selLay[0].name+"\""
    : Instead of getting the selectedLayer’s name, I get their index instead, which takes away the “\””quotation marks, which makes lay a valid object when I use the looseJsonParse(obj) function
    looseJsonParse(obj)lay.toString())

    thanks for the reply!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy