changing the color of raster items in illustrator

hey guys,

i’m just trying to change the color of a raster item… i must be missing something.


tell application "Adobe Illustrator"
	tell document 1
		set x to raster item 1 of layer 1
		set theNewColor to {spot:spot "NA"}
		set fill color of x to theNewColor
	end tell
end tell

any ideas?

thanks a lot,
jordan

You do not set a Fill Color ‘property’ but use the ‘colorize’ command on the object.

tell application "Adobe Illustrator"
	tell document 1
		set x to raster item 1 of layer 1
		set y to color of spot "NA"
		colorize x raster color y
	end tell
end tell

you just blew my mind. i hope this helps some other people cause i was going crazy.

thanks!
-jordan

… ok i’ve had some more time to play with it, and i’m running into a problem.

the raster image is the correct color, but it hasnt been associated with the spot. this is important if i’m trying to switch things that are spot this to spot that…

regardless, this will work for the most part, and i really appreciate it. adobe just did a horrible job documenting this stuff it seems.

thanks again,
jordan

The documentation says colors with RGB or CMYK? I can’t see a way with the actual spot? hum.

ok, so i’m playing with it, and if i add selected colors to the swatch palette, it recognizes the color as the correct spot so i can merge everything, so i can make an action to do that and script it in, like this:


tell application "Adobe Illustrator"
	tell document 1
		set x to raster item 1 of layer 1
		set y to color of spot "VG"
		get properties of x
		colorize x raster color y
		set selection to x
		do script "Add Selected Colors" from "Swatch Actions" without dialogs
	end tell
end tell

thats sort of clumsy, but the best ive been able to come up with so far. the only problem is, lets say i’ve got artwork with two raster images, one that should change to the new color, and one that shouldnt… i’m stuck.

still, we’re getting somewhere for sure. i was ready to scrap the whole idea and just make people manually color them in until i read this this morning. this will work for most designs here in the office.

-jordan

OK…

Not to overpost to the point I’m unbearable, but I got it!

It’s totally rigged, and I’d bet there’s a quicker way to do this, but…


on changecolors(oldOne, newOne)
	tell application "Adobe Illustrator"
		
		tell current document
			set whatwasselected to selection
			
			set selectedthenwhat to ""
			set selectedthenwhat1 to ""
			set selectedthenwhat2 to ""
			set selectedthenwhat3 to ""
			set selectedthenwhat4 to ""
			set selectedthenwhat5 to ""
			
			try
				set selectedthenwhat1 to every page item of every group item of selection
				set selectedthenwhat3 to every page item of every group item of every group item of selection
				set selectedthenwhat4 to every page item of every group item of every group item of every group item of selection
				set selectedthenwhat5 to every page item of every group item of every group item of every group item of every group item of selection
			end try
			try
				set selectedthenwhat2 to every page item of selection
			end try
			set selectedthenwhat to selectedthenwhat1 & selectedthenwhat2 & selectedthenwhat3 & selectedthenwhat4 & selectedthenwhat5
			
			set oldcolorinfo to color of spot oldOne
			set newcolorinfo to color of spot newOne
			
			repeat with x from 1 to (count of selectedthenwhat)
				set i to item x of selectedthenwhat
				set objectClass to class of i
				if objectClass is raster item then
					set selection to i
					set stupidsquare to make new rectangle at the beginning of layer 1
					set stupidsquarecolor to fill color of stupidsquare
					try
						set stupidsquarecolor to spot of stupidsquarecolor
						set stupidsquarecolor to color of stupidsquarecolor
					end try
					
					if stupidsquarecolor is oldcolorinfo then
						colorize i raster color newcolorinfo
						do script "Add Selected Colors" from "Swatch Actions" without dialogs
					end if
					delete stupidsquare
					set selection to ""
				end if
				if objectClass is compound path item then
					repeat with j from 1 to (count of path items of i)
						try
							if (the name of spot of fill color of path item j of i begins with oldOne) then set fill color of path item j of i to {spot:spot newOne}
						end try
						try
							if (the name of spot of stroke color of path item j of i begins with oldOne) then set stroke color of path item j of i to {spot:spot newOne}
						end try
						try
							if (the name of pattern of fill color of path item j of i begins with oldOne) then set fill color of path item j of i to {spot:spot newOne}
						end try
						try
							if (the name of pattern of stroke color of path item j of i begins with oldOne) then set stroke color of path item j of i to {spot:spot newOne}
						end try
					end repeat
				end if
				try
					if the name of spot of fill color of i begins with oldOne then set the fill color of i to {spot:spot newOne}
				end try
				try
					if the name of spot of stroke color of i begins with oldOne then set the stroke color of i to {spot:spot newOne}
				end try
				try
					if the name of pattern of fill color of i begins with oldOne then set the fill color of i to {spot:spot newOne}
				end try
				try
					if the name of pattern of stroke color of i begins with oldOne then set the stroke color of i to {spot:spot newOne}
				end try
				
				try
					if the name of spot of fill color of character 1 of i begins with oldOne then set the fill color of every text of i to {spot:spot newOne}
				end try
				try
					if the name of spot of stroke color of character 1 of i begins with oldOne then set the fill color of every text of i to {spot:spot newOne}
				end try
				try
					if the name of pattern of fill color of character 1 of i begins with oldOne then set the fill color of every text of i to {spot:spot newOne}
				end try
				try
					if the name of pattern of stroke color of character 1 of i begins with oldOne then set the fill color of every text of i to {spot:spot newOne}
				end try
				
			end repeat
			set selection to whatwasselected
			
		end tell
	end tell
end changecolors

Basically, if I select the raster item and make a square, it’ll make it the color I need, and I can just look to that for the answers.

Pretty ridiculous, but it works!

Thanks for the help,
Jordan

I can’t get any of this to work in Illustrator CS3, nor can I get it to work in Illustrator CS5. Help?

the error I get is that Applescript doesn’t understand the colorize message…