Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects My modification of Compify Script ( as requested )

  • My modification of Compify Script ( as requested )

    Posted by Joseph M. morgan on April 21, 2005 at 8:12 pm

    Some time back, I asked about a macroing language. I learned (here) by a very pleasant surprise that they use ECMAScript (JavaScript). Anyway, I’m a programmer turned advanced hobbyist movie maker kind of guy, and promised to post my script when I finished. I was in the middle of something, so it took me a while to get around to it, but here it is.

    This is a modification of Compify, found on the AE Enhancers web site. I needed just about the same thing, so I started with Compify and modified it in several ways. This script does the following things:

    1) Takes all selected footage items and adds them to a comp
    2) Allows you to select a destination folder for the comps (it must exist first)
    3) Puts the selected footage items (all if none are selected) into a layer
    4) Allows you to choose the size of the comp (740 x 480 default)
    5) Adjusts the size of the footage item to the comp size as closely as possible, preserving the existing w/h aspect ratio.
    6) Adds the “Auto Color” effect to the layer.

    I needed this because I compose a considerable number of photographs into movies. I like to clean up the pics a little and create some slight motion on each one for effect. Normally the pics are in the 3200 x 2100 range, so the resizing is needed.

    The modifications to Compify are significant, and if you have any questions, please ask.

    Here it is:

    /* =====================================================================
    * Compify2
    * Byron Nash, Edited and Improved by Paul Tuersley
    * October 2004
    *
    * Comp Scaling, Folder destination, Auto Color effect
    * added by Joseph M. Morgan – April 2005
    *
    * Select footage items to be comped or select none to comp all
    * enter a suffix at prompt to be appended to the end of the comp name
    ===================================================================== */
    { // opening brace

    function createWindow(title, x, y, width, height) {
    var window = new Window(‘dialog’, title, [x, y, x + width, y + height]);

    return window;
    }

    function createPanel(container, x, y, width, height, label) {
    var panel = createControl(container, ‘panel’, x, y, width, height, label);

    return panel;
    }

    function createControl(container, type, x, y, width, height, value) {
    var control = container.add(type, [x, y, x + width, y + height], value);

    return control;
    }

    function createDialog() { //function to create the dialog
    var destinationFolderName;

    function onTimeCodeClick() { //enables timecode fields
    rb_TimeCode.value = true;
    rb_Frames.value = false;
    et_Frames.enabled = false;
    et_TimeCodeHours.enabled = true;
    et_TimeCodeMinutes.enabled = true;
    et_TimeCodeSeconds.enabled = true;
    et_TimeCodeFrames.enabled = true;

    et_Rate.enabled = false;
    et_TimeCodeSeconds.active = true;
    }

    function onFrameClick() { //enables frames field
    rb_TimeCode.value = false;
    rb_Frames.value = true;
    et_Frames.enabled = true;
    et_TimeCodeHours.enabled = false;
    et_TimeCodeMinutes.enabled = false;
    et_TimeCodeSeconds.enabled = false;
    et_TimeCodeFrames.enabled = false;

    et_TimeCodeSeconds.active = false;
    et_Frames.enabled = true;
    }

    // ==================================================================
    // added a custom click function so the edittxt box gets highlighted.
    // ==================================================================
    function onCustomClick() {
    et_TimeCodeSeconds.active = false;
    et_Rate.enabled = true;
    }

    // ================================================================
    // Added this code to disable the et_Rate field if
    // any of the frame rate radio buttons are selected except the
    // custom one.
    // ================================================================
    function onRateRBClick() {
    et_Rate.enabled = false;
    }

    // ====================
    // Create dialog window
    // ====================
    var dlg = createWindow(‘Automatic Composition Creation’, 100, 100, 385, 240);

    // =============================================================================
    // Composition Settings Panel – Wraps the Frame Rate, Duration, and Scale Panels
    // =============================================================================
    var compositionSettingsPanel = createPanel(dlg, 5, 5, 375, 155, ‘Composition Settings’);

    // ================
    // Frame Rate Panel
    // ================
    var frameRatePanel = createPanel(compositionSettingsPanel, 5, 15, 150, 135, ‘Frame Rate’);

    // =============================================================
    // add radio buttons for the different frame rates
    // increment the button placement in between creation of buttons
    // =============================================================
    var rb_NTSC = createControl(frameRatePanel, ‘radiobutton’, 5, 15, 90, 15, ‘29.97 [NTSC]’);
    rb_NTSC.value = true;

    var rb_PAL = createControl(frameRatePanel, ‘radiobutton’, 5, 35, 90, 15,’25 [PAL]’);
    var rb_Film = createControl(frameRatePanel, ‘radiobutton’, 5, 55, 50, 15, ’24’);
    var rb_Custom = createControl(frameRatePanel, ‘radiobutton’, 5, 75, 60, 15, ‘Custom’);
    var et_Rate = createControl(frameRatePanel, ‘edittext’, 70, 75, 60, 15, ’30’);
    et_Rate.enabled = false;

    // =======================
    // Duration Settings Panel
    // =======================
    var durationPanel = createPanel(compositionSettingsPanel, 160, 15, 210, 65, ‘Duration’);

    // =========================
    // frames radio and text box
    // =========================
    var rb_Frames = createControl(durationPanel, ‘radiobutton’, 5, 15, 90, 15, ‘Frames’);
    var et_Frames = createControl(durationPanel, ‘edittext’, 100, 15, 90, 15, ‘150’, ”);

    // ==================================================
    // timecode radio and fields for entering in timecode
    // ==================================================
    var rb_TimeCode = createControl(durationPanel, ‘radiobutton’, 5, 35, 90, 15, ‘Timecode’);
    var et_TimeCodeHours = createControl(durationPanel, ‘edittext’, 100, 35, 20, 15, ’00’);
    var et_TimeCodeMinutes = createControl(durationPanel, ‘edittext’, 122, 35, 20, 15, ’00’);
    var et_TimeCodeSeconds = createControl(durationPanel, ‘edittext’, 144, 35, 20, 15, ’06’);
    var et_TimeCodeFrames = createControl(durationPanel, ‘edittext’, 166, 35, 20, 15, ’00’);

    // =====================
    // initialize the values
    // =====================
    rb_TimeCode.value = true;
    rb_Frames.value = false;
    et_Frames.enabled = false;
    et_TimeCodeHours.enabled = true;
    et_TimeCodeMinutes.enabled = true;
    et_TimeCodeSeconds.enabled = true;
    et_TimeCodeFrames.enabled = true;

    // ============
    // Scale Panel
    // ============
    var scalePanel = createPanel(compositionSettingsPanel, 160, 85, 210, 65, ‘Scale’);
    var st_Width = createControl(scalePanel, ‘statictext’, 10, 15, 40, 15, ‘Width’);
    var et_Width = createControl(scalePanel, ‘edittext’, 100, 15, 40, 15, ‘720’);

    var st_Height = createControl(scalePanel, ‘statictext’, 10, 35, 40, 15, ‘Height’);
    var et_Height = createControl(scalePanel, ‘edittext’, 100, 35, 40, 15, ‘480’);

    // ========================================================================================
    // Folder Settings – Locate all the folders first, then build the dialog with radio buttons
    // for the user.
    // ========================================================================================
    var rootFolderItems = currentProject.rootFolder.numItems;
    var folders = new Array();
    var folderCount = 0;

    for (i = 1; i <= rootFolderItems; i++) { var item = currentProject.rootFolder.items[i]; if (item.typeName == "Folder") { folders[folderCount++] = item.name; } } var destFolderPanelHeight = (20 * folderCount) + 20; var folderPanel = createPanel(dlg, 5, 165, 375, destFolderPanelHeight, 'Destination Folder:'); for (i = 0, y = 15; i < folderCount; i++, y += 20) { var radioButton = createControl(folderPanel, 'radiobutton', 10, y, 365, 15, folders[i]); radioButton.onClick = function() { destinationFolderName = this.text; }; // ========================================================== // Enable the first RB and get its name in the event the user // doesn't change the name // ========================================================== if (i == 0) { radioButton.value = true; destinationFolderName = folders[i]; } } // ========================= // buttons for ok and cancel // ========================= buttonPanel = createPanel(dlg, 5, 165 + destFolderPanelHeight + 15, 375, 30, ''); var cb_OK = createControl(buttonPanel, 'button', 110, 5, 75, 20, 'OK'); var cb_Cancel = createControl(buttonPanel, 'button', 190, 5, 75, 20, 'Cancel'); // ========================================================================= // Reset the window size due to dynamic creation of destination folder panel // ========================================================================= dlg.bounds = [5, 5, 385, 220 + destFolderPanelHeight]; // ======================================================= // send clicks to functions for enabling/disabling buttons // ======================================================= rb_TimeCode.onClick = onTimeCodeClick; rb_Frames.onClick = onFrameClick; rb_Custom.onClick = onCustomClick; rb_NTSC.onClick = onRateRBClick; rb_PAL.onClick = onRateRBClick; rb_Film.onClick = onRateRBClick; // ======================================================== // Activate the dialog by showing it... respond to OK click // ======================================================== if (dlg.show() == 1) { var frameRate = 10; var duration = 1; var folder = ""; var scaleWidth; var scaleHeight; // ===================================== // Figure out what frame rate is checked // ===================================== if (rb_NTSC.value == true) { frameRate = 29.97; // NTSC } else if (rb_PAL.value == true) { frameRate = 25; // PAL } else if (rb_Film.value == true) { frameRate = 24; // Film } else if (rb_Custom.value == true) { frameRate = et_Rate.text; // get value from text box } // ================================ // set comp length for still images // ================================ if(rb_Frames.value == true){ duration = et_Frames.text / 30; // take the frames value } else { var h = Number(et_TimeCodeHours.text * 3600); // multiply hours var m = Number(et_TimeCodeMinutes.text * 60); // multiply minutes var s = Number(et_TimeCodeSeconds.text); // multiply seconds var f = Number(et_TimeCodeFrames.text/30); // divide frames duration = h + m + s + f; // add'em up } // =============================================== // Get the scale values.. force them to be numbers // =============================================== scaleWidth = et_Width.text * 1; scaleHeight = et_Height.text * 1; // ============================== // Process the destination folder // ============================== var rootFolderItems = currentProject.rootFolder.numItems; var itemCollection = null; for (i = 1; i <= rootFolderItems; i++) { var item = currentProject.rootFolder.items[i]; if (item.typeName == "Folder" && item.name == destinationFolderName) { itemCollection = item.items; } } if (itemCollection == null) { itemCollection = currentProject.rootFolder.items; } // ===================== // setup array to return // ===================== var returnData = [itemCollection, frameRate, duration, scaleWidth, scaleHeight]; return returnData; } } // ******************************************************************************** // MAIN CODE - ACTUAL EXECUTION BEGINS HERE // ******************************************************************************** clearOutput(); var currentProject = app.project; // Get project // ======================== // call the dialog function // ======================== var userInfo = createDialog(); // ======================================================================================== // NOTE!!!! // by testing if anything was returned by the createDialog function, you know whether // the user ok'ed or cancelled. This main body of the script will only execute if something // was returned (i.e if userInfo isn't null); // ======================================================================================== if (userInfo) { var suffix; var targetItems; // Will hold items to compify var destinationFolder = userInfo[0]; var frameRate = userInfo[1]; var duration = userInfo[2]; var scaleWidth = userInfo[3]; var scaleHeight = userInfo[4]; // ============================================== // create undo group if user didn't cancel dialog // ============================================== app.beginUndoGroup("Compify2"); var projectItems = currentProject.items; // list of items in project writeLn("Compify2: Byron Nash, Paul Tuersley, Joe Morgan"); var createdCompositions = new Array(); // array for storing all the comps made var selectedItems = app.project.selection; // set selected import items to an array if (selectedItems.length > 0) { // check to see if anything is selected
    targetItems = app.project.selection; // if so the use the selection
    }
    else { // if not, use entire project contents
    targetItems = new Array();
    for (j = 0; j < projectItems.length; j++) { // add project list to an array targetItems[j] = projectItems[j + 1]; } } for (i = 0; i <= targetItems.length; i++) { // loop through the project var currentItem = targetItems[i]; if (currentItem instanceof FootageItem) { // check for footage items var fileExtensionPosition = currentItem.name.lastIndexOf("."); // find file extension // ================== // Extract the suffix // ================== suffix = currentItem.name.substring(fileExtensionPosition + 1, currentItem.name.length); // ===================================================== // add suffux to comp name and remove the file extension // ===================================================== var curName = currentItem.name.substring(0, fileExtensionPosition) + suffix; // ======================================================= // Truncate comp name if it exceeds the 31 character limit // ======================================================= if (curName.length > 30) {
    curName = curName.slice(0,29-suffix.length) + suffix;
    }

    // ====================
    // setup comp variables
    // ====================
    var curWidth = currentItem.width;
    var curHeight = currentItem.height;
    var curAspect = currentItem.pixelAspect;
    var curduration = currentItem.duration;
    var curRate = currentItem.frameRate;

    // ==================================================
    // Calcualte the new width and height (scale to comp)
    // ==================================================
    if (curWidth > scaleWidth || curHeight > scaleHeight) {
    var widthRatio = scaleWidth / curWidth;
    var heightRatio = scaleHeight / curHeight;
    var newScale = Math.max(widthRatio, heightRatio) * 100; // preserve 1 to 1 aspect ratio
    }

    // =====================================
    // Handle the duration and rate settings
    // =====================================
    if (curduration == 0) {
    curduration = duration //set duration to dialog value if it is a still image
    }

    if (curRate < 1) { curRate = frameRate //set frame rate to dialog value if it is a still image } // ========================= // create comp and add layer // ========================= var newComposition = destinationFolder.addComp(curName, scaleWidth, scaleHeight, curAspect, curduration, curRate); var layerItems = newComposition.layers; //variable for collection of layer objects in Comp var newLayer = layerItems.add(currentItem); //add layer newLayer.scale.setValue([newScale, newScale]); // Scale it as close to the comp as we can newLayer("Effects").addProperty("Auto Color"); // Add the "Auto Color" effect createdCompositions[createdCompositions.length] = newComposition;//add comp to array } } writeLn("Created " + createdCompositions.length + " Comps"); app.endUndoGroup(); } } //closing

    Joe Morgan

    Mike Clasby replied 21 years, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Nicholas White

    April 21, 2005 at 8:30 pm

    Hey,

    If you haven’t already, you should post your stuff over on aenhancers.com as well, I’m sure it will get more mileage over there : )

    Take care,

    Nick

  • Mike Clasby

    April 21, 2005 at 10:07 pm

    Thanks for posting your solution, now I need to sit down and use a few scripts, to over the fear factor.

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