Highlighted

Activate the Global option on Swatch options - Illustrator Script

Community Beginner ,
Jun 27, 2020

Copy link to clipboard

Copied

Hello!

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


1941EE06-E10B-417E-B5B2-27721AD65C2F.jpeg

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

TOPICS
How to, Scripting

Views

123

Likes

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

Activate the Global option on Swatch options - Illustrator Script

Community Beginner ,
Jun 27, 2020

Copy link to clipboard

Copied

Hello!

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


1941EE06-E10B-417E-B5B2-27721AD65C2F.jpeg

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

TOPICS
How to, Scripting

Views

124

Likes

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
Jun 27, 2020 0
Contributor ,
Jun 27, 2020

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

Likes

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
Reply
Loading...
Jun 27, 2020 1
Community Beginner ,
Jun 29, 2020

Copy link to clipboard

Copied

It was very useful!

Thanks!

Likes

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
Reply
Loading...
Jun 29, 2020 0
Adobe Community Professional ,
Jun 27, 2020

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.

Likes

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
Reply
Loading...
Jun 27, 2020 0