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:
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();
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!
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.
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?
Copy link to clipboard
Copied
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.
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.