Skip to main content
Known Participant
September 29, 2023
Answered

What is wrong with my script

  • September 29, 2023
  • 1 reply
  • 273 views
if (app.project.activeItem instanceof CompItem) {
  var comp = app.project.activeItem;
  var selectedLayer = comp.selectedLayers[0];

  if (selectedLayer) {
    // Check if the layer has effects
    if (selectedLayer.property("ADBE Effect Parade").numProperties > 0) {
      var effectGroup = selectedLayer.property("ADBE Effect Parade");
      var lastEffect = effectGroup.property(effectGroup.numProperties);

      // Check if the last effect has checkboxes
      if (lastEffect.numProperties > 0) {
        var checkbox1 = lastEffect.property("Uniform"); // Change to the actual name
        var checkbox2 = lastEffect.property("Individual"); // Change to the actual name

        // Add expressions to the checkboxes
        if (checkbox1 !== null) {
          checkbox1.expression = 'value;';
        }

        if (checkbox2 !== null) {
          checkbox2.expression = 'value;';
        }
      }
    }
  }
}
 
 
 
 
It gives me the error "cannot set expression or expressionEnabled on this property"
I am trying to add expression to the checkboxes of the last effect on the selected layer, you can manually add expressions to the checkbox but when I try to add it using script it doesnt work
This topic has been closed for replies.
Correct answer Alex White

I've added an additional check if the expression can be set for the chosen property.

 

if (app.project.activeItem instanceof CompItem) {
    var comp = app.project.activeItem;
    var selectedLayer = comp.selectedLayers[0];

    if (selectedLayer) {
        // Check if the layer has effects
        if (selectedLayer.property("ADBE Effect Parade").numProperties > 0) {
            var effectGroup = selectedLayer.property("ADBE Effect Parade");
            var lastEffect = effectGroup.property(effectGroup.numProperties);

            // Check if the last effect has checkboxes
            if (lastEffect.numProperties > 0) {
                var checkbox1 = lastEffect.property("Uniform"); // Change to the actual name
                var checkbox2 = lastEffect.property("Individual"); // Change to the actual name

                // check if expected effect is present and expression can be set

                if (checkbox1 !== null || (!checkbox1.canSetExpression)) {
                    alert("Cannot set expression for the property: " +
                    selectedLayer.name + "." + lastEffect.name + ".Uniform");
                } else {
                    checkbox1.expression = 'value;';
                }

                if (checkbox2 !== null || (!checkbox2.canSetExpression)) {
                    alert("Cannot set expression for the property: " +
                    selectedLayer.name + "." + lastEffect.name + ".Individual");
                } else {
                    checkbox2.expression = 'value;';
                }
            }
        } else {
            alert("No effects found on the selected layer.");
        }
    }
}

1 reply

Alex White
Alex WhiteCorrect answer
Legend
September 29, 2023

I've added an additional check if the expression can be set for the chosen property.

 

if (app.project.activeItem instanceof CompItem) {
    var comp = app.project.activeItem;
    var selectedLayer = comp.selectedLayers[0];

    if (selectedLayer) {
        // Check if the layer has effects
        if (selectedLayer.property("ADBE Effect Parade").numProperties > 0) {
            var effectGroup = selectedLayer.property("ADBE Effect Parade");
            var lastEffect = effectGroup.property(effectGroup.numProperties);

            // Check if the last effect has checkboxes
            if (lastEffect.numProperties > 0) {
                var checkbox1 = lastEffect.property("Uniform"); // Change to the actual name
                var checkbox2 = lastEffect.property("Individual"); // Change to the actual name

                // check if expected effect is present and expression can be set

                if (checkbox1 !== null || (!checkbox1.canSetExpression)) {
                    alert("Cannot set expression for the property: " +
                    selectedLayer.name + "." + lastEffect.name + ".Uniform");
                } else {
                    checkbox1.expression = 'value;';
                }

                if (checkbox2 !== null || (!checkbox2.canSetExpression)) {
                    alert("Cannot set expression for the property: " +
                    selectedLayer.name + "." + lastEffect.name + ".Individual");
                } else {
                    checkbox2.expression = 'value;';
                }
            }
        } else {
            alert("No effects found on the selected layer.");
        }
    }
}