Copy link to clipboard
Copied
Hey there, first time posting here.
Tried my best to find the solution for this on this forum and everywhere else but no success.
So, I'm trying to apply some effects to a layer and then duplicate it via a button in my script. The applying part works if not followed by the duplicate() part and vice-versa, but when I try to assemble the steps, it crashes AE.
Here's the code:
function example() {
app.beginUndoGroup('Example');
var thisComp = app.project.activeItem;
applyFx(thisComp.selectedLayers[0]);
thisComp.selectedLayers[0].duplicate();
app.endUndoGroup();
function applyFx(target) {
var fx = target.property("ADBE Effect Parade");
var timeDiff = fx.addProperty("ADBE Difference");
timeDiff.property(2).expression = "thisLayer.source.frameDuration";
timeDiff.property(4).setValue(1);
var colorControl = fx.addProperty("ADBE Color Control");
colorControl.property(1).expression = "t = thisLayer;\nt.sampleImage([0,0],[t.width,t.height],true);";
}
}
The only thing I can think of is the script tries to duplicate the layer while the effects are still being added.
Thanks for the help!
Alright, so if someone's having the same issue, just found the solution by the one and only Dan Ebberts over on creativecow.
Apparently, you can't add sampleImage expression to a layer by script and leave it there, but you can add it, harness the value and remove it later.
Cheers!
Copy link to clipboard
Copied
I tend to agree with your assessment. You may need to implement an extra check/ break and structure your script more.
Mylenium
Copy link to clipboard
Copied
Thanks for the answer!
Any suggestions on what would be best practice for this situation? I'm not really a programmer, just an enthusiast. Tried using async functions but I guess it's not compatible.
Thanks!
Copy link to clipboard
Copied
Alright, so if someone's having the same issue, just found the solution by the one and only Dan Ebberts over on creativecow.
Apparently, you can't add sampleImage expression to a layer by script and leave it there, but you can add it, harness the value and remove it later.
Cheers!