Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

What is wrong with my script

Explorer ,
Sep 29, 2023 Sep 29, 2023
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
TOPICS
Expressions , Scripting
292
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Sep 29, 2023 Sep 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(effect
...
Translate
Enthusiast ,
Sep 29, 2023 Sep 29, 2023
LATEST

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.");
        }
    }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines