Deleting Unused Swatches

Community Beginner ,
Jul 27, 2009 Jul 27, 2009

Copy link to clipboard

Copied

Because I'm unable to invoke the "Select All Unused" menu item of the Swatches panel menu I'm trying to attack it programmatically.

What I'm trying to determine is if it's sufficient to compare the Fill and Stroke Color of each Path Item (every path item of current document) or are there other items that should be examined to achieve the same results as the command in the Swatches panel menu? Page Items doesn't appear to contain a Fill Color property. I've got AppleScript code that appears to do the trick, but I'd like to get input so as to make sure I'm not missing something that my testing might not have uncovered.

Thanks!

Stephan

TOPICS
Scripting

Views

4.1K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 27, 2009 Jul 27, 2009

Copy link to clipboard

Copied

Have you tried the Delete Unused Panel Items from the default Actions set? If you are using AS, you can use the do script construct to run the action.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 27, 2009 Jul 27, 2009

Copy link to clipboard

Copied

Yes, I looked at that as an option. The script I'm working on will be potentially used by a large number of folks and I can't be sure that the action is available. A user could have deleted it and then my script will fail. I could possibly check first to make sure it's there, but I'd like to work around the dependency in the first place.

What I'm trying to determine is what all items in a document are examined with the action. If I could reproduce it with my own code I'd feel that the solution I'm providing is foolproof. It'd be nice if I could just use UI scripting to select the unused color swatches and delete them, but I haven't found a way to access the menus of panels.

Thanks.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 27, 2009 Jul 27, 2009

Copy link to clipboard

Copied

Another method might be to remove the extra swatches from the startup files (or New Document Profiles as they are now known) So there are fewer unused swatches to deal with. Relatively few people take the time to modify the action sets aside from adding new ones. Here's how the Delete Unused Panel Items looks in the Default _Actions.aia file

/action-10 {
    /name (Delete Unused Panel Items)
    /keyIndex 0
    /colorIndex 0
    /isOpen 0
    /eventCount 8
    /event-1 {
        /internalName (ai_plugin_symbol_palette)
        /localizedName (Symbols)
        /isOpen 0
        /isOn 1
        /hasDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette -1
            /type (enumerated)
            /name (Select All Unused)
            /value 12
        }
    }
    /event-2 {
        /internalName (ai_plugin_symbol_palette)
        /localizedName (Symbols)
        /isOpen 0
        /isOn 1
        /hasDialog 1
        /showDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette -1
            /type (enumerated)
            /name (Delete Symbol)
            /value 5
        }
    }
    /event-3 {
        /internalName (ai_plugin_styles)
        /localizedName (Graphic Styles)
        /isOpen 0
        /isOn 1
        /hasDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette 1
            /type (enumerated)
            /name (Select All Unused)
            /value 14
        }
    }
    /event-4 {
        /internalName (ai_plugin_styles)
        /localizedName (Graphic Styles)
        /isOpen 0
        /isOn 1
        /hasDialog 1
        /showDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette 1
            /type (enumerated)
            /name (Delete Style)
            /value 3
        }
    }
    /event-5 {
        /internalName (ai_plugin_brush)
        /localizedName (Brush)
        /isOpen 0
        /isOn 1
        /hasDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette 1
            /type (enumerated)
            /name (Select All Unused)
            /value 8
        }
    }
    /event-6 {
        /internalName (ai_plugin_brush)
        /localizedName (Brush)
        /isOpen 0
        /isOn 1
        /hasDialog 1
        /showDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette 1
            /type (enumerated)
            /name (Delete Brush)
            /value 3
        }
    }
    /event-7 {
        /internalName (ai_plugin_swatches)
        /localizedName (Swatches)
        /isOpen 0
        /isOn 1
        /hasDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette 1
            /type (enumerated)
            /name (Select All Unused)
            /value 11
        }
    }
    /event-8 {
        /internalName (ai_plugin_swatches)
        /localizedName (Swatches)
        /isOpen 0
        /isOn 1
        /hasDialog 1
        /showDialog 0
        /parameterCount 1
        /parameter-1 {
            /key 1835363957
            /showInPalette 1
            /type (enumerated)
            /name (Delete Swatch)
            /value 3
        }
    }
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 28, 2009 Jul 28, 2009

Copy link to clipboard

Copied

Larry, Thanks for the tips. Unless I missed it, the .aia file doesn't seem to help in understanding exactly which items (path items, page items, text items, etc) are being examined when you go to select unused color swatches.

If anyone can tell me which items are being examined that'd be great. I'm fine examining those items. I'm hoping someone at Adobe can answer this for me.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 28, 2009 Jul 28, 2009

Copy link to clipboard

Copied

It would seem to be looking at any object which could have a color description of some sort. It deletes the Swatches in the reverse order of their use, i.e. a Symbol can use any of the other three types of swatches (Graphic Style, Brush or Swatch [color or pattern]), while a Graphic Style can use brushes or swatches but not symbols and so on.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 29, 2009 Jul 29, 2009

Copy link to clipboard

Copied

After thinking about this some more, there must be a flag set in the panels which identifies which swatches are used and any not used are selected for deletion.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2009 Aug 04, 2009

Copy link to clipboard

Copied

I ended up coming full circle and looking at just calling the "Delete All Unused Panel Items" from the Default Actions set. No I'm seeing this weird error message in more than half the time: "Could not complete the Play command because the action is playing." I'm not sure what that's about. I've verified that the action isn't already playing. Very strange. Anyone have any insight into this error message?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 04, 2009 Aug 04, 2009

Copy link to clipboard

Copied

Make sure no action or another action is highlighted in the Actions Panel. It happens if the action you want to use is highlighted.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2009 Aug 04, 2009

Copy link to clipboard

Copied

Is there a way programmatically to make sure an action isn't highlighted that you know of?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 04, 2009 Aug 04, 2009

Copy link to clipboard

Copied

Not that I'm aware of, sorry.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

I'm trying something similar with AppleScript and getting the same error. Does anyone know if there is a way to resolve this either manually or through AppleScript?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 26, 2017 Mar 26, 2017

Copy link to clipboard

Copied

Larry had it correct in saying actions are the key.

We don't care that people can add, modify and remove actions.

we just need to make sure we create the action we want, run it, then remove it.

Here is a working script that will create an action to selectAllUnused Swatches, and Delete that selection.

it will run the action after creating it, and then it removes the action keeping the users action panel as clean as when we started.

Let me know if you have any trouble with it...

//

//    SCRIPTED ACTIONS

//    creates an action, runs it, then removes it.

//

//    Author: Qwertyfly

//    Contact: tristan@qwertyfly.com

//

//    Version 1.001 - 27/3/17

//

//     Change Log:

//     V1.001 - setup for Delete Unused Swatches

//    

//

// All code within this script is the property of Tristan O'Brien.

// This script is free for personal use

// Permission is required prior to any commercial application.

//

//  any suggestions? drop me a line...

//

function QwertyflyScriptedActions_DeleteUnusedSwatches(){ 

    if(app.documents.length = 0){return;}

    var ActionSet = "QwertyflyScriptedActions"

    var Action1Name = "KillSwatches"

    var ActionString = '/version 3\n/name [ 24\n'+ Hexit(ActionSet) +'\n]\n/isOpen 0\n/actionCount 1\n/action-1 {\n/name [ 12\n'+ Hexit(Action1Name) +'\n]\n/keyIndex 0\n/colorIndex 0\n/isOpen 0\n/eventCount 2\n/event-1 {\n/useRulersIn1stQuadrant 1\n/internalName (ai_plugin_swatches)\n/localizedName [ 8\n5377617463686573\n]\n/isOpen 0\n/isOn 1\n/hasDialog 0\n/parameterCount 1\n/parameter-1 {\n/key 1835363957\n/showInPalette 1\n/type (enumerated)\n/name [ 17\n53656c65637420416c6c20556e75736564\n]\n/value 11\n}\n}\n/event-2 {\n/useRulersIn1stQuadrant 1\n/internalName (ai_plugin_swatches)\n/localizedName [ 8\n5377617463686573\n]\n/isOpen 0\n/isOn 1\n/hasDialog 1\n/showDialog 0\n/parameterCount 1\n/parameter-1 {\n/key 1835363957\n/showInPalette 1\n/type (enumerated)\n/name [ 13\n44656c65746520537761746368\n]\n/value 3\n}\n}\n}';

    createAction(ActionString,ActionSet);  

    ActionString = null; 

    app.doScript(Action1Name, ActionSet, false); 

    app.unloadAction(ActionSet,""); 

    function createAction (str,act) {  

        var f = new File('~/' + act+ '.aia');  

        f.open('w');  

        f.write(str);  

        f.close();  

        app.loadAction(f);  

        f.remove();  

    }

    function Hexit(str) {

        var hex = '';

        for(var i=0;i<str.length;i++) {

            hex += ''+str.charCodeAt(i).toString(16);

        }

        return hex;

    }

QwertyflyScriptedActions_DeleteUnusedSwatches();

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

LATEST

I had a similar issue, wherin everytime I tried to delete unused swatches, Illustrator crashed.  My solve was to expand all instances of symbols.  

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines