Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Paint effect stroke shape to Shape layer shape via script

  • Paint effect stroke shape to Shape layer shape via script

    Posted by Juanluis Vich on April 19, 2018 at 12:15 am

    Hi!
    IWhen working with paint stroke effect, I usually like to paste the path info to a shape layer’s path (as easy as go to the paint stroke path, then copy, and go to the shape layer path and paste.
    BUT I’m trying to automate that a bit via scripting, so when the script is executed, it automatically copies that info of the stroke path value and paste into the shape layer’s path value.
    I was reading a bit here at the redefinery site but Im totally stuck, because I don’t know how to use the stored data in the paintStroke array he mentions about, and paste into the shapePathData of a new created shape

    (this is the code from the Redefinery article, just in case you can’t click at the link)

    // given:
    // layer = Layer object, and the layer can have effects applied
    //
    var selectedPaintBrushes = new Array(); // Store brush strokes in an array
    var effects = layer.property("Effects"); // Look for layers that can have effects
    if (effects !== null)
    {
    var effect, paintStrokes, paintStroke;
    // Iterate over all effects on the layer
    for (var i = 1; i <= effects.numProperties; i++)
    {
    effect = effects.property(i);
    if (effect.matchName === "ADBE Paint") // Look for Paint effects
    {
    // Get PropertyGroup containing the strokes
    paintStrokes = effect.property("ADBE Paint Group");
    // Iterate over the brush strokes
    for (var j = 1; j <= paintStrokes.numProperties; j++)
    {
    // Store only selected strokes in the array
    paintStroke = paintStrokes.property(j);
    if (paintStroke.selected)
    selectedPaintBrushes[selectedPaintBrushes.length] = paintStroke;
    }
    }
    }
    }
    // The selectedPaintBrushes array now contains the list of selected paint brush strokes
    // in top-to-bottom order

    do you have any ideas?

    thanks!

    Juanluis Vich replied 8 years ago 2 Members · 2 Replies
  • 2 Replies
  • Santi Agustí

    April 25, 2018 at 5:10 am

    mmm
    this post recalls me to an old quick adaptation I made of the exquisite Redefinery Script that converted masks to shapes, to make it work with paint brushes and shape layers. As I was in an animation project rush and I needed a quick tool for converting brushes paths to shape layers, I only could scratch the surface of the script, and I ended up copy-pasting the paths by hand.
    The thing is, having this adapted script as a basis, maybe you can do the copypaste via scripting, copying from the brush path property array to the newly shape paths generated.
    Im totally lost on that, so I can help more than that, I don’t know how to go from the original paths, store their values, and paste on the duplicated paths in the shape layer ☹

    Making that work would be a really handy tool I think! Any advice?

    here is the quick script you can start from. Now it goes thru all the brushes of a solid, and makes a duplicated of them on a newly created shape layer, buuuuuuut they are empty (is handy to recreate the hierarchy btw)


    // quick and awufully adapted code from the original rd_MasksToShapes from the great https://www.redefinery.com/ae/rd_scripts/

    app.beginUndoGroup("duplicate paintGroups to shape layer groups");
    var activeComp = app.project.activeItem;
    var myLayers = activeComp.selectedLayers[0];

    // Get PropertyGroup containing the strokes
    var paintGroup = myLayers.property("ADBE Effect Parade").property("ADBE Paint").property("ADBE Paint Group");

    // Create an empty shape layer
    var suffix = " the Shape";
    var shapeLayer = activeComp.layers.addShape();
    shapeLayer.name = myLayers.name.substr(0,31-suffix.length) + suffix;
    shapeLayer.moveBefore(myLayers);

    var shapeLayerContents = shapeLayer.property("ADBE Root Vectors Group");
    var shapeGroup = shapeLayerContents; //.addProperty("ADBE Vector Group");

    // Iterate over the paints layer's paints, converting their paths to shape paths

    for (var m=1; m<=paintGroup.numProperties; m++)
    // for (var m=1; m<=paintGroup.numProperties; m++)

    {
    // Get paint info
    paint = paintGroup.property(m);
    paintShape = paintGroup.property("ADBE Paint Shape");

    // Create new shape path using paint info
    shapePathGroup = shapeGroup.addProperty("ADBE Vector Shape - Group");
    shapePathGroup.name = paint.name;
    shapePath = shapePathGroup.property("ADBE Vector Shape");

    app.endUndoGroup();
    }

    Sorry I can’t help more, but as your question was something similar to what I did, maybe is useful as a start until some real scripting expert can drive you onto a better direction ????

  • Juanluis Vich

    April 27, 2018 at 1:04 pm

    thanks!
    I have no idea about how to achieve the copypaste thing via scripting, but as a hierarchy replicator as you said, it works 😀

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