Skip to main content
Participant
August 26, 2024
Answered

Illustrator scripting help. How to know if Live Effect applied?

  • August 26, 2024
  • 2 replies
  • 423 views

Hello.

I can't figure out, is it possible to know somehow if any Live Effect applied to PageItem or some other object in a document? Using Graphic Styles turned out wrong.

This topic has been closed for replies.
Correct answer m1b

Unfortunately @jonas_5930, we can't know if a Live Effect is applied. The scripting API only gives access to the very basic appearance (1 x fill, 1 x stroke).

 

You can do something hacky like this:

(function () {

    var doc = app.activeDocument,
        item = doc.selection[0];

    var expandedItem = expandAppearance(item.duplicate());

    /* 
    * now compare `item` with `expandedItem` somehow:
    * - different `typename`?
    * - number of paths or pathItems?
    * - different visibleBounds?
    * 
    * Example - a square with Live Effect Drop Shadow:
    *   `item` is a PathItem with 4 pathPoints
    *   `expandedItem` is a GroupItem containing:
    *      - a GrouptItem containing two PathItems, and
    *      - a RasterItem
    * 
    * So from this you can be sure that the square
    * does have some kind of special appearance.
    * I don't know how reliably you'd be able to tell
    * which Live Effect though.
    * 
    * Note: later you will delete `expandedItem`.
    */

    function expandAppearance(item) {
        app.redraw();
        app.executeMenuCommand('expandStyle');
        return app.activeDocument.selection[0];
    };

})();

 

Sometimes that can help. But otherwise, it isn't a good answer for you, sorry.

- Mark 

2 replies

Kurt Gold
Community Expert
Community Expert
August 26, 2024

Rick Johnson's SelectMenu plugin has a couple of commands to select objects to which live effects are applied.

Perhaps it can help you.

Participant
August 28, 2024

Thank you very much.

I never heard about this plugin, but I saw similar opportunities in the Astute Graphic Stylism plugin.

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
August 26, 2024

Unfortunately @jonas_5930, we can't know if a Live Effect is applied. The scripting API only gives access to the very basic appearance (1 x fill, 1 x stroke).

 

You can do something hacky like this:

(function () {

    var doc = app.activeDocument,
        item = doc.selection[0];

    var expandedItem = expandAppearance(item.duplicate());

    /* 
    * now compare `item` with `expandedItem` somehow:
    * - different `typename`?
    * - number of paths or pathItems?
    * - different visibleBounds?
    * 
    * Example - a square with Live Effect Drop Shadow:
    *   `item` is a PathItem with 4 pathPoints
    *   `expandedItem` is a GroupItem containing:
    *      - a GrouptItem containing two PathItems, and
    *      - a RasterItem
    * 
    * So from this you can be sure that the square
    * does have some kind of special appearance.
    * I don't know how reliably you'd be able to tell
    * which Live Effect though.
    * 
    * Note: later you will delete `expandedItem`.
    */

    function expandAppearance(item) {
        app.redraw();
        app.executeMenuCommand('expandStyle');
        return app.activeDocument.selection[0];
    };

})();

 

Sometimes that can help. But otherwise, it isn't a good answer for you, sorry.

- Mark 

Participant
August 26, 2024

Thanks for the reply.
Well, that's sad news(

m1b
Community Expert
Community Expert
August 26, 2024

Yep. 100% agree.