Skip to main content
Participant
April 21, 2023
Question

Script making help

  • April 21, 2023
  • 1 reply
  • 382 views

Hey there I'm trying to create a script which can look up for specific properties in any active comp and apply an expression of control to each, depending in some variables, like their color, I have a null created with the expressions control effects , I've created the script but when I run it I don't get any error, nothing happens, am I doing something wrong? 

 

function applyExpressionsToSelectedLayers() {
// Get the currently active composition
var comp = app.project.activeItem;

// Check if a composition is active
if (comp !== null && comp instanceof CompItem) {
// Get the selected layers
var selectedLayers = comp.selectedLayers;

// Loop through all selected layers
for (var i = 0; i < selectedLayers.length; i++) {
var layer = selectedLayers[i];

// Check if the layer is a shape layer
if (layer instanceof ShapeLayer) {
// Loop through all groups in the shape layer
for (var j = 1; j <= layer.property("ADBE Root Vectors Group").numProperties; j++) {
var group = layer.property("ADBE Root Vectors Group").property(j);

// Check if the group has a stroke
if (group.property("ADBE Vector Graphic - Stroke").enabled) {
// Get the stroke color
var strokeColor = group.property("ADBE Vector Graphic - Stroke").property("ADBE Vector Stroke Color").value;

// Set stroke color expression
var highlightExpression = 'thisComp.layer("Main Stroke width - Color Ctrl").effect("Highlight")("Color")';
var baseColorExpression = 'thisComp.layer("Main Stroke width - Color Ctrl").effect("Base Color")("Color")';
group.property("ADBE Vector Graphic - Stroke").property("ADBE Vector Stroke Color").expression = 'if (Math.round(thisComp.layer("Main Stroke width - Color Ctrl").effect("Color Control")("Color")[0]) == ' + Math.round(strokeColor[0]) + ' && Math.round(thisComp.layer("Main Stroke width - Color Ctrl").effect("Color Control")("Color")[1]) == ' + Math.round(strokeColor[1]) + ' && Math.round(thisComp.layer("Main Stroke width - Color Ctrl").effect("Color Control")("Color")[2]) == ' + Math.round(strokeColor[2]) + ') {\n ' + highlightExpression + ';\n} else {\n ' + baseColorExpression + ';\n}';

// Set stroke width expression based on stroke color
var strokeWidthExpression = 'if (Math.round(thisComp.layer("Main Stroke width - Color Ctrl").effect("Color Control")("Color")[0]) == ' + Math.round(strokeColor[0]) + ' && Math.round(thisComp.layer("Main Stroke width - Color Ctrl").effect("Color Control")("Color")[1]) == ' + Math.round(strokeColor[1]) + ' && Math.round(thisComp.layer("Main Stroke width - Color Ctrl").effect("Color Control")("Color")[2]) == ' + Math.round(strokeColor[2]) + ') {\n thisComp.layer("Main Stroke width - Color Ctrl").effect("Highlight Width")("Slider");\n} else {\n thisComp.layer("Main Stroke width - Color Ctrl").effect("Base Width")("Slider");\n}';
group.property("ADBE Vector Graphic - Stroke").property("ADBE Vector Stroke Width").expression = strokeWidthExpression;
}
}
}
}
} else {
alert("Please select a composition first.");
}
}

// Create UI panel
var scriptPanel = new Window("palette", "Apply Expressions to Selected Layers", undefined);
var applyButton = scriptPanel.add("button", undefined, "Apply Expressions");
applyButton.onClick = applyExpressionsToSelectedLayers;
scriptPanel.show();
This topic has been closed for replies.

1 reply

Justin Taylor-Hyper Brew
Community Expert
Community Expert
July 5, 2023

You'll want to break your entire panel into smaller pieces and test to see what's going wrong. If you are having an issue with a specific problem, try opening a new thread for that issue.