• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete unused swatches in InDesign CS5, js

Participant ,
Dec 29, 2011 Dec 29, 2011

Copy link to clipboard

Copied

Hi,

I need to select and delete unused swatches in InDesign CS5. I looked through OMV in "Swatches" and "Swatch", but I could not find any function to select unused swatch and delete it.

Am I looking for it in the wrong place?

And I also need to read color values for used swatches. I got this in OMV and was hoping it would give me an array of the color values for all existing swatches, but I am only getting "Object color":


mySwatches = myDoc.swatches[1].getElements();


alert (mySwatches)

Thank you for your help.

Yulia

TOPICS
Scripting

Views

9.2K

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 Expert ,
Dec 29, 2011 Dec 29, 2011

Copy link to clipboard

Copied

check this thread, i think siva prasath has answered this (it is the last post in the thread)

http://forums.adobe.com/message/4059167

it deletes unused swatches and gradients without any ramifications.

to make it more useful, try adding this line to the start of the script:

app.menuActions.item("$ID/Add All Unnamed Colors").invoke();

as this will add any unnamed colours to the list of swatches, and then siva's script will remove all of the unused swatches/gradients.

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

Votes

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 ,
Jan 01, 2012 Jan 01, 2012

Copy link to clipboard

Copied

Hi Yuliaart,

Try this script it will help ful.

# target "Deleting unused swatches change the gradient"
var myIndesignDoc = app.activeDocument;
var myUnusedSwatches = myIndesignDoc.unusedSwatches;
for (var s = myUnusedSwatches.length-1; s >= 0; s--) {
     var mySwatch = myIndesignDoc.unusedSwatches
;
     var name = mySwatch.name;
// alert (name);
  if (name != ""){
mySwatch.remove();
}
}

Votes

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
Explorer ,
Oct 12, 2012 Oct 12, 2012

Copy link to clipboard

Copied

Hi siva,

I am a beginner to Indesign scripting. I have a doubt in this script (Delete unused Swatches).

What is the correct meaning for the below command from your script? What this command actually did?

 

"if (name != "")"

 

I know, this command is used, not to affect the applied gradients, Can you please give some other similarity for this use of command?

I want to know the actual meaning and usage of this command

Can you please clear?

Votes

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
Engaged ,
Oct 12, 2012 Oct 12, 2012

Copy link to clipboard

Copied

if the variable name does not equal nothing then remove the swatch.

Votes

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
Contributor ,
Nov 11, 2012 Nov 11, 2012

Copy link to clipboard

Copied

hi,

i also used "siva's script for removing unused swatches.

my query is! do it say the name of the swatch deleted, as requested by Yuliaart, earlier.

thanks,

rajnikanth

Votes

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
Engaged ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

The alert is commented out.

Votes

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
Engaged ,
Jan 03, 2012 Jan 03, 2012

Copy link to clipboard

Copied

function trashUnusedSwatch(){

    while (myDocument.unusedSwatches[0].name != "") {

            id = myDocument.unusedSwatches[0].id;

            sw = myDocument.swatches.itemByID(id);

            sw.remove();

        }

    }

This should also work.

Votes

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
Participant ,
Jan 05, 2012 Jan 05, 2012

Copy link to clipboard

Copied

Love it!

Thank you.

Votes

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
Explorer ,
Aug 20, 2017 Aug 20, 2017

Copy link to clipboard

Copied

LATEST

Do you realize you gave yourself, as the OP, the “correct answer” instead of the actual user who answered it.

Votes

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