How to ungroup all swatch groups?

Engaged ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

Hello!

Task:

task.png

Expected result:

result.png

PS. The problem is that it does not impossible - select swatch group on palette swatches via script (to start the ungrouping through action).

PPS. Or if make duplicate swatches and remove all swatch groups then the document items loose the original colors.

Thanks!

TOPICS
Scripting

Views

1.0K

Likes

translate

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

Engaged , Dec 19, 2016 Dec 19, 2016
The problem turned out to be very simple. /** * ungroup all swatchGroups * */function ungrSw() {  var d        = activeDocument;  if (activeDocument.swatchGroups.length < 1) return;  var swGrps   = d.swatchGroups;  var mainSwGr = d.swatchGroups[0];  for (var i = 1; i < swGrps.length; i++) { // move swatches to main group    var swGr    = swGrps;    var swGrSws = swGr.getAllSwatches();    for (var j = 0; j < swGrSws.length; j++) {      var sw = swGrSws;      mainSwGr.addSwatch(sw);    }  }  for (...

Likes

translate

Translate

Translate
Enthusiast ,
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

If all of the swatches in group are pantone spot color, and all are used in document( if not, add some temp path to apply color), steps of the script can be:

- select all and cut

- remove all swatch groups except swatchGroups[0]

- paste in place(remember layers checked on) and swatches will be added automatically.

Likes

translate

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, 2016 Dec 19, 2016

Copy link to clipboard

Copied

The problem turned out to be very simple.

/**

* ungroup all swatchGroups

* */

function ungrSw() {

  var d        = activeDocument;

  if (activeDocument.swatchGroups.length < 1) return;

  var swGrps   = d.swatchGroups;

  var mainSwGr = d.swatchGroups[0];

  for (var i = 1; i < swGrps.length; i++) { // move swatches to main group

    var swGr    = swGrps;

    var swGrSws = swGr.getAllSwatches();

    for (var j = 0; j < swGrSws.length; j++) {

      var sw = swGrSws;

      mainSwGr.addSwatch(sw);

    }

  }

  for (var k = swGrps.length - 1; k > 0; k--) { // remove empty groups

    var obj = swGrps;

    obj.remove();

  }

}

Likes

translate

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