Skip to main content
Known Participant
August 14, 2020
Answered

Illustrator script to remove the unwanted swatches

  • August 14, 2020
  • 1 reply
  • 2501 views

Hi Everyone ,

Im trying to remove the unwanted swatches in my document. But it would not work. Could anyone help me to remove the unwanted swatches in the active document

Correct answer Charu Rajput

Hi Raghav,

There is no direct API to delete the unused swatches. This possible via action only. There is another way of doing this but in the end it also using actions. Try following code

 

 

function unusedSwatch(){
    actionString = [
        '/version 3',
        '/name [ 8',
        '756e757365647377',
        ']',
        '/isOpen 1',
        '/actionCount 1',
        '/action-1 {',
        '/name [ 8',
        '737774636864656c',
        ']',
        '/keyIndex 0',
        '/colorIndex 0',
        '/isOpen 0',
        '/eventCount 2',
        '/event-1 {',
        '/useRulersIn1stQuadrant 0',
        '/internalName (ai_plugin_swatches)',
        '/localizedName [ 8',
        '5377617463686573',
        ']',
        '/isOpen 0',
        '/isOn 1',
        '/hasDialog 0',
        '/parameterCount 1',
        '/parameter-1 {',
        '/key 1835363957',
        '/showInPalette 4294967295',
        '/type (enumerated)',
        '/name [ 17',
        '    53656c65637420416c6c20556e75736564',
        ']',
        '/value 11',
        '}',
        '}',
        '/event-2 {',
        '/useRulersIn1stQuadrant 0',
        '/internalName (ai_plugin_swatches)',
        '/localizedName [ 8',
        '5377617463686573',
        ']',
        '/isOpen 0',
        '/isOn 1',
        '/hasDialog 1',
        '/showDialog 0',
        '/parameterCount 1',
        '/parameter-1 {',
        '/key 1835363957',
        '/showInPalette 4294967295',
        '/type (enumerated)',
        '/name [ 13',
        '    44656c65746520537761746368',
        ']',
        '/value 3',
        '}',
        '}',
        '}'
   ].join('\n')
        $.writeln('hit')
        var f = new File(Folder.desktop + "/unusedsw.aia");
        f.open('w')
        f.write(actionString)
        f.close()
        app.loadAction(f)
        app.doScript('swtchdel','unusedsw')
        app.unloadAction('unusedsw', '');
        f.remove();
}

unusedSwatch();

 

 

The difference here is action string is in the code instead of separate file. It also creating a file in the background but also removing it. For me it is almost same solution just a different way of doing that.

 

1 reply

Charu Rajput
Community Expert
Community Expert
August 14, 2020

Hi,

You can record the action and execute the action using script. I have recorded the action, you can download the action file from. below link and make sure to keep this file on your desktop. Following is the script to execute the action file

 

Action File 

 

var actionFile = File(Folder.desktop + "/Delete Unused Swatches.aia");
app.loadAction(actionFile);
app.doScript('Delete Unused Swatches', 'Set 1');
app.unloadAction('Set 1', '');

Let us know if this works for you.

 

Best regards
Known Participant
August 20, 2020

Hi Charu,

Thanks for your update. Is there any possible way for delete the unwanted swatches without making actions file?

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
August 20, 2020

Hi Raghav,

There is no direct API to delete the unused swatches. This possible via action only. There is another way of doing this but in the end it also using actions. Try following code

 

 

function unusedSwatch(){
    actionString = [
        '/version 3',
        '/name [ 8',
        '756e757365647377',
        ']',
        '/isOpen 1',
        '/actionCount 1',
        '/action-1 {',
        '/name [ 8',
        '737774636864656c',
        ']',
        '/keyIndex 0',
        '/colorIndex 0',
        '/isOpen 0',
        '/eventCount 2',
        '/event-1 {',
        '/useRulersIn1stQuadrant 0',
        '/internalName (ai_plugin_swatches)',
        '/localizedName [ 8',
        '5377617463686573',
        ']',
        '/isOpen 0',
        '/isOn 1',
        '/hasDialog 0',
        '/parameterCount 1',
        '/parameter-1 {',
        '/key 1835363957',
        '/showInPalette 4294967295',
        '/type (enumerated)',
        '/name [ 17',
        '    53656c65637420416c6c20556e75736564',
        ']',
        '/value 11',
        '}',
        '}',
        '/event-2 {',
        '/useRulersIn1stQuadrant 0',
        '/internalName (ai_plugin_swatches)',
        '/localizedName [ 8',
        '5377617463686573',
        ']',
        '/isOpen 0',
        '/isOn 1',
        '/hasDialog 1',
        '/showDialog 0',
        '/parameterCount 1',
        '/parameter-1 {',
        '/key 1835363957',
        '/showInPalette 4294967295',
        '/type (enumerated)',
        '/name [ 13',
        '    44656c65746520537761746368',
        ']',
        '/value 3',
        '}',
        '}',
        '}'
   ].join('\n')
        $.writeln('hit')
        var f = new File(Folder.desktop + "/unusedsw.aia");
        f.open('w')
        f.write(actionString)
        f.close()
        app.loadAction(f)
        app.doScript('swtchdel','unusedsw')
        app.unloadAction('unusedsw', '');
        f.remove();
}

unusedSwatch();

 

 

The difference here is action string is in the code instead of separate file. It also creating a file in the background but also removing it. For me it is almost same solution just a different way of doing that.

 

Best regards