-
[HELP] My Script UI code isn’t working but i don’t know why
Hello guys, i’m trying to create an script ui with a button that does this:
Add an expression to any selected properties, but if you are selecting a layer (or multiple layers) instead of properties then pre-compose that layers, i don’t know if this is possible, but the code should be working, and it doesn’t, it adds the expression to selected properties but the pre-compose option is not working can you guys help me?
This is the code:
var win = new Window("palette", "My Script UI", undefined); // Add a button for the expression
var myButton = win.add("button", undefined, "Button");
// Add an event listener for the button's click event
myButton.onClick = function() {
// Get the active composition
var comp = app.project.activeItem;
// Get the selected properties
var selProps = comp.selectedProperties;
// Loop through the selected properties
for (var i = 0; i < selProps.length; i++) {
// Get the current property
var prop = selProps[i];
// Check if the property is a shape path
if (prop.propertyValueType == PropertyValueType.SHAPE) {
// Add the custom expression to the shape path property
prop.expression = "my custom expression";
} else {
// Add the another custom expression to the property
prop.expression = "my other custom expression";
}
// Check if the active item is a layer
if (comp.activeItem instanceof AVLayer) {
// Get the active layer
var layer = comp.activeItem;
// Precompose the layer
var precomp = layer.precompose(layer.name, true);
}
}
}
// Show the window
win.show();