-
UI Buttons to run scripts
Hi all!
I’m trying to hack together a simple Extendscript(hope it’s ok to post here still) panel with buttons to be able to more quickly run scripts. I have two scripts that I found around forums, both from Mr Dan Ebberts if I remember correctly. The first creates markers from selected layers inpoints to the comp and the second copies a layers markers to the comp. They work perfectly when ran as separate scripts, but when I try to run them through the very basic panel with buttons nothing happens, even though my print calls run as expected when tested in Extendscript Toolkit. I’m guessing it has something to do with the functions not having the right focus so to speak, but unfortunately my scripting skills are very limited and I would badly need this for a current project, so any help would be greatly appreciated!
Ideally I would love to add a button for deleting all comp markers, one for deleting all markers on selected layers aswell as one for running ‘Update markers from source’, but these I can survive without. 🙂
Thanks in advance!
function myPanel (thisObj)
{
var win = {};
win.pal = thisObj instanceof Panel ? thisObj : new Window('palette', '', undefined, {resizeable: true});
if (win.pal === null) return win.pal;
var res = "Group {orientation: 'column', alignment: ['fill', 'fill'], preferredSize: [128, 30], \
button01: Button {text: 'Layers InPoint -> Comp Markers', alignment: ['fill', 'center']}\
button02: Button {text: 'Layer Markers -> Comp Markers', alignment: ['fill', 'center']}\
}";
win.ui = win.pal.add(res);
win.ui.button01.minimumSize = [128, 24];
win.ui.button02.minimumSize = [128, 24];
win.pal.layout.layout(true);
win.pal.onResizing = win.pal.onResize = function (){
this.layout.resize();
};
if (win.pal !== null && win.pal instanceof Window){
win.pal.show();
}
win.ui.button01.onClick = function(){
print("button 01 pressed"); //debug
layersInToCompMarkers();
}
win.ui.button02.onClick = function(){
print("button 02 pressed"); //debug
layerMarkersToComp();
}
return win;
}
myPanel(this);
function layerMarkersToComp(){
print("layerMarkersToComp");
var theComp = app.project.activeItem;
if ((theComp == null) || ! (theComp instanceof CompItem)){
alert ("No comp active.");
return;
}
if (theComp.selectedLayers.length == 0){
alert("No layer selected.");
return;
}
var theLayers = theComp.selectedLayers;
var theLayer;
var theMarker = new MarkerValue("");
var theTime;
for (var i = 0; i < theLayers.length;i++){
theLayer = theLayers[i];
for (var j = 1; j <= theLayer.property("Marker").numKeys; j++){
theTime = theLayer.property("Marker").keyTime(j);
theMarker = theLayer.property("Marker").keyValue(j);
theComp.markerProperty.setValueAtTime(theTime,theMarker);
}
}
}
function layersInToCompMarkers(){
print("layersInToCompMarkers");
var theComp = app.project.activeItem;
var theLayers = theComp.selectedLayers;
var theMarker = new MarkerValue("");
for (var i = 0; i < theLayers.length; i++){
theMarker.comment = theLayers[i].name;
theComp.markerProperty.setValueAtTime(theLayers[i].inPoint,theMarker);
}
}