Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions UI Buttons to run scripts

  • UI Buttons to run scripts

    Posted by Dagur Maunason on October 3, 2021 at 6:33 pm

    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);

    }

    }

    Dagur Maunason replied 4 years, 7 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dagur Maunason

    October 3, 2021 at 6:35 pm

    And the script file, couldn’t add in edit for some reason…

  • Dan Ebberts

    October 3, 2021 at 6:41 pm

    <div>Try changing this section:</div>

    win.ui.button01.onClick = function(){

    print("button 01 pressed"); //debug

    layersInToCompMarkers();

    }

    win.ui.button02.onClick = function(){

    print("button 02 pressed"); //debug

    layerMarkersToComp();

    }

    to this:

    win.ui.button01.onClick = layersInToCompMarkers;

    win.ui.button02.onClick = layerMarkersToComp;

  • Dagur Maunason

    October 3, 2021 at 7:05 pm

    Thank you Dan for super fast help as always!

    Unfortunately this didn’t solve the issue, it’s behaves just like before. When clicked the button remain blue as if it’s stuck in a clicked state, could that be an indicator of what’s going on perhaps?

  • Dagur Maunason

    October 3, 2021 at 7:18 pm

    I’m now getting an error message for the code below on row 77, could that be the issue?

    var theComp = app.project.activeItem;
  • Dan Ebberts

    October 3, 2021 at 8:33 pm

    When I took your your code, removed the print() statements, and made the changes I suggested, it worked for me (copied the markers). I’m not sure why it doesn’t work for you.

  • Dagur Maunason

    October 3, 2021 at 9:31 pm

    Aha, that must’ve been it, I left the print statements in the functions in.. Had no clue they could mess with functionality, I assumed since they worked in the Toolkit debug that they would be ok, but lesson learned, without them everything works perfectly. Thank you so so much Dan, you’re a true lifesaver! Do you have a donation Paypal or such? Would love to buy you a beer/coffee or two 🙂

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy