Refreshing swatches in Illustrator CS2/CS3

I have a FileMaker Pro database that contains a script to generate a legend (client and job info etc) in Adobe Illustrator CS2 from the information in the database.

An Illustrator document is like a template with placeholder text and 8 swatches named Col 1, Col 2 etc. Path items are normally identified by a comment in the Attributes field (Col_swatch_1)

The information in the template is replaced by the information coming from FileMaker and the existing swatches are re-coloured based on the appropriate colour (this CMYK breakdown has already been looked up in a relational db in FMP). This seemed a lot easier than defining new swatches.

Originally, at the end of the script, a do Action (Delete unused palette items) deletes unused swatches from the palette. A bug in Illustrator prevents the new swatch names from displaying until the palette is refreshed in some way. Therefore I have added a step to the Action which sorts the swatch palette by name. Now all the Col 1 etc swatches display correctly.

The problem is having given this to our production team, people won’t necessarily have the action loaded, and it stalls the script (or leave it out and it doesn’t refresh the palette).

Cutting and pasting the new art also refreshes the swatches palette, but does not do away with unused swatches (and is a pretty clunky workaround). The term ‘Redraw’ doesn’t work.

Any clever ideas? Thanks in advance.

Ian

Ian:

I don’t have a refresh solution but since I script Illustrator (constantly it seems!) I will make a few suggestions.

  1. Avoid using Actions within Scripts whenever possible. Unless you enjoy having to install / update / maintain the Actions on all of your production machines. Also, they are a bit hardcoded for most tasks and pure scripting allows for flexibility. I’m not saying, “Never use them.”, just avoid them when you can.

  2. Instead of redefining the swatches, create them on the fly. Ideally your “template” will only have [Registration] with the balance of the colors being created as needed. This is a really trivial task and avoids the ‘refresh bug’ you’re experiencing.

  3. I tend to harp on this but one more time… whenever possible (and it almost always IS possible!) stay away from System Events to autoClick buttons / select menu items / etc. Make it a very, very last resort. (Not that you are using them, just keeping you from temptation :P)

Have fun,
Jim Neumann
BLUEFROG

Jim,

Thank you for your helpful advice. I had been using actions for various scripts, but it became apparent when the scripts are used by other people, them having the action is one extra thing to worry about!

I will revisit trying to generate the swatches one at a time as needed.

Regards

Ian

For CS1&2 you could edit the default files so you don’t have any colours except the ones you want to introduce. The files for this are located
Adobe Illustrator CS2/Plug-ins/Adobe Illustrator Startup_CMYK.ai
Adobe Illustrator CS2/Plug-ins/Adobe Illustrator Startup_RGB.ai
Run your action on these save and close.
You may need to quit and launch Illustrator.
Then you may not need a template either just create new doc on the fly.

Mark,

Thanks for your input. I figured out how to create swatches as required. I still need a ‘template’ file, as the rest of the legend (of which there are 3 different variants) contains a lot of information and various logos. It also runs a little quicker now, for some reason. The only problem I have now is I need to merge an existing colour into one of the newly created spots. The merge swatches menu item is not part of the Illustrator dictionary. I’ll have to dig a little deeper.

I’ll see if I can post some of the code tomorrow when I am back at work.

Thanks to all

Ian

Here is some of the code for your information: it is a little long winded, but I am still learning :slight_smile:

 try
	tell application "Adobe Illustrator" to set mydocslist to (get name of every document)
	repeat with i in mydocslist
		try
			set key_char to (characters 1 thru 20) of i as string
			if key_char is equal to "MASTER COLSEP LEGEND" then
				tell application "Adobe Illustrator"
					activate
					display dialog "Legend Template already open!" buttons {"Close"} default button {"Close"}
					close (every document whose name begins with "MASTER COLSEP LEGEND") without saving
				end tell
				tell application "FileMaker Pro" to activate
				exit repeat
			end if
		end try
	end repeat
end try
set y to 1
tell application "Adobe Illustrator"
	activate
	open col_leg
	repeat num_cols times
		tell current document
			set COLSWTCH to first path item whose note is "Col_Swatch_" & y
			tell application "FileMaker Pro"
				tell current record
					get cell ("Colour " & y)
					set Col_cell to ("PG " & the result)
					get cell ("Col " & y & " C")
					set ColC_cell to the result
					get cell ("Col " & y & " M")
					set ColM_cell to the result
					get cell ("Col " & y & " Y")
					set ColY_cell to the result
					get cell ("Col " & y & " K")
					set ColK_cell to the result
				end tell
			end tell
			try
				make new spot with properties {name:Col_cell, color:{class:CMYK color info, cyan:(ColC_cell), magenta:(ColM_cell), yellow:(ColY_cell), black:(ColK_cell)}, color type:spot color, class:spot}
			on error
				display dialog "Colour not in Library" with icon caution giving up after 2
				set color type of spot Col_cell to spot color
				set name of swatch (Col_cell) to ((Col_cell) & " X")
			end try
			try
				set currSwatch to first swatch whose name is Col_cell
				set myNewColor to color of currSwatch
				set fill color of COLSWTCH to myNewColor
			on error
				set currSwatch to first swatch whose name is (Col_cell & " X")
				set myNewColor to color of currSwatch
				set fill color of COLSWTCH to myNewColor
			end try
			set COLSWTCH_txt to (first text frame whose contents is ("Col " & y) as text) as reference
			set spot_name to (Col_cell) as text
			set contents of COLSWTCH_txt to spot_name
			tell application "FileMaker Pro"
				tell current record
					get cell ("dE " & y & " 1")
					set dE100_cell to the result
					if dE100_cell is equal to "" then
						set dE100_cell to "N/A"
					end if
					get cell ("dE " & y & " 5")
					set dE50_cell to the result
					if dE50_cell is equal to "" then
						set dE50_cell to "N/A"
					end if
				end tell
			end tell
			set deltaE_100 to (first text frame whose contents is "dE " & y & " 1") as reference
			set deltaE_50 to (first text frame whose contents is "dE " & y & " 5") as reference
			set LegRedSwatch to first swatch whose name is "Legend Red"
			set myColor to color of LegRedSwatch
			set contents of deltaE_100 to dE100_cell
			if dE100_cell is not "N/A" then
				if dE100_cell is greater than 2.5 then
					set fill color of every character of deltaE_100 to myColor
				end if
			end if
			set contents of deltaE_50 to dE50_cell
			if dE50_cell is not "N/A" then
				if dE50_cell is greater than 3.5 then
					set fill color of every character of deltaE_50 to myColor
				end if
			end if
			set y to y + 1
		end tell
	end repeat
	tell current document
		if num_cols is less than 8 then
			set count_times to (num_cols + 1)
			repeat (8 - num_cols) times
				set dlt_layer to first layer whose name is ("Layer Col " & count_times)
				delete dlt_layer
				set count_times to (count_times + 1)
			end repeat
		end if
		set PROJECT_NAME to (first text frame whose contents is "PROJECT NAME") as reference
		set PROJECT_NUMBER to (first text frame whose contents is "PROJECT NO") as reference
		set MANU_PLNT to (first text frame whose contents is "PLANT") as reference
		set NO_REF to (first text frame whose contents is "REF") as reference
		set TECH_DRAWG to (first text frame whose contents is "TECH DRAW") as reference
		set JOB_NUMBER to (first text frame whose contents is "JOB NUMBER") as reference
		try
			set contents of PROJECT_NAME to Proj_name
			set contents of PROJECT_NUMBER to Proj_numb
			set contents of MANU_PLNT to Manu_plant
			set contents of NO_REF to REF_numb
			set contents of TECH_DRAWG to tech_draw
			set contents of JOB_NUMBER to job_numb
		end try
		set w1 to (first text frame whose contents is Proj_name) as reference
		if width of w1 is greater than 100 then
			set width of w1 to 100
		end if
		set has selected artwork of (every layer) to true
		move selection to first layer whose name is "Gate (CAGT)"
		delete (every layer whose name contains "Col")
		set selection to false
		set xList to every swatch whose name contains ("X")
		if xList is not equal to {} then
			display dialog "Please colour up swatch(es) flagged with an 'X'... and enter dE values (if applicable)"
		else
			display dialog "...Done" buttons "OK" giving up after 2
		end if
	end tell
	redraw
end tell

what is really bothering me now is that set fill color only works with individual path items, so i cannot apply a new fill colour to a compound path or group item. Grrr

Ian