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

Script making help

New Here ,
Apr 21, 2023 Apr 21, 2023

Copy link to clipboard

Copied

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();
TOPICS
Scripting

Views

204

Translate

Translate

Report

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
Community Expert ,
Jul 05, 2023 Jul 05, 2023

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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