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

Merging swatches

Contributor ,
Oct 02, 2015 Oct 02, 2015

Hello everyone,

I was wondering if there was a way to merge swatches via script. I only see ways to add or delete.

Thanks!

TOPICS
Scripting
3.0K
Translate
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

correct answers 1 Correct answer

Engaged , Oct 02, 2015 Oct 02, 2015

Re: Batch replace color with another color

#target illustrator

var docRef = app.activeDocument;

with (docRef) {

    var replaceColor = swatches.getByName('PANTONE 101 C').color;

    for (var i = 0; i < pathItems.length; i++) {

    with (pathItems) {

        if (filled == true && fillColor instanceof SpotColor) {

            if (fillColor.spot.name == 'PANTONE 133 C') fillColor = replaceColor;

        }

        if (stroked == true && strokeColor instanceof SpotColor) {

            if (strokeCol

...
Translate
Adobe
Contributor ,
Oct 02, 2015 Oct 02, 2015

Hello man,

I don't understand what kind of merge you want to do, sum your values in new swatche? For example swatche x: cyan = 50 | magenta = 30 | yellow = 0 | black = 10, swatche y: cyan = 10 | magenta = 10 | yellow = 10 | black = 10, swatch result = cyan = 60 | magenta = 40 | yellow = 10 | black = 20.

what purpose of this?

Best regards

Vinícius

Translate
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
Engaged ,
Oct 02, 2015 Oct 02, 2015

I assume he means like this, but with a script.

Screen Shot 2015-10-02 at 2.16.18 PM.png

Translate
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
Contributor ,
Oct 02, 2015 Oct 02, 2015

yea exactly, thanks

Translate
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
Engaged ,
Oct 02, 2015 Oct 02, 2015

Re: Batch replace color with another color

#target illustrator

var docRef = app.activeDocument;

with (docRef) {

    var replaceColor = swatches.getByName('PANTONE 101 C').color;

    for (var i = 0; i < pathItems.length; i++) {

    with (pathItems) {

        if (filled == true && fillColor instanceof SpotColor) {

            if (fillColor.spot.name == 'PANTONE 133 C') fillColor = replaceColor;

        }

        if (stroked == true && strokeColor instanceof SpotColor) {

            if (strokeColor.spot.name == 'PANTONE 133 C') strokeColor = replaceColor;

            }

        }

    }

   

    for (var j = 0; j < stories.length; j++) {

        with (stories) {

            for (var k = 0; k < characters.length; k++) {

                with (characters.characterAttributes) {

                    if (fillColor instanceof SpotColor) {

                        if (fillColor.spot.name == 'PANTONE 133 C') fillColor = replaceColor;

                    }

                    if (strokeColor instanceof SpotColor) {

                        if (strokeColor.spot.name == 'PANTONE 133 C') strokeColor = replaceColor;

                    }

                }

            }

        }

    }

}

Translate
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
Contributor ,
Oct 02, 2015 Oct 02, 2015

var docRef = app.activeDocument;

var colorToKill = 'ORANGE PMS 172';

var colorToLive = 'YELLOW PMS 109';

docRef.selection = null;

var rect = docRef.pathItems.rectangle (20, 0, 20, 20);

rect.filled = true;

rect.fillColor = docRef.swatches.getByName (colorToKill).color;

rect.selected = true;

rect.remove();

app.executeMenuCommand ('Find Fill Color menu item');

for (i = 0; i < docRef.selection.length; i++) {

   

    {

    docRef.selection.fillColor = docRef.swatches.getByName (colorToLive).color;

   

    }

}

docRef.selection = null;

var rect = docRef.pathItems.rectangle (20, 0, 20, 20);

rect.stroked = true;

rect.strokeColor = docRef.swatches.getByName (colorToKill).color;

rect.selected = true;

rect.remove();

app.executeMenuCommand ('Find Stroke Color menu item');

for (i = 0; i < docRef.selection.length; i++) {

   

    {

    docRef.selection.strokeColor = docRef.swatches.getByName (colorToLive).color;

   

    }

}

docRef.selection = null;

  with (docRef) {

    for (var j = 0; j < stories.length; j++) { 

        with (stories) { 

            for (var k = 0; k < characters.length; k++) { 

                with (characters.characterAttributes) { 

                   if (fillColor instanceof SpotColor) { 

                        if (fillColor.spot.name == colorToKill)  fillColor = swatches.getByName(colorToLive).color;

                                                                

                   }

                    if (strokeColor instanceof SpotColor) { 

                        if (strokeColor.spot.name == colorToKill)  strokeColor = swatches.getByName(colorToLive).color;

                                                                

                   }

                         

                    } 

               

            }

        } 

    } 

}

docRef.swatches.getByName(colorToKill).remove();

Thanks for the help, I learned some new syntax and shortcuts by looking at what you wrote. I will test this out and see if I run into any problems, I would like to avoid looping pathitems if at all possible (I have to deal with a bunch of crazy livetraced crap haha)

Thanks everyone!

Translate
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
Engaged ,
Oct 05, 2015 Oct 05, 2015

Credit for writing goes to Muppet Mark‌. I only get credit for needing the info once and passing it on to you. Good Luck.

Translate
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
Participant ,
Feb 16, 2016 Feb 16, 2016
LATEST

How to Merge any color swatches in illustrator using Javascript

Screen Shot 2016-02-15 at 3.45.21 pm.png

when you select two swatches, and go to merge swatches, the 2nd swatch you select disappears, and everything in the document that had the 2nd swatch takes the color of the 1st swatch you selected.

Translate
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
Contributor ,
Oct 02, 2015 Oct 02, 2015

Like in your swatch dialog box, when you select two swatches, and go to merge swatches, the 2nd swatch you select disappears, and everything in the document that had the 2nd swatch takes the color of the 1st swatch you selected.

I understand that I could loop through all the path items in the document, change the fill or/and stroke of the path items with the 2nd swatch to the 1st swatch, and then delete the 2nd swatch, but I was wondering if there was a more efficient way sometime I get documents with thousands and thousands of path items and it takes a minute or two.

I guess another way would be to deselect everything, create a rectangle that's selected with the fill of the 2nd swatch, delete the rectangle, select same fill through menu command, then loop through the selected items and give them all the fill of the 1st swatch....repeat the steps for the stroke....and then delete that 2nd swatch. That would be more efficient than looking for all the paths I will probably go with this plan if there isn't a way to merge swatches.

Translate
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