ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Function works on dialog but not on a palette

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Rodrigo Aben
Function works on dialog but not on a palette
on May 17, 2020 at 9:40:12 pm

With 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 &lt;= 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++;
}

}


Return to posts index

Tomas Bumbulevičius
Re: Function works on dialog but not on a palette
on May 18, 2020 at 7:47:30 am

Since 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 VH


Return to posts index

Andrei Popa
Re: Function works on dialog but not on a palette
on May 18, 2020 at 8:16:17 am

Off 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.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]