Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Need expression to control Width and Height of Bezier Path

  • Need expression to control Width and Height of Bezier Path

    Posted by :lonnie Busch on June 23, 2018 at 5:39 pm

    I am trying to control Width and Height of Bezier Path. I am creating a template to re-use and want to be able to control the size/scale of whatever Path I paste into the Path field. I would like to be able to scale the width and height separately.

    Pasting alternate Paths works great, but I am not even sure if it is possible to control the width and height of the Bezier path. I can size/scale the original path by “clicking” on the path in the viewport, and scale it that way without getting any distortion of the Stroke, but that is the only way I can scale without getting distortion.

    It seems there would be a way of sizing/scaling the source Path so that it doesn’t distort the Stroke I am applying to the destination Shape Layer.

    I am new to expressions and still struggling with the javascript language. I posted the image below to show there are no other controls for width and height for the Path.

    One forum post suggested using “scale” and then turning continuous raster on and off to get rid of stroke distortion, except that my raster buttons are grayed out. They are On, though.

    Thanks for any help with this!

    Justin Lundy replied 1 month, 2 weeks ago 4 Members · 7 Replies
  • 7 Replies
  • Walter Soyka

    June 25, 2018 at 11:00 am

    Check out this sample project:
    12475_scalepath.aep.zip

    You need Ae CC 2018 v15.0 or higher to have expression access to paths. This project is set up to work on masks on solids, but it could be adapted to shape layers.

    Here are the setup instructions if you want to build it from scratch:

    1. Create a solid named PATH_SOURCE, and add a mask to it named Mask 1.

    2. Create a solid named PATH_SCALE, and add as mask to it. Also, add two Slider Control effects to PATH_SCALE, and rename them xScale and yScale in the Effects Control Panel or on the Timeline. Alt+click the Mask Path property stopwatch on the PATH_SCALE layer’s mask and paste the following code:

    originalPath = thisComp.layer("PATH_SOURCE").mask("Mask 1").maskPath;
    var newPoints= [];
    var newInTangents = [];
    var newOutTangents = [];
    var totalX = 0;
    var totalY = 0;
    xScale = thisComp.layer("PATH_SCALE").effect("xScale")("Slider")/100;
    yScale = thisComp.layer("PATH_SCALE").effect("yScale")("Slider")/100;

    for (i = 0; i < originalPath.points(time).length; i++) {
    totalX += originalPath.points(time)[i][0];
    totalY += originalPath.points(time)[i][1];
    }
    var centroid = [totalX, totalY] / originalPath.points(time).length;

    for (var i = 0; i < originalPath.points(time).length; i++) {
    var point = originalPath.points(time)[i];
    var delta = point - centroid;
    var scaledPoint = [delta[0] * xScale, delta[1] * yScale];
    var scaledCentroid = [centroid[0] * xScale, centroid[1] * yScale];
    newPoints.push(scaledPoint + centroid);
    }

    for (var i = 0; i < originalPath.inTangents(time).length; i++) {
    var point = originalPath.inTangents(time)[i];
    var scaledInTangent = [point[0] * xScale, point[1] * yScale];
    newInTangents.push(scaledInTangent);
    }

    for (var i = 0; i < originalPath.outTangents(time).length; i++) {
    var point = originalPath.outTangents(time)[i];
    var scaledOutTangent = [point[0] * xScale, point[1] * yScale];
    newOutTangents.push(scaledOutTangent);
    }

    createPath(newPoints, newInTangents, newOutTangents, thisComp.layer("PATH_SOURCE").mask("Mask 1").maskPath.isClosed());

    I’d be happy to try to answer any questions you might have about what exactly the code is doing.

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

  • :Lonnie Busch Create COW Profile Image

    :lonnie Busch

    June 25, 2018 at 1:31 pm

    Walter, thank you for the quick reply. I apologize for not including in my post that I am using AE 5.5. I am hoping for some solution that will work with my version.

    Thanks again!

  • Walter Soyka

    June 25, 2018 at 2:08 pm

    There’s BAO Mask Avenger, but the compatibility matrix says it only goes back to CS6:
    https://aescripts.com/bao-mask-avenger/

    Maybe you can outline what it is exactly that you’re trying to accomplish? We might be able to suggest some other way you haven’t considered yet.

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

  • :Lonnie Busch Create COW Profile Image

    :lonnie Busch

    June 25, 2018 at 2:38 pm

    I am creating a template that I can re-use. It involves 2 layers, one is just for the path, called layer P, the other is for all the animation controls, called A.

    I have it set up that I can replace the path in P, which is referenced by layer A which has about 50 controls—sliders, angles, checkboxes— to animate properties of stroke and fill within layer A. And I have several instances of the same “path” in layer A and separate controls for each path, as well as global controls for all paths, all set up with expressions. That’s why I set up layer P so I would only have to replace the path in one place. And I want to be able to change the path to whatever I need. And everything is working perfectly.

    But scaling the path has become problematic with sliders. It seems I can only Scale the “shape” itself, not the path. If I set up a controller on layer A Transform>Scale [using the Transform>Scale in layer P does nothing], that works fine, until I want to scale X and Y separately, which I do. But then I get distortion of the stroke because I am scaling the “shape” not the path itself. But, if I double click the path itself in layer P (path layer) I get a “bounding box” that I can then scale X and Y individually without distortion of the stroke.

    I guess what I am saying is that I am trying to access that “bounding box” but I am very new to expressions and can’t even begin to figure that out or if it is even possible, or where to “place” the expression.

    I thought about using a CRGreen script and using to attach the points of my main Path to a null to then use the null as my Path Scaler, but it seems you can only attach one point, and I would need to run the script each time I changed paths.

    I am not sure that a complicated solution makes sense here as I can double click the path and scale it as I need to. Or I can animate the scale over all by using Transform>Scale in layer A. The only problem would arise if I wanted to animate scale on say X but not Y. That would be impossible without some kind of control.

    I am just trying to streamline my rig so it works somewhat flawlessly, and that I can use it 6 months from now and not have to wonder how it works!

    I hope this makes sense, Walter, and I appreciate your input.

  • Steve Bentley

    June 25, 2018 at 6:12 pm

    Hi Guys, We still have a copy of AE 5.5 hanging around for specialized things and it uses Mask Avenger just fine.

  • :Lonnie Busch Create COW Profile Image

    :lonnie Busch

    June 25, 2018 at 6:18 pm

    Hi Steve, thanks for the post! I’ll check it out!

  • Justin Lundy

    August 30, 2024 at 2:42 pm

    I followed your code and got the following expression error:

    Any suggestions on how to fix this?

    Thanks!

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