• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Applying Rounded Corners to specific Anchor Points

Explorer ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

Hey y'all,

 

I'm working on a script to round specific corners of my artwork based on their angle and type (inside or outside corners). For example, I want all inside corners to be rounded to 0.01", and outside corners to be rounded to 0.02". I've tried various methods, such as creating two vectors, rounding the corners separately, and then merging them, but this isn't ideal for all use cases.

Here is the code I've been using to identify which corners need the live effect applied, but I'm having trouble applying the effect to individual points:

Kernzy_3-1715895907661.png

 

function checkCorners() {
    var corners = [];
    var doc = app.activeDocument;
    var sel = doc.selection;
    if (sel.length > 0 && sel[0].typename === "PathItem") {
        var path = sel[0].pathPoints;

        for (var i = 0; i < path.length; i++) {
            var point = path[i];
            var nextPoint = path[(i + 1) % path.length];
            var prevPoint = path[(i - 1 + path.length) % path.length];
            var vec1 = {
                x: point.anchor[0] - prevPoint.anchor[0],
                y: point.anchor[1] - prevPoint.anchor[1]
            };
            var vec2 = {
                x: nextPoint.anchor[0] - point.anchor[0],
                y: nextPoint.anchor[1] - point.anchor[1]
            };
            var angle = Math.atan2(vec2.y, vec2.x) - Math.atan2(vec1.y, vec1.x);
            angle = angle * (180 / Math.PI);
            if (angle < 0) {
                angle += 360;
            }
            var cornerType = (angle > 180) ? "Inside Corner" : "Outside Corner";
            corners.push("Point " + i + ": " + cornerType + " (" + angle.toFixed(2) + " degrees)");
        }
    } else {
        alert("Please select a single path item.");
    }
    alert(corners.join("\n"));
}

checkCorners();

 

Kernzy_2-1715895892106.png

With the results above, I would like to run the following code to apply the effect to the specific corners:

function roundCorners(radius) {
    var doc = app.activeDocument
    var sel = doc.selection;
    xmlstring2 = '<LiveEffect name="Adobe Round Corners"><Dict data="R radius ' + (radius * 72) + '"/></LiveEffect>';
    for (var j = 0; j < sel.length; j++) {
        sel[j].applyEffect(xmlstring2);
    }
}

Despite my efforts, I haven't been able to apply the effect from point to point, which brings me here...
Any thoughts, ideas, or alternate methods y'all can think of that might point me in the right direction?

Thanks!

TOPICS
Scripting

Views

379

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
May 16, 2024 May 16, 2024

Copy link to clipboard

Copied

Live corner is a feature that recognizes the state of the path point and handle as a corner afterward and edits it to live.

 

If you add, move, and scale path points and handles correctly on your own, Illustrator will recognize them as live corners.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 17, 2024 May 17, 2024

Copy link to clipboard

Copied

Hey sttk3,

 

I've been trying to manage this via script because I need to apply this to hundred pieces at a time. I haven't been able to find any documentation on accessing the anchors/corners via script.

Are you aware of anything that could be used to edit 5 & 2 seperatly from the rest via script?

Kernzy_0-1715952685409.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2024 May 17, 2024

Copy link to clipboard

Copied

LATEST

There is no class for corners in Illustrator's Scripting API. Only a PathPoint and its anchor and handle coordinates. Instead of requiring Illustrator to control the corners, you edit the PathPoints on your own.

 

If you want fine control over corners, perhaps it might be a better choice to use Glyphs. There is a corner component feature.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2024 May 17, 2024

Copy link to clipboard

Copied

Alternatively, this can be solved with three Offset path effects. The look can be applied to a single path, to a group of paths or to an entire layer.

 

Appearance panel

New fill with:

Effect 1: Offset path 0.01" rounded 

Effect 2: Offset path -0.03" rounded

Effect 3: Offset path 0.02" rounded

 

Gives you the desired result.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines