Copy link to clipboard
Copied
Hello community! 👋
I’m looking for a script that can apply a blue fill and a yellow stroke to a selection, while the fill appears in front and the stroke in the background within the Appearance panel. This is to maintain organization within the panel itself, not merely applying a stroke outside.
Any help would be greatly appreciated!
After several attempts and modifications, I've finally crafted a script that seems to be functioning correctly. Below is the solution script that worked for me:
// Ensure an active document is open and a page item is selected
if (app.documents.length > 0 && app.activeDocument.selection.length > 0) {
var doc = app.activeDocument;
var myPageItem = doc.selection[0];
try {
// Try to get the graphic style and apply it
doc.graphicStyles.getByName("StyleName").applyTo(myPag
...
Copy link to clipboard
Copied
Unbelievably, the scripting API currently does not provide access to the capabilities of the Appearance Panel, such as applying multiple fills and strokes in arbitrary order. Via scripting we can only access "fillColor" and "strokeColor" with no control of order (stroke is always above fill). Sorry.
- Mark
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ah good question. Graphic styles do contain the appearance attributes as you see them in the appearance panel.
I've never scripted graphic styles, but I had a quick look at the docs and found ArtStyle. You seem to be able to do something like:
var myGraphicStyle = app.activeDocument.graphicStyles.getByName("my style");
myGraphicStyle.applyTo(myPageItem);
I haven't tested, but see if that's helpful.
- Mark
Copy link to clipboard
Copied
After several attempts and modifications, I've finally crafted a script that seems to be functioning correctly. Below is the solution script that worked for me:
// Ensure an active document is open and a page item is selected
if (app.documents.length > 0 && app.activeDocument.selection.length > 0) {
var doc = app.activeDocument;
var myPageItem = doc.selection[0];
try {
// Try to get the graphic style and apply it
doc.graphicStyles.getByName("StyleName").applyTo(myPageItem);
} catch (e) {
// Handle error silently
}
}
I hope this can be of help to anyone who might be facing similar issues.
Copy link to clipboard
Copied
Well done!
Copy link to clipboard
Copied
By the way, this could also be done with a simple action (at least as far as I understand the task).