-
layer.applyPreset does not work when executed by a ScriptUI button
Hey all! I’m facing a really weird issue and can’t fix it on my own.
I wrote (copied snippets from here and there) a ScriptUI Panel for AE that creates a rectangle shape layer of the size of the comp, adds it fill, and applies an external .ffx (Animation Preset) to it. And that works fine (lines 36 to 74 on their own).
But when I try to make it run from the press of a button (lines 1 to 33), the script runs fine until line 53, then stops.
That line is an .applyPreset and I have no clue why it works fine on its own, but not when it’s activated by the button. The referenced .ffx is in its correct place (same folder as the ScriptUI Panel).Would appreciate it immensely if someone could help me out with this! Code for the .jsx under.
function createDockableUI(thisObj) {
var dialog =
thisObj instanceof Panel
? thisObj
: new Window("dialog", undefined, undefined, { resizeable: true });
dialog.onResizing = dialog.onResize = function() {
this.layout.resize();
};
return dialog;
}
function showWindow(myWindow) {
if (myWindow instanceof Window) {
myWindow.center();
myWindow.show();
}
if (myWindow instanceof Panel) {
myWindow.layout.layout(true);
myWindow.layout.resize();
}
}
var win = createDockableUI(this);
var PixelDisruptor = createDockableUI(this);
var ApplyPXD = PixelDisruptor.add("button", undefined, undefined, {name: "ApplyPXD"});
ApplyPXD.text = "Disrupt your pixels";
ApplyPXD.onClick = function () {
PXD()
}
showWindow(win);
function PXD() {
var currentComp = app.project.activeItem;
app.beginUndoGroup("Pixel Disruptor layers creation");
//Create Map layer
var mapLayer = currentComp.layers.addShape();
var mapGroup = mapLayer.property("Contents").addProperty("ADBE Vector Group");
mapLayer.name = "PXD MAP";
mapLayer.label = 0;
// Map shape
mapGroup.property("Contents").addProperty("ADBE Vector Shape - Rect");
mapGroup.property("Contents").property("Rectangle Path 1").property("Size").expression = "var width = thisComp.width;\rvar height = thisComp.height;\r[width, height]";
// Map color
mapGroup.property("Contents").addProperty("ADBE Vector Graphic - Fill");
// Apply the effects from the .ffx file to the map layer
mapLayer.applyPreset(File("./PXDMAP.ffx"));
app.endUndoGroup();
}