Skip to main content
June 27, 2020
Answered

Activate the Global option on Swatch options - Illustrator Script

  • June 27, 2020
  • 2 replies
  • 5595 views

Hello!

Do you know how to activate the Global option on Swatch options in Illustrator using a Script?


This topic has been closed for replies.
Correct answer m1b

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

2 replies

CarlosCanto
Community Expert
Community Expert
June 28, 2020

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.

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 27, 2020

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

June 30, 2020

It was very useful!

Thanks!