-
1. Re: Batch replace color with another color
Muppet Mark Feb 5, 2010 12:05 PM (in response to lohari)I don't think you can do a color comparison like this in script. In the GUI you can select an path item and if its fill matches a swatch then its associated with it. Your 'findColor' will return a [swatch Object] which you can't compare to fillColor as this returns [color Object] . Im fairly new to using JavaScript but think you need to dig down deeper to there values to compare? I made only the simplest of test files to try this.
Try something like…
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var findColor = swatches.getByName('vih').color;
var replaceColor = swatches.getByName('sin').color;
for (var i = 0; i < pathItems.length; i++) {
with (pathItems[i].fillColor) {
if (cyan == findColor.cyan && magenta == findColor.magenta && yellow == findColor.yellow && black == findColor.black) {
$.writeln('True');
cyan = replaceColor.cyan, magenta = replaceColor.magenta, yellow = replaceColor.yellow, black = replaceColor.black;
} else {
$.writeln('False');
}
}
}
//saveAs(filePath, saveOptions)
}
My example was just swapping on CMYK for another. You may want to check what pageItems you have as NOT all will return you a fillColor?
-
2. Re: Batch replace color with another color
lohari Feb 5, 2010 2:43 PM (in response to Muppet Mark)Thank you Mark for answering, I tried the code you proposed, and it failed at the 'if' -statement with error "cyan is undefined". After that, I tried adding 'pathItems[i].fillColor.' in front of each undefined color. It resulted to the script running through, but not changing anything. So.. I still don't know if the comparison works or not
-
3. Re: Batch replace color with another color
Muppet Mark Feb 6, 2010 3:20 AM (in response to lohari)I only tried a very basic test in my case ALL path items were filled with various CMYK swatches and the swap did take place so the comparison did work. I would suspect that you have a path item that contains NO fill so any of its properties would be undefined. You can also include this in your code too. This should work for both filled and stroked path items in CMYK art.
#target illustrator
var docRef = app.activeDocument;
with (docRef) {
var findColor = swatches.getByName('vih').color;
var replaceColor = swatches.getByName('sin').color;
for (var i = 0; i < pathItems.length; i++) {
if (pathItems[i].filled == true) {
with (pathItems[i].fillColor) {
if (cyan == findColor.cyan && magenta == findColor.magenta && yellow == findColor.yellow && black == findColor.black) {
$.writeln('True');
cyan = replaceColor.cyan, magenta = replaceColor.magenta, yellow = replaceColor.yellow, black = replaceColor.black;
} else {
$.writeln('False');
}
}
}
if (pathItems[i].stroked == true) {
with (pathItems[i].strokeColor) {
if (cyan == findColor.cyan && magenta == findColor.magenta && yellow == findColor.yellow && black == findColor.black) {
$.writeln('True');
cyan = replaceColor.cyan, magenta = replaceColor.magenta, yellow = replaceColor.yellow, black = replaceColor.black;
} else {
$.writeln('False');
}
}
}
}
//saveAs(filePath, saveOptions)
}
-
4. Re: Batch replace color with another color
Tony_Wide Feb 12, 2010 6:51 AM (in response to Muppet Mark)Hi,
I was tried this in Illustrator CS4 with Extendscript toolkit. I am getting some error pls find the attachment.
Thank you
-
Picture 1.png 15.1 K
-
-
5. Re: Batch replace color with another color
Muppet Mark Feb 12, 2010 8:23 AM (in response to Tony_Wide)And do you have a swatch in the current documents swatches pallet called 'vih'
getByName will fail like this if it does NOT exist…
-
6. Re: Batch replace color with another color
Tony_Wide Feb 12, 2010 11:02 PM (in response to Muppet Mark)Hi Mark,
There is no such swatch in my palette. need to create this swatch or what (Vih, sin)? if yes what color to use for this? and what is the purpose of creating this. Can u explain me little bit clear.
Joe
-
7. Re: Batch replace color with another color
Muppet Mark Feb 13, 2010 1:13 AM (in response to Tony_Wide)Joe, the following lines set a variable reference to the color of 2 swatches. Like I said using getByName() will fail if its NOT there. You can change the names 'vih' & 'sin' to the names of 2 colors that you do have in your swatches pallet. The rest of the script does a compassion of the CMYK values ONLY so both of your swatches need to be this.
var findColor = swatches.getByName('vih').color;
var replaceColor = swatches.getByName('sin').color;
-
8. Re: Batch replace color with another color
Tony_Wide Feb 15, 2010 7:41 PM (in response to Muppet Mark)Hi mark,
The same script i have modified little bit to convert one pantone to another pantone but here i am getting some error PFA.
#target illustratorvar docRef = app.activeDocument;with (docRef) {var findColor = swatches.getByName('PANTONE 133 C').color;var replaceColor = swatches.getByName('PANTONE 101 C').color;for (var i = 0; i < pathItems.length; i++) {if (pathItems[i].filled == true) {with (pathItems[i].fillColor) {if (PANTONE 133 C == findColor.PANTONE 133 C) {$.writeln('True');PANTONE 101 C = replaceColor.PANTONE 101 C;} else {$.writeln('False');}}}if (pathItems[i].stroked == true) {with (pathItems[i].strokeColor) {if (PANTONE 133 C == findColor.PANTONE 133 C) {$.writeln('True');PANTONE 101 C = replaceColor.PANTONE 101 C;} else {$.writeln('False');}}}}//saveAs(filePath, saveOptions)}Pls give suggestion. Here i want to find PANTONE 133 C and replace with PANTONE 101 C. -
9. Re: Batch replace color with another color
Muppet Mark Feb 16, 2010 4:16 AM (in response to Tony_Wide)Im busy at work at the mo… but have a script that I was working on last night (learning JS @ home) that should do this for you. I'll post it L8R…
-
10. Re: Batch replace color with another color
Muppet Mark Feb 16, 2010 2:18 PM (in response to Muppet Mark)I would expect something like this to be close although I've NOT looked into colored placed items yet…
#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[i]) {
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[j]) {
for (var k = 0; k < characters.length; k++) {
with (characters[k].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;
}
}
}
}
}
}
-
11. Re: Batch replace color with another color
Tony_Wide Feb 16, 2010 9:10 PM (in response to Muppet Mark)Hi Mark,
Thank you its really working fine...
joe


