I used to use this script a bit. it has not been updated in a long time so is missing many of the newer PMS colors, and I believe pantone has modified many of the CMYK breakdowns over the past few years.
that said it should still give decent results if you don't need to be too accurate.
if you look at the code, Wunds has included all the swatch names and all the breakdown for CMYK and RGB.
it does not access a swatchbook in illustrator.
this makes it much more then an added few lines here and there to get it to recolor automatically.
a workaround to that is to save a document that has all the Pantone colors added to it's swatch pallet, then you can access them from there.
this thread has some info on the topic. How do I script Illustrator to get a PANTONE swatch from a swatch library
there is a built in function of the recolor Artwork Dialog that will convert colors to Pantone, but this is not scriptable with JS.
it could be done using VB Script with a few SendKey statements, not ideal but could work...
It sounds like adding pantone color is more difficult than I thought,
as an alternative, I am wondering if we can put the object in to the layer that has the name of pantone color?
For this, I think,
1) select 1 object and run above script to find out the pantone color name
2) take the first pantone color name ( which I think "matchlist" at line 162 )
3) creating a layer with the name of the pantone color name (matchlist) if it is not already exist.
4) select all objects with the same fill color.
5) move all selected object into the layer with the name of the pantone color.
Could you let me know if this is feasible to think about? or could you help on coding for this?
Thanks a lot.
I can't see that being an issue.
moving things to new layers based on their colour should not be hard.
but it will mess with your stacking order!
I would look at doing it right.
create a new doc, delete all swatches, add all PMS swatches from desired colorbook
this can be used to change the colours to the PMS swatch that it best matches
the Wundes script works only on the first item in selection.
you will need to make that a loop of all pathItems.
it also only checks the fill, and not the stroke.
a few more lines of code can fix that.
you will also want to remove the "do you want to use pastels" dialog. and all other dialogs...
you may also want to automate an increasing prec (precision) until it finds a match.
depending on what you want this for it may also pay to export all this info to a text doc so you can find any colours that are a poor match etc.
as you can see there is a few hours of messing around to tweak the script to do what you want.
and I am happy to help out with some of it.
give us some more info about how the final result is being used. I don't want to wast time on features that are not needed.
here is a bit of a start.
still does not do strokes.
still can fail badly in some cases.
it's using the "PANTONE+ Color Bridge Coated" color book.
this was loaded into the PMS.ai file
save the .ai file in the same directory as the script file.
this should give you a good place to get started.
Thanks a lot Qwerty.
The concept of swatch book was new to me and a bit confused.
But I believe I get the idea and will take a look and try to make it work.
so is this kinda doing what you wanted?
if so, I'm glad I could help.
sing out if you get stuck finishing it off.
cool, like I said, let me know if I can help you out some more.
with JS in illustrator we don't have access to swatch books.
but we do have access to the document swatches.
the PMS.ai file I made.
all I did was move all the colors from the "Pantone+ Color Bridge coated" in to the document swatches then save it.
then we can access the swatches from that document...
I used the color bridge as this swatch book has colors like Process Cyan C, unlike the newer Solid Coated V2 book. (I think they even have a newer one now)
just as a note.
if you are looking for what I have changed.
all changes I made have comments to show what I did.
// QF - now we open the document with all the PMS swatches in it.