Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scripting for Bounding box around text or AI file

  • Scripting for Bounding box around text or AI file

    Posted by Stanley Castello on April 14, 2022 at 8:09 pm

    Before I starting breaking my head around this issue. Is it possible to code this type of scenario:

    Select any text layer or AI text file. Then add a bounding box (shape layer or one line stroke) on top of it ? I was able to create a shape layer on on the middle on canvas so far. My knowledge is limited as for now. Is it possible? If not possible, is okay 🙂

    function addShapeOnTop (){

    var project = app.project;

    var comp = project.activeItem;

    if(comp === null){

    alert(‘Please select a text layer or AI file to continue’);

    return

    };

    app.beginUndoGroup(Layer on top”)

    var shapeLayer = comp.layers.addShape();

    shapeLayer.name = “Shape on top”;

    var rectangleGroup = shapeLayer.property(“Contents”).addProperty(“ADBE Vector Group”);

    rectangleGroup.name = “Rectangle”;

    var pathGroup = shapeLayer.property(“Contents”).property(“Rectangle”).property(“Contents”).addProperty(“ADBE Vector Shape – Rect”);

    var pathStroke = shapeLayer.property(“Contents”).property(“Rectangle”).property(“Contents”).addProperty(“ADBE Vector Graphic – Stroke”);

    var pathFill = shapeLayer.property(“Contents”).property(“Rectangle”).property(“Contents”).addProperty(“ADBE Vector Graphic – Fill”);

    };

    app.endUndoGroup();

    I would love to be able to TIP for the huge help on this site, specially Dan, but I couldn’t find a way here. It’s only fair for you to take the time and help. It’s incredibly appreciate it.

    Stanley Castello replied 4 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 14, 2022 at 10:49 pm

    I’m not what all you’re looking for, but whatever you want to do is probably do-able. This just expands on what you have a little to maybe give you some ideas. I think I’d position the rectangle with an expression, so I’ve included how to do that. Anyway, I hope it’s helpful.

    function addShapeOnTop(){

    var comp = app.project.activeItem;

    if (comp == null || ! (comp instanceof CompItem)){

    alert("No comp active.");

    return;

    }

    if (comp.selectedLayers.length == 0){

    alert("No layer selected.");

    return;

    }

    var margin = 10;

    var textLayer = comp.selectedLayers[0];

    var shapeLayer = comp.layers.addShape();

    shapeLayer.name = "Shape on top";

    var shapeLayerContents = shapeLayer.property("ADBE Root Vectors Group");

    var rectangleGroup = shapeLayerContents.addProperty("ADBE Vector Group");

    rectangleGroup.name = "Rectangle 1";

    var rectangleContents = rectangleGroup.property("ADBE Vectors Group");

    var pathGroup = rectangleContents.addProperty("ADBE Vector Shape - Rect");

    var sourceRect = textLayer.sourceRectAtTime(0,false);

    pathGroup.property("ADBE Vector Rect Size").setValue([sourceRect.width + margin*2,sourceRect.height + margin*2]);

    var pathStroke = rectangleContents.addProperty("ADBE Vector Graphic - Stroke");

    var pathFill = rectangleContents.addProperty("ADBE Vector Graphic - Fill");

    var expr = 'L = thisComp.layer("' + textLayer.name + '");\r' +

    'r = L.sourceRectAtTime(time,false);\r' +

    'L.toComp([r.left+r.width/2,r.top+r.height/2])';

    shapeLayer.property("Position").expression = expr;

    shapeLayer.moveAfter(textLayer);

    }

    addShapeOnTop();

  • Stanley Castello

    April 15, 2022 at 12:11 am

    It’s possible, wow! thank you again. My idea is to reveal text by animating the shape layer from left to right. When the shape is in full, the text is hiding, the revealed by the shape and then the shape is gone leaving only the text or item.

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