• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Rename swatches / edit rgb values of swatches

New Here ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

hi

I need a script for 2 parts

  1. for mapping colornames e.g. search "colorname1" to "colorname2". both colors are swatches
  2. for mapping the rgb values of an color. e.g. "color1 rgb 0,50,150" to "color1 rgb 0,80,200" (swatch)
TOPICS
Scripting

Views

1.0K

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
Adobe
Community Expert ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

Are you looking for help writing a script or are you looking for someone to write a script for you?

Votes

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
New Here ,
May 23, 2016 May 23, 2016

Copy link to clipboard

Copied

the second one - but I thougt many people need this and its alrady done 😞

Votes

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
Community Expert ,
May 23, 2016 May 23, 2016

Copy link to clipboard

Copied

So you don't need the script anymore?

That's fine. But if this script worked for you, could you please mark it as correct so that it may help someone searching for the same question in the future?

Votes

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
New Here ,
May 24, 2016 May 24, 2016

Copy link to clipboard

Copied

no, sorry, the script don't work.

Votes

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
Community Expert ,
May 24, 2016 May 24, 2016

Copy link to clipboard

Copied

What result did you get when you tried this script?

Votes

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
New Here ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

the swatch is renamed and has a new value

but all objects of the graphic lost the swatch

Votes

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
Community Expert ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

Oh yes.. I suppose it wouldn't have. You asked how to change the name and value of a swatch, not update the colors of any item that uses that color. It is a much much larger undertaking to update the colors in the document. You can't simply change a swatch, you actually have to loop the pageItems and check for the desired color and change the fillColor attribute to the new swatch.

Votes

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
Community Expert ,
May 20, 2016 May 20, 2016

Copy link to clipboard

Copied

function changeSwatch()

{

    var docRef = app.activeDocument;

    var swatches = docRef.swatches;

    var theSwatch = swatches["colorname1"];

    theSwatch.name = "colorname2";

    var swatchColor = new RGBColor();

        swatchColor.red = 0;

        swatchColor.green = 80;

        swatchColor.blue = 200;

      

    theSwatch.color = swatchColor;

    theSwatch.red = 0;

    theSwatch.green = 80;

    theSwatch.blue = 200;

  

}

changeSwatch();

Votes

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
Community Beginner ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

if the colors were set as global, and objects painted with them, you could easily change the colors using the script provided.

Votes

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
Community Expert ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

when you use the UI to make the change, this is true. However if you use javascript to change the properties of a swatch, it is not applied globally to all objects that have that global swatch applied.

the only way to do this is to loop all the pageItems and change the fillColor property conditionally like so:

var docRef = app.activedocument

var newSwatch = new RGBColor();

newSwatch.red = 0;

newSwatch.green = 80;

newSwatch.blue = 200;

var oldSwatch = docRef.swatches["oldSwatch"];

var oldSwatchName = "oldSwatch";

var items = docRef.pageItems;

for(var a=0;a<items.length;a++)

{

    if(items.fillColor.spot.name == oldSwatchName)

    {

          items.fillColor = newSwatch;

    }

}

The problem with this is that if you have any groups or compound paths, this won't work. It's much more involved because you need recursive loops to dig to the bottom of each group and compound path to compare every pathItem to find out whether the color needs to be changed.

It's not impossible, but it is much more involved than you think.

Votes

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
Community Expert ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

… and some other problems remains:

You have no access to additional fill or stroke colors (which are added in the appereance palette).

And what is if the color isn't RGB ?

And what is with colors in symbols ?

And …

Votes

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
Community Expert ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

indeed.

it seems like this would be really easy if....

ADOBE WOULD FRIGGING GIVE JAVASCRIPT ACCESS TO THE MERGE SWATCHES FUNCTION!!!!!!!!

i hope you're listening, adobe.. though i know you're not.

Votes

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
Community Expert ,
May 25, 2016 May 25, 2016

Copy link to clipboard

Copied

… and a very long-cherished wish of many users:   /* is this the correct wording in english? */

Shortcuts for scripts

and, and, and:

Illustrator scripting bug list.

Votes

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
Enthusiast ,
May 26, 2016 May 26, 2016

Copy link to clipboard

Copied

It's OK for global swatch, the problem is his swatch just not global I think.

And if for this purpose only, instead of script, using "recolor artwork" menu is more easy?

function changeSwatch() {

    var theSwatch = activeDocument.swatches["colorname1"];

    if (theSwatch.color.typename === 'SpotColor' ) {

        theSwatch.name = "colorname2";

        var swatchColor = new RGBColor();

        swatchColor.red = 0;

        swatchColor.green = 80;

        swatchColor.blue = 200;

       

        var s = theSwatch.color.spot;

        s.color = swatchColor;

        s.sportKind = SpotColorKind.SPOTRGB;

    };

}

changeSwatch();

Votes

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
New Here ,
May 30, 2016 May 30, 2016

Copy link to clipboard

Copied

LATEST

thanks to you all.

I have dissolved the problem with "actions".

I take colornames with an "_" at the end. at the end of the action I use a script to delete the "_".

so I can map 1000ends of motifs without one click.

Votes

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