Skip to main content
Known Participant
July 27, 2009
質問

Deleting Unused Swatches

  • July 27, 2009
  • 返信数 3.
  • 7424 ビュー

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

返信数 3

Egor Chistyakov
Inspiring
December 26, 2024
Qwertyfly___
Legend
March 27, 2017

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();

Participant
February 28, 2022

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

Larry G. Schneider
Community Expert
Community Expert
July 27, 2009

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.

Known Participant
July 27, 2009

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.

Larry G. Schneider
Community Expert
Community Expert
July 27, 2009

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
        }
    }
}