Copy link to clipboard
Copied
Hello!
Do you know how to activate the Global option on Swatch options in Illustrator using a Script?
Hi Robsmith01, it seems a bit complicated due to the structure of colors in Illustrator. There are swatches and colors and spotColors and spots.
Check out the convertSelectedSwatchesToGlobal function below to give you a practical idea. It expects you to select swatch(es) in the Swatch Palette first. Or just call the individual function convertSwatchToGlobal with a single Swatch object passed in.
function convertSelectedSwatchesToGlobal() {
var swatches = app.activeDocument.swatches.getSelect
...
Copy link to clipboard
Copied
Hi Robsmith01, it seems a bit complicated due to the structure of colors in Illustrator. There are swatches and colors and spotColors and spots.
Check out the convertSelectedSwatchesToGlobal function below to give you a practical idea. It expects you to select swatch(es) in the Swatch Palette first. Or just call the individual function convertSwatchToGlobal with a single Swatch object passed in.
function convertSelectedSwatchesToGlobal() {
var swatches = app.activeDocument.swatches.getSelected();
for (var i = 0; i < swatches.length; i++) {
convertSwatchToGlobal(swatches[i]);
}
}
function convertSwatchToGlobal(swatch) {
if (swatch.color.typename == 'CMYKColor' || swatch.color.typename == 'RGBColor') {
var newSpot = app.activeDocument.spots.add();
newSpot.name = swatch.name;
newSpot.colorType = ColorModel.PROCESS;
newSpot.color = swatch.color;
var newSpotColor = new SpotColor();
newSpotColor.spot = newSpot;
swatch.remove()
}
}
convertSelectedSwatchesToGlobal();
One side effect is that the converted swatches will all be moved to the end of the swatches list, unless yours is sorted.
Regards,
Mark
Copy link to clipboard
Copied
It was very useful!
Thanks!
Copy link to clipboard
Copied
is this all you want to do? if checking Global is not a requirements of a larger script then you could select the swatches manually and check the option. All selected swatches will be affected in one go.