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

Remove unused Swatch Groups

Explorer ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

Hi, guys!

Is there any script code to remove unused core sample group? I know the code to erase color swatches, but not groups.
Exmple to remove color swatches (not groups):

 

var allDocs = app.documents;

for (var i = 0; i < allDocs.length; i++) {
trashUnusedSwatch (allDocs[i]);
}

function trashUnusedSwatch(myDocument){
var id, sw;
while (myDocument.unusedSwatches[0].name != "") {
id = myDocument.unusedSwatches[0].id;
sw = myDocument.swatches.itemByID(id);
sw.remove();
}
}

 

TOPICS
Feature request , How to , Scripting

Views

133

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

correct answers 1 Correct answer

Participant , Feb 10, 2024 Feb 10, 2024

Try this:

var allDocs = app.documents;

for (var i = 0; i < allDocs.length; i++) {
    trashUnusedSwatchGroups (allDocs[i]);
}

function trashUnusedSwatchGroups(myDocument){
    for (var j=myDocument.colorGroups.count()-1; j>=0; j--) {
        if(myDocument.colorGroups[j].colorGroupSwatches.length == 0) {
            myDocument.colorGroups[j].remove();
        }
    }
}

Votes

Translate

Translate
Participant ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

Try this:

var allDocs = app.documents;

for (var i = 0; i < allDocs.length; i++) {
    trashUnusedSwatchGroups (allDocs[i]);
}

function trashUnusedSwatchGroups(myDocument){
    for (var j=myDocument.colorGroups.count()-1; j>=0; j--) {
        if(myDocument.colorGroups[j].colorGroupSwatches.length == 0) {
            myDocument.colorGroups[j].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 ,
Feb 11, 2024 Feb 11, 2024

Copy link to clipboard

Copied

LATEST

Thanks so much!

 

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