Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions general AFX scripting advice

  • general AFX scripting advice

    Posted by Frank Mansfield on June 14, 2014 at 11:52 pm

    Hi all

    I’ve stalked through theses forums for a long time, but never actually posted anything before. I’ve decided to try and learn a bit of scripting in after effects and as a test project I’ve tried to make a simple dockable panel to speed up adding loop expressions.

    After a bit of faffing around I seem to have got it working (go me) but I was just wondering if any of you scripting badasses could have a quick scan over my code and give me any pointers or ways I could or should improve it? I’ve attached the script to this post in case anybody does get a second to look it over.

    A couple of specific questions that I have got are:

    1) is there any way of finding the parent layer of a specified property? Perhaps the correct way of going about this is to drill down from selected layers to selected properties in the first place, but if there is a way of reverse-discovering a property’s parent layer then this would seem to be a quicker way of going about it.
    2) If I don’t add the ” mPanel.layout.layout(true); ” line then the dockable panel appears empty. To be honest, I just copied this section wholesale from a different script and I’m not really sure what this is doing. Could someone explain it to me in idiot-friendly language please?

    Thanks loads in advance – and even if you don’t get a chance to look it over (it *is* quite long) then thank you for all your time and effort on these forums. I’m sure I speak for a legion of lurkers when I say that there’s a few individuals in particular who’ve been incredibly helpful time and time again, and you are owed a huge debt of gratitude. So thanks!

    -frank

    {
    function fmLoopPanel(thisObj){

    //panel UI maker function
    function fmLoopPanelMakeUI(thisObj){
    var fmPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette","FM Loop Panel", undefined, {resizeable:true});

    //define resource string for panel buttons
    fmResString = "group{orientation:'column',\
    groupOne: Group{orientation:'row',\
    fmStaticText: StaticText{text:'FM Loop v0.0.01'},\
    },\
    groupTwo: Group{orientation:'column',\
    fmLoopInOutDDL: DropDownList{properties:{items:['Loop Out', 'Loop In', 'Loop In + Out']}},\
    groupTwoA: Group{orientation:'column',\
    fmLoopRB: RadioButton{text:'cycle', alignment:['left', 'top']},\
    fmContinueRB: RadioButton{text:'continue', alignment:['left', 'top']},\
    },\
    },\
    groupThree: Group{orientation:'column',\
    fmLoopButton: Button{text:'OK', name:'OK'},\
    },\
    }";

    //assign resource string to panel
    fmPanel.grp = fmPanel.add(fmResString);

    //set default selections
    fmPanel.grp.groupTwo.fmLoopInOutDDL.selection = 0;
    fmPanel.grp.groupTwo.groupTwoA.fmLoopRB.value = true;

    //on click set variables from selected optins and call fmLoopButtonPressed function
    fmPanel.grp.groupThree.fmLoopButton.onClick = function(){
    var fmRadioButtons = fmPanel.grp.groupTwo.groupTwoA;
    var fmInOutType = fmPanel.grp.groupTwo.fmLoopInOutDDL.selection.text;
    for (var i = 0; i< fmRadioButtons.children.length ; i++){
    if (fmRadioButtons.children[i].value == true) {
    var fmLoopType = fmRadioButtons.children[i].text;
    }
    }
    fmLoopButtonPressed(fmInOutType, fmLoopType);
    };

    //panel resizing
    fmPanel.layout.layout(true);
    fmPanel.grp.minimumSize = fmPanel.grp.size;
    fmPanel.layout.resize();
    fmPanel.onResizing = fmPanel.onResize = function () {this.layout.resize();}

    //return Panel
    return fmPanel;
    }
    //call the panel UI maker function
    var fmWindow = fmLoopPanelMakeUI(thisObj);

    //if window rather than panel
    if((fmWindow != null) && (fmWindow instanceof Window)) {
    fmWindow.center();
    fmWindow.show();
    }
    }

    //start LoopPanel function referencing panel or window
    fmLoopPanel(this);

    //main create loop function
    function fmLoopButtonPressed(fmInOutType, fmLoopType){

    app.beginUndoGroup("FM Loop"); //start undo group

    var fmThisComp = app.project.activeItem; //set active project

    if (fmThisComp == null) {
    alert ("Select the properties you want to loop. "); //check if there is an active comp
    }
    else {
    var fmSelectedProperties = fmThisComp.selectedProperties; //set selected properties array
    if (fmSelectedProperties.length == 0) {
    alert ("Select the properties you want to loop."); //check if there are properties selected
    }
    else {
    var fmKeyFrameCount = 0;
    for (i=0 ; i 0 && key(1).time > time){" + "\n" +
    " loopIn('" + fmLoopType + "')" + "\n" +
    " }else if (numKeys > 0 && time > key(numKeys).time){ " + "\n" +
    " loopOut('" + fmLoopType + "') " + "\n" +
    " }else{ " + "\n" +
    " value " + "\n" +
    " } "
    }

    var fmPropertiesWithoutKeyframes = []; //set array for properties with no keyframes
    for (i=0 ; i 0) {
    var fmPropertiesWithoutKeyframesList = ""; //set up list of properties without keyframes
    for (i=0 ; i<fmPropertiesWithoutKeyframes.length ; i++) { //for every property without a keyframe
    fmPropertiesWithoutKeyframesList += "\n" + fmPropertiesWithoutKeyframes[i].name; //add name of property
    }
    alert ("The following properties had no keyframes:" + fmPropertiesWithoutKeyframesList);
    }

    }

    app.endUndoGroup(); //end undo group

    }

    }

    Frank Mansfield replied 12 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    June 15, 2014 at 6:37 pm

    I can help you with your first question. I think this will give you the parent layer of any property:

    var myLayer = myProperty.propertyGroup(myProperty.propertyDepth);

    Dan

  • Frank Mansfield

    June 16, 2014 at 9:02 am

    That’s brilliant – thanks, Dan.

    It took me a while to work out how it was doing what it was doing, mind you… I specifically asked for ‘idiot-proof’ explanations! 😉

    Cheers again
    -f

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