Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Why isn’t this script creating four nulls?

  • Why isn’t this script creating four nulls?

    Posted by Nick Hill on January 29, 2024 at 5:40 pm

    I’m trying to create a script, using the Create paths from nulls example as a starting point. The function called when the button is clicked is below – it should create four nulls, but only creates one. I tried removing the loop and putting in four separate code blocks to manually create the nulls one after another, but that didn’t work either:

    <pre class=””>function createNull(targetComp){
    return targetComp.layers.addNull();
    }

    function CurveMaker(){
    var undoGroup = localize("$$$/AE/Script/createCurveMaker/curveMaker=Make Curves");
    app.beginUndoGroup(undoGroup);
    nl = [];
    var comp = getActiveComp();
    // TODO: if there isn't an active comp, make one
    for (var i = 0; i <= 3; i++) {
    nl[i] = createNull(comp);
    nl[i].name = ("Control-0" + (i+1));
    nl[i].label = 11; // orange
    var np = nl[i].position;
    np.setValue([100 + (i%2)*100, 100 + (Math.floor(i/2)*100)]);
    var e1 = addSlider(nl[i], "CurveDepth", 1);
    var e2 = addSlider(nl[i], "Roundedness", 0.5);
    var e3 = addSlider(nl[i], "Influence", 1);
    var e4 = addCheckbox(nl[i], "Disable", false);
    }
    app.endUndoGroup();
    }

    I get one orange null with the sliders attached to it, but it’s like the loop then stops. Is there a reason why createNull() can’t be called more than once, or something like that?

    Brie Clayton replied 1 month ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    January 29, 2024 at 8:24 pm

    It works for me if I comment out the addSlider() calls since that function isn’t included. If I don’t comment those out, it errors out, and it only creates one null.

  • Nick Hill

    January 29, 2024 at 8:45 pm

    Ah, sorry Dan! I didn’t include all the code; addSlider() and addCheckbox() are defined elsewhere –

    <br>function addSlider(targetLayer, sliderName, defaultValue) {<br>var slz = targetLayer.property("Effects").addProperty("ADBE Slider Control");<br>slz.name = sliderName;<br>slz("Slider").setValue(defaultValue);<br>return slz.propertyIndex;<br>}</p><p> function addCheckbox(targetLayer, chkName, defaultValue) {<br>var chz = targetLayer.property("ADBE Effect Parade").addProperty("ADBE Checkbox Control");<br>chz.name = chkName;<br>chz.setValue(defaultValue);<br>return chz;<br>}</p><p></p><p>

    These work the first time round, and if I comment them both out I get four nulls… so what’s happening with these functions that they’ll only run through once?

  • Dan Ebberts

    January 29, 2024 at 9:39 pm

    Ah, OK. I think in your addCheckbox() function you need to change this:

    chz.setValue(defaultValue);

    to this:

    chz("ADBE Checkbox Control-0001").setValue(defaultValue);
  • Nick Hill

    January 29, 2024 at 9:47 pm

    You sir are a genius – this is the correct answer. Thank you so much!

  • Brie Clayton

    January 29, 2024 at 10:13 pm

    Thank you for this solve, Dan!

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