Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Simple script modification (I think?)

  • Simple script modification (I think?)

    Posted by Chaz Chester on January 31, 2020 at 8:36 am

    Hi, I’ve been using After Effects for about 8 years now, and I’ve recently been experimenting with modifying free, unprotected scripts to improve my workflow. I’m still fairly new to ExtendScript, so I could really use a hand.
    This is a script by Arttu Rautio that changes the labels on layers in an active comp based on their type. It would really, really help me out if it did this for all of the comps in the project instead of just the active one. I think I need a loop of some kind, so that it automatically goes through all of the comps, but I don’t know how to make that happen. Would anyone here be able to help with this?

    function ColoriseByType() {
    app.beginUndoGroup(“Colorize By Type”); // Begin undo group
    var comp = app.project.activeItem; // Get active composition
    var layers = comp.selectedLayers; // Get selected layers
    var colors = {‘none’: 0, ‘red’: 1, ‘yellow’: 2, ‘aqua’: 3, ‘pink’: 4, ‘lavender’: 5, ‘peach’: 6, ‘seafoam’: 7, ‘blue’: 8,
    ‘green’: 9, ‘purple’: 10, ‘orange’: 11, ‘brown’: 12, ‘fuchsia’: 13, ‘cyan’: 14, ‘sandstone’: 15, ‘darkgreen’: 16}; // Label colors
    var adjustmentlayer = colors[‘seafoam’];
    var avlayer = colors[‘green’];
    var audiolayer = colors[‘green’];
    var cameralayer = colors[‘purple’];
    var complayer = colors[‘cyan’];
    var guidelayer = colors[‘sandstone’];
    var lightlayer = colors[‘yellow’];
    var nulllayer = colors[‘none’];
    var shapelayer = colors[‘blue’];
    var solidlayer = colors[‘red’];
    var textlayer = colors[‘orange’];
    if (layers != 0) { // If there is layer selection
    for (var i = 0; i < layers.length; i++) { // Loop through layers
    if (layers[i] instanceof AVLayer) { layers[i].label = avlayer; // If avlayer
    if (!layers[i].hasVideo) { layers[i].label = audiolayer; } // If audio layer
    if (layers[i].source.mainSource instanceof SolidSource) { layers[i].label = solidlayer; } // If solid layer
    if (layers[i].nullLayer == true) { layers[i].label = nulllayer; } // If null layer
    if (layers[i].adjustmentLayer == true) { layers[i].label = adjustmentlayer; } // If adjustment layer
    if (layers[i].source instanceof CompItem) { layers[i].label = complayer; } // If composition layer
    }
    if (layers[i] instanceof ShapeLayer) { layers[i].label = shapelayer; } // If shape layer
    if (layers[i] instanceof TextLayer) { layers[i].label = textlayer; } // If text layer
    if (layers[i] instanceof CameraLayer) { layers[i].label = cameralayer; } // If camera layer
    if (layers[i] instanceof LightLayer) { layers[i].label = lightlayer; } // If light layer
    if (layers[i].guideLayer) { layers[i].label = guidelayer; } // If guide layer
    }
    } else { // If there is no layer selection
    for (var i = 1; i <= comp.layers.length; i++) { // Iterate through layers
    if (comp.layer(i) instanceof AVLayer) { comp.layer(i).label = avlayer; // If AVLayer
    if (!comp.layer(i).hasVideo) { comp.layer(i).label = audiolayer; } // If audio layer
    if (comp.layer(i).source.mainSource instanceof SolidSource) { comp.layer(i).label = solidlayer; } // If solid layer
    if (comp.layer(i).nullLayer == true) { comp.layer(i).label = nulllayer; } // If null layer
    if (comp.layer(i).adjustmentLayer == true) { comp.layer(i).label = adjustmentlayer; } // If adjustment layer
    if (comp.layer(i).source instanceof CompItem) { comp.layer(i).label = complayer; } // If composition layer
    }
    if (comp.layer(i) instanceof ShapeLayer) { comp.layer(i).label = shapelayer; } // If shape layer
    if (comp.layer(i) instanceof TextLayer) { comp.layer(i).label = textlayer; } // If text layer
    if (comp.layer(i) instanceof CameraLayer) { comp.layer(i).label = cameralayer; } // If camera layer
    if (comp.layer(i) instanceof LightLayer) { comp.layer(i).label = lightlayer; } // If light layer
    if (comp.layer(i).guideLayer) { comp.layer(i).label = guidelayer; } // If guide layer
    }
    }
    app.endUndoGroup(); // End undo group
    }
    ColoriseByType(); // Run the function

    Tomas Bumbulevičius replied 6 years, 3 months ago 2 Members · 8 Replies
  • 8 Replies
  • Tomas Bumbulevičius

    January 31, 2020 at 9:43 am

    Hey Chaz, there are few ways to make it to work, but the most simplest for you would be:

    1. Instead of var comp = app.project.activeItem; you need to loop through project items (outside of ColoriseByType function)
    for (var i = 1; i <= app.project.numItems; i++)

    2. Then, add conditioning:
    var curItem = app.project.item(i);
    if(curItem.typeName == "Composition"){

    }

    3. If above condition true, run your function with the following line:
    ColoriseByType(curItem)

    Since you are learning, I am purposefully not making it as a direct actionable code 😉

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.
    Boxer – Dynamic Text Boxes Template with a Live Preview

  • Chaz Chester

    January 31, 2020 at 12:59 pm

    Hi, Thomas. Thank you for helping me with this. I’m getting an error that says “comp is undefined”. I’ve tried a few different ways and I’m not sure what I’m doing wrong. Could you show me how to add these lines to the script, please?

  • Tomas Bumbulevičius

    January 31, 2020 at 5:25 pm

    Here are few things you need to make, assuming all from previous post is done as described:

    1. Change function ColoriseByType() to function ColoriseByType(comp)
    2. Delete var comp = app.project.activeItem; // Get active composition

    You need to cover the basics on how functions works and how variables are passed/retrieved by different objects, within global/local scopes.

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.
    Boxer – Dynamic Text Boxes Template with a Live Preview

  • Chaz Chester

    January 31, 2020 at 11:40 pm

    Sorry, Tomas, I’m still a little lost. This is what I currently have. Could you show me where I’m messing up, please?

    for (var i = 1; i <= app.project.numItems; i++)
    var curItem = app.project.item(i);
    if(curItem.typeName == “Composition”){
    }
    function ColoriseByType(comp){
    app.beginUndoGroup(“Colorize By Type”); // Begin undo group
    var layers = comp.selectedLayers; // Get selected layers
    var colors = {‘none’: 0, ‘red’: 1, ‘yellow’: 2, ‘offwhite’: 3, ‘pink’: 4, ‘lavender’: 5, ‘peach’: 6, ‘audition’: 7, ‘blue’: 8,
    ‘green’: 9, ‘purple’: 10, ‘orange’: 11, ‘brown’: 12, ‘fuchsia’: 13, ‘cyan’: 14, ‘sandstone’: 15, ‘darkgreen’: 16}; // Label colors
    var adjustmentlayer = colors[‘fuchsia’];
    var avlayer = colors[‘cyan’];
    var audiolayer = colors[‘audition’];
    var cameralayer = colors[‘purple’];
    var complayer = colors[‘sandstone’];
    var guidelayer = colors[‘darkgreen’];
    var lightlayer = colors[‘yellow’];
    var nulllayer = colors[‘green’];
    var shapelayer = colors[‘orange’];
    var solidlayer = colors[‘blue’];
    var textlayer = colors[‘red’];
    if (layers != 0) { // If there is layer selection
    for (var i = 0; i < layers.length; i++) { // Loop through layers
    if (layers[i] instanceof AVLayer) { layers[i].label = avlayer; // If avlayer
    if (!layers[i].hasVideo) { layers[i].label = audiolayer; } // If audio layer
    if (layers[i].source.mainSource instanceof SolidSource) { layers[i].label = solidlayer; } // If solid layer
    if (layers[i].nullLayer == true) { layers[i].label = nulllayer; } // If null layer
    if (layers[i].adjustmentLayer == true) { layers[i].label = adjustmentlayer; } // If adjustment layer
    if (layers[i].source instanceof CompItem) { layers[i].label = complayer; } // If composition layer
    }
    if (layers[i] instanceof ShapeLayer) { layers[i].label = shapelayer; } // If shape layer
    if (layers[i] instanceof TextLayer) { layers[i].label = textlayer; } // If text layer
    if (layers[i] instanceof CameraLayer) { layers[i].label = cameralayer; } // If camera layer
    if (layers[i] instanceof LightLayer) { layers[i].label = lightlayer; } // If light layer
    if (layers[i].guideLayer) { layers[i].label = guidelayer; } // If guide layer
    }
    } else { // If there is no layer selection
    for (var i = 1; i <= comp.layers.length; i++) { // Iterate through layers
    if (comp.layer(i) instanceof AVLayer) { comp.layer(i).label = avlayer; // If AVLayer
    if (!comp.layer(i).hasVideo) { comp.layer(i).label = audiolayer; } // If audio layer
    if (comp.layer(i).source.mainSource instanceof SolidSource) { comp.layer(i).label = solidlayer; } // If solid layer
    if (comp.layer(i).nullLayer == true) { comp.layer(i).label = nulllayer; } // If null layer
    if (comp.layer(i).adjustmentLayer == true) { comp.layer(i).label = adjustmentlayer; } // If adjustment layer
    if (comp.layer(i).source instanceof CompItem) { comp.layer(i).label = complayer; } // If composition layer
    }
    if (comp.layer(i) instanceof ShapeLayer) { comp.layer(i).label = shapelayer; } // If shape layer
    if (comp.layer(i) instanceof TextLayer) { comp.layer(i).label = textlayer; } // If text layer
    if (comp.layer(i) instanceof CameraLayer) { comp.layer(i).label = cameralayer; } // If camera layer
    if (comp.layer(i) instanceof LightLayer) { comp.layer(i).label = lightlayer; } // If light layer
    if (comp.layer(i).guideLayer) { comp.layer(i).label = guidelayer; } // If guide layer
    }
    }
    app.endUndoGroup(); // End undo group
    }
    ColoriseByType(); // Run the function

  • Chaz Chester

    February 2, 2020 at 2:18 am

    Can anyone help me with this? I’m sorry if I’m being a pain, I just can’t seem to get this script to do what I need on my own.

  • Tomas Bumbulevičius

    February 2, 2020 at 9:20 am

    Chaz, here it is, tested, works as expected. With pure honesty – it doesn’t seem you know what programming logic is about, strongly suggest going through fundamentals before trying to modify any code. It will be simpler, and a lot more beneficial learning curve. Good luck !

    for (var i = 1; i <= app.project.numItems; i++){
    var curItem = app.project.item(i);
    if (curItem.typeName == "Composition") {
    ColoriseByType(curItem); // Run the function
    }
    }

    function ColoriseByType(comp) {
    app.beginUndoGroup("Colorize By Type"); // Begin undo group
    var layers = comp.selectedLayers; // Get selected layers
    var colors = {
    'none': 0, 'red': 1, 'yellow': 2, 'offwhite': 3, 'pink': 4, 'lavender': 5, 'peach': 6, 'audition': 7, 'blue': 8,
    'green': 9, 'purple': 10, 'orange': 11, 'brown': 12, 'fuchsia': 13, 'cyan': 14, 'sandstone': 15, 'darkgreen': 16
    }; // Label colors
    var adjustmentlayer = colors['fuchsia'];
    var avlayer = colors['cyan'];
    var audiolayer = colors['audition'];
    var cameralayer = colors['purple'];
    var complayer = colors['sandstone'];
    var guidelayer = colors['darkgreen'];
    var lightlayer = colors['yellow'];
    var nulllayer = colors['green'];
    var shapelayer = colors['orange'];
    var solidlayer = colors['blue'];
    var textlayer = colors['red'];
    if (layers != 0) { // If there is layer selection
    for (var i = 0; i < layers.length; i++) { // Loop through layers
    if (layers[i] instanceof AVLayer) {
    layers[i].label = avlayer; // If avlayer
    if (!layers[i].hasVideo) { layers[i].label = audiolayer; } // If audio layer
    if (layers[i].source.mainSource instanceof SolidSource) { layers[i].label = solidlayer; } // If solid layer
    if (layers[i].nullLayer == true) { layers[i].label = nulllayer; } // If null layer
    if (layers[i].adjustmentLayer == true) { layers[i].label = adjustmentlayer; } // If adjustment layer
    if (layers[i].source instanceof CompItem) { layers[i].label = complayer; } // If composition layer
    }
    if (layers[i] instanceof ShapeLayer) { layers[i].label = shapelayer; } // If shape layer
    if (layers[i] instanceof TextLayer) { layers[i].label = textlayer; } // If text layer
    if (layers[i] instanceof CameraLayer) { layers[i].label = cameralayer; } // If camera layer
    if (layers[i] instanceof LightLayer) { layers[i].label = lightlayer; } // If light layer
    if (layers[i].guideLayer) { layers[i].label = guidelayer; } // If guide layer
    }
    } else { // If there is no layer selection
    for (var i = 1; i <= comp.layers.length; i++) { // Iterate through layers
    if (comp.layer(i) instanceof AVLayer) {
    comp.layer(i).label = avlayer; // If AVLayer
    if (!comp.layer(i).hasVideo) { comp.layer(i).label = audiolayer; } // If audio layer
    if (comp.layer(i).source.mainSource instanceof SolidSource) { comp.layer(i).label = solidlayer; } // If solid layer
    if (comp.layer(i).nullLayer == true) { comp.layer(i).label = nulllayer; } // If null layer
    if (comp.layer(i).adjustmentLayer == true) { comp.layer(i).label = adjustmentlayer; } // If adjustment layer
    if (comp.layer(i).source instanceof CompItem) { comp.layer(i).label = complayer; } // If composition layer
    }
    if (comp.layer(i) instanceof ShapeLayer) { comp.layer(i).label = shapelayer; } // If shape layer
    if (comp.layer(i) instanceof TextLayer) { comp.layer(i).label = textlayer; } // If text layer
    if (comp.layer(i) instanceof CameraLayer) { comp.layer(i).label = cameralayer; } // If camera layer
    if (comp.layer(i) instanceof LightLayer) { comp.layer(i).label = lightlayer; } // If light layer
    if (comp.layer(i).guideLayer) { comp.layer(i).label = guidelayer; } // If guide layer
    }
    }
    app.endUndoGroup(); // End undo group
    }

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.
    Boxer – Dynamic Text Boxes Template with a Live Preview

  • Chaz Chester

    February 2, 2020 at 1:44 pm

    Thank you, Tomas! I really appreciate it. I’ve been having success with some of the modifications I’ve been doing, but you’re right, I’m not up to speed on programming logic. Is there a good resource you would recommend for learning ExtendScript/Java?

  • Tomas Bumbulevičius

    February 3, 2020 at 8:53 pm

    Chaz, you are welcome! While myself I landed into Extendscript with previous programming experience & knowledge, the courses from David Torno were amazing to begin with:

    https://www.provideocoalition.com/after-effects-extendscript-training-complete-series/

    He covers the basics of JS too, which could be pretty much enough to get your feet wet. And from there – the sky is the limit. Good luck !

    Find out more:
    After Effects Tutorials: motion design, expressions, scripting.
    Boxer – Dynamic Text Boxes Template with a Live Preview

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