Copy link to clipboard
Copied
Hello!
Task:
Expected result:
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!
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 (
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.
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();
}
}
Copy link to clipboard
Copied
I use this 🙂
function SwatchesUngroup() {
// Script ID variables
var scriptID = 'SwatchesUngroup';
var scriptDescription = 'Ungroups all swatch groups.';
// Bail if no open documents
if (app.documents.length == 0) {
alert('Oops! No open documents.',scriptID);
return;
}
// Local variables
var aDoc = app.activeDocument;
var aDocSwatchGroups = aDoc.swatchGroups;
var mainGroup = aDocSwatchGroups[0]; // 'ungrouped' swatches at top of panel
// Run script?
var promptSwatches = confirm(scriptDescription + '\n\nContinue?', false, scriptID);
// Bail if No or Cancel or X
if (promptSwatches != true ) {
alert('Script has been stopped.', scriptID);
return;
}
// Bail if no swatch groups
if (aDocSwatchGroups.length < 2) {
alert('No swatch groups to ungroup.', scriptID);
return;
}
// Move swatches to mainGroup and delete empty groups
while (aDocSwatchGroups.length > 1) {
var swatches = aDocSwatchGroups[1].getAllSwatches()
for (var j = 0; j < swatches.length; j++) {
var swatch = swatches[j];
mainGroup.addSwatch(swatch);
}
aDocSwatchGroups[1].remove()
}
} // function
// Run this puppy :)
SwatchesUngroup();