Skip to main content
MidoSemsem
Inspiring
May 23, 2024
Answered

A Script to Reorganize Appearance Panel

  • May 23, 2024
  • 2 replies
  • 784 views

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! 

This topic has been closed for replies.
Correct answer MidoSemsem

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 


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.

2 replies

Kurt Gold
Community Expert
Community Expert
May 24, 2024

By the way, this could also be done with a simple action (at least as far as I understand the task).

m1b
Community Expert
Community Expert
May 23, 2024

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

MidoSemsem
Inspiring
May 24, 2024

Thanks @m1b

 

Sorry to hear that 

Can this be applied by graphic styles? 

 

m1b
Community Expert
Community Expert
May 24, 2024

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