Forums › Adobe After Effects Expressions › Function works on dialog but not on a palette
Function works on dialog but not on a palette
Rodrigo Aben
May 17, 2020 at 9:40 pmWith the help of Andrei I’ve arrived at the code below that works great, but stops working when assigned to a button on a ScriptUi palette. It simply bypasses the ifs in the while loop. I have to change from new Window(“palette”) to new Window(“dialog”) for the function to work.
Since I’m trying to create a dockable script it would be great to have it working on a palette.
Am I missing something?
function Detect(){
var comp = app.project.activeItem;
var videoLayer = comp.selectedLayers[0];
var time = comp.time;
var frame = Math.round(time / comp.frameDuration);
var opacityLevel = videoLayer.property("Transform").property("Opacity");
var threshold = 48.0;above = false;
while (frame <= 100) {
t = frame * comp.frameDuration;
if (above) {
if (opacityLevel.valueAtTime(t, true) != threshold) {
frame++;
above = false;
}
} else if (opacityLevel.valueAtTime(t, true) == threshold) {
above = true;
var myMarker = new MarkerValue("Mark");
videoLayer.property("Marker").setValueAtTime(t, myMarker);
}
frame++;
}}
Tomas Bumbulevičius
May 18, 2020 at 7:47 amSince you hit the button in a script panel, does this still remain true?
var comp = app.project.activeItem;
Overall, a layer must always be selected in the comp, thus you surely need to define try/catch in case selection is not made.
Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VHAndrei Popa
May 18, 2020 at 8:16 amOff topic: Please don’t start your function name with capital letters.
On topic:
Idk if the problem is the one specified by Thomas. But if so, why don’t pass the composition as a parameter in your function?
Something like
function detect(comp) {
var videoLayer = comp.selectedLayers[0];
var time = comp.time;
var frame = Math.round(time / comp.frameDuration);
var opacityLevel = videoLayer.property("Transform").property("Opacity");
var threshold = 48.0;above = false;
while (frame <= 100) {
t = frame * comp.frameDuration;
if (above) {
if (opacityLevel.valueAtTime(t, true) != threshold) {
frame++;
above = false;
}
} else if (opacityLevel.valueAtTime(t, true) == threshold) {
above = true;
var myMarker = new MarkerValue("Mark");
videoLayer.property("Marker").setValueAtTime(t, myMarker);
}
frame++;
}
}
//and call it like this on the onClick event of the button
detect(app.project.activeItem);
I need to see the entire code and test it in order to see the problem, because it’s not that obvious.
If you can share your code or file, I could be more explicit.Andrei
My Envato portfolio.Rodrigo Aben
July 15, 2020 at 5:15 amTurns out, Thomas was right. Sorry for the delay guys but your help has been amazing. These are the projects I’ve been able to create with it http://www.abenathar.com
Log in to reply.