Copy link to clipboard
Copied
Hello to all the nice people!
For more than a week I'm stuck with the problem of how to apply arrowheads to my path object. I can apply color or swatch color, I can define width, overprint, dashes, but I can't figure out arrowheads (specifically I want to apply "Arrow 1" style from Illustrator native library). Asked ChatGPT hundred times with no results that would work, searched Google and Github. No luck. Below is a snippet in which I define a function to use it later with several path objects. Could someone please show a way to do this task or at least suggest a resource in which I could search for proper commands and arguments.
Thanks in advance!
// Define a path object Style3 (arrows)
var pathStyle3 = {
strokeColor: doc.swatches.getByName("Keyline").color,
strokeDashes: [],
strokeWidth: 0.1 * mm,
filled: false
};
// Function to apply the path style to a path item
function applyPathStyle3(pathItem, pathStyle3) {
pathItem.strokeColor = pathStyle3.strokeColor;
pathItem.strokeDashes = pathStyle3.strokeDashes;
pathItem.strokeWidth = pathStyle3.strokeWidth;
pathItem.strokeOverprint = true;
pathItem.filled = pathStyle3.filled;
}
Copy link to clipboard
Copied
I've never seen a way to access arrowheads via the scripting API. You do have two easy options though...
First, you could create a graphic style and then apply it to each path.
var gs = app.activeDocument.graphicStyles.getByName("Arrowheads");
gs.applyTo(somePathItem);
Or you could record an action that applies the arrowheads and then run the action within your script.
app.doScript("ActionName", "ActionSet");
Copy link to clipboard
Copied
ChatGPT might be the best Psychologist but it needs to train harder to solve all the illustrator intricacies we humans spot a mile away.
In theory, it could have been possible to apply Arrowheads via the API a few versions back when Arrowheads were applied via Effects. Now that they live in the Stroke panel, follow jduncan's advice
Copy link to clipboard
Copied
Thanks jduncan and CarlosCanto! As I understand it, Adobe has forgotten about the stroke property known as Arrowheads or thinks it is too irrelevant, which is sad. Of course, I could draw triangles at the end of every stroke, but that is not ideal. Alternatively, I could define a Graphic Style and then make a reference to that document, which means that my script is not usable without it. Another option is to create an action, which should also be available for the script to refer to. It would be easier to refer to 'arrowheads.ai', which is a standard Illustrator system file available to everyone by default. This file uses arrow objects as symbols, but I was not able to figure out how to import the symbol I need and apply it to my path object.
Copy link to clipboard
Copied
can you use the symbols in the arrowheads file? after breaking the link, the arrows are pathItems. If you can use them then there's a third option, you might be able to use Unicode arrows, there are many to choose from. You'll add a text frame, type your Unicode glyph, make outlines, etc
in regards of actions, your script could create the action on the fly and delete it after you're done.
Copy link to clipboard
Copied
In the end I made it to work (sort of) by copying the Graphic Style from my preset file. It opens 'default.ai', draws an object, applies the graphic style, copies the object, closes the 'default.ai', pastes the object in current document, deletes the object (Graphic Style is retained) and then I can apply the graphic style when needed. This way I can retain the functionality of the stroke object - it is not a group of paths and triangles or paths and symbols. Downside is that the script will only work on my PC and not universally.
Copy link to clipboard
Copied
that's how it's done unfortunately, if you plan on distributing the script you might find it useful to have the script alert the user the arrows ai file is needed.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now