Skip to main content
Known Participant
August 3, 2022
Question

Apply corner radius using setEntirePath()

  • August 3, 2022
  • 4 replies
  • 848 views

How to apply corner radius to shape using setEntirePath()

This topic has been closed for replies.

4 replies

femkeblanco
Legend
August 4, 2022

Here's a roundedRectangle() function with the same syntax as rectangle(), but with an added corner radius argument.

 

// e.g. of function call
roundedRectangle(
    -25 /*top*/, 25 /*left*/, 50 /*w*/, 50 /*h*/, 10 /*cornerRadius*/);

/*
 * roundedRectangle by Femke Blanco
 * Beta 04/08/2022
 */
function roundedRectangle(top, left, w, h, r) {
    var paths = app.activeDocument.pathItems;
    var path1 = paths.add();
    var p;
    var c = r * ((4 / 3) * Math.tan(Math.PI / 8));  // handle length
    // p2
    point(left + r, top, left + r, top, left + r - c, top);
    // p3
    point(left + w - r, top, left + w - r + c, top, left + w - r, top);
    // p4
    point(left + w , top - r, left + w , top - r, left + w , top - r + c);
    // p5
    point(left + w, top - h + r, left + w, top - h + r - c, 
        left + w, top - h + r);
    // p6
    point(left + w - r, top - h, left + w - r, top - h, 
        left + w - r + c, top - h);
    // p7
    point(left + r, top - h, left + r - c, top - h, left + r, top - h);
    // p8
    point(left, top - h + r, left, top - h + r, left, top - h + r - c);
    // p1
    point(left, top - r, left, top - r + c, left, top - r);
    path1.closed = true;
    function point(x, y, Rx, Ry, Lx, Ly) {
        p = path1.pathPoints.add();
        p.anchor = [x, y];
        p.rightDirection = [Rx, Ry];
        p.leftDirection = [Lx, Ly];
    }
}

 

CarlosCanto
Community Expert
Community Expert
August 4, 2022
Known Participant
August 4, 2022

Okay thanks.

But "PointType.SMOOTH" not working for me.

CarlosCanto
Community Expert
Community Expert
August 4, 2022

PointType is ReadOnly, it's used to find out what kind of point we're dealing with, not to change from corner to smooth or viceversa.

CarlosCanto
Community Expert
Community Expert
August 4, 2022

setEntirePath() takes care of the Anchor points, after that you'll have to set the Handles of each Anchor. It's quite a bit of Math, but it can technically be done

femkeblanco
Legend
August 3, 2022

Not possible.  You can't make smooth points with setEntirePath().

Known Participant
August 4, 2022

Okay.

Is there any other method to do that in script?