Problem with repeat dialog variable!!

Hi
I have a script which changes colors in an illustrator document sometimes its one color sometimes its several.
What happens however is this. it displays a dialog to find out how many colors will change so it can repeat through.
say for instance its 2 colors it lets me input the info for both colors but only converts the last one i input.
i don’t know how to store the information i get through the first loop so when it loops the second time it doesn’t overwrite it.
heres my script so far.

set the_SD_file to choose file with prompt "Pick some Superdrug Files" with multiple selections allowed
set the_amount to display dialog "How many colors are we converting Today" default answer "1" buttons {"cancel", "convert colors"} default button 2 ¬
	with title "Superdrug Script"
set the_number_of_colors to text returned of result
repeat with i from 1 to the_number_of_colors
	set spot_color_name to display dialog "Enter the pantone color Dave:" default answer "P1505" with title "Creating the Color" --with icon 0
	set spot_color to text returned of spot_color_name
	set cyan_value to display dialog "Enter the Spot color's Cyan Value:" default answer "0" with title "cyan"
	set my_cyan to text returned of cyan_value as integer
	set Magenta_value to display dialog "Enter the Spot color's Magenta Value:" default answer "42" with title "magenta"
	set my_mag to text returned of Magenta_value as integer
	set yellow_value to display dialog "Enter the Spot color's Yellow Value:" default answer "77" with title "yellow"
	set my_yellow to text returned of yellow_value as integer
	set black_value to display dialog "Enter the Spot color's Black Value:" default answer "0" with title "black"
	set my_black to text returned of black_value as integer
end repeat
tell application "Illustrator CS"
	repeat with the_SD_file in the_SD_file
		open the_SD_file
		delete every swatch of current document
		if not (exists spot spot_color_name in current document) then
			make new spot at beginning of current document with properties ¬
				{name:spot_color, color type:{spot color}, color:{cyan:my_cyan, magenta:my_mag, yellow:my_yellow, black:my_black}}
		end if
		tell application "Illustrator CS"
			if (count text frames in document 1) > 0 then
				set textItemCount to count text frames in document 1
				repeat with i from 1 to textItemCount
					try
						set (fill color of every line of text frame i of document 1 ¬
							whose fill color = {class:CMYK color info, cyan:my_cyan, magenta:my_mag, yellow:my_yellow, black:my_black}) to {spot:spot spot_color of document 1, tint:50}
					end try
				end repeat
			end if
		end tell
		tell application "Illustrator CS"
			try
				--convert to paths (every text frame of document 1)
				set (fill color of every path item of document 1 whose fill color is {class:CMYK color info, cyan:my_cyan, magenta:my_mag, yellow:my_yellow, black:my_black}) ¬
					to {spot:spot spot_color of document 1, tint:100}
			end try
		end tell
		save current document as eps with options {class:EPS save options, compatibility:Illustrator 9, preview:color Macintosh, embed linked files:true, include document thumbnails:true, embed all fonts:true, CMYK PostScript:true, PostScript:level 2} with replacing
		close current document saving no
	end repeat
end tell

any help with this would be greatly appreciated
Cheers

Well, I’m going to take a stab at this, since I’ve seen no one else has! I haven’t done a tremendous amount of scripting, but I think that want you need here is similar to a problem that I had. I think that you need to make a list of records. Each record will contain the definitions for each color (Spot Name…CMYK, etc…) then the list will contain all the different colors that the user entered in your first repeat field. Hope that makes sense. I haven’t tested it, but here’s what I think you should need:

set the_SD_file to choose file with prompt "Pick some Superdrug Files" with multiple selections allowed
set the_amount to display dialog "How many colors are we converting Today" default answer "1" buttons {"cancel", "convert colors"} default button 2 ¬
	with title "Superdrug Script"
set the_number_of_colors to text returned of result
repeat with i from 1 to the_number_of_colors
	set spot_color_name to display dialog "Enter the pantone color Dave:" default answer "P1505" with title "Creating the Color" --with icon 0
	set spot_color to text returned of spot_color_name
	set cyan_value to display dialog "Enter the Spot color's Cyan Value:" default answer "0" with title "cyan"
	set my_cyan to text returned of cyan_value as integer
	set Magenta_value to display dialog "Enter the Spot color's Magenta Value:" default answer "42" with title "magenta"
	set my_mag to text returned of Magenta_value as integer
	set yellow_value to display dialog "Enter the Spot color's Yellow Value:" default answer "77" with title "yellow"
	set my_yellow to text returned of yellow_value as integer
	set black_value to display dialog "Enter the Spot color's Black Value:" default answer "0" with title "black"
	set my_black to text returned of black_value as integer
	--color_list is the list of records
	set end of color_list to {my_spot:spot_color, set_cyan:my_cyan, set_magenta:my_mag, set_yellow:my_yellow, set_black:my_black}
end repeat
tell application "Adobe Illustrator"
	repeat with the_SD_file in the_SD_file
		open the_SD_file
		delete every swatch of current document
		repeat with my_list in color_list --access each color in color_list
			if not (exists spot my_spot of my_list in current document) then
				make new spot at beginning of current document with properties ¬
					{name:my_spot of my_list, color type:{spot color}, color:{cyan:set_cyan of my_list, magenta:set_magenta of my_list, yellow:set_yellow of my_list, black:set_black of my_list}}
			end if
			tell application "Adobe Illustrator"
				if (count text frames in document 1) > 0 then
					set textItemCount to count text frames in document 1
					repeat with i from 1 to textItemCount
						try
							set (fill color of every line of text frame i of document 1 ¬
								whose fill color = {class:CMYK color info, cyan:set_cyan of my_list, magenta:set_magenta of my_list, yellow:set_yellow of my_list, black:set_black of my_list}) to {spot:spot spot_color of document 1, tint:50}
						end try
					end repeat
				end if
			end tell
			tell application "Adobe Illustrator"
				try
					--convert to paths (every text frame of document 1)
					set (fill color of every path item of document 1 whose fill color is {class:CMYK color info, cyan:set_cyan of my_list, magenta:set_magenta of my_list, yellow:set_yellow of my_list, black:set_black of my_list}) to {spot:spot spot_color of document 1, tint:100}
				end try
			end tell
		end repeat
		save current document as eps with options {class:EPS save options, compatibility:Illustrator 9, preview:color Macintosh, embed linked files:true, include document thumbnails:true, embed all fonts:true, CMYK PostScript:true, PostScript:level 2} with replacing
		close current document saving no
	end repeat
end tell

Hi Bc

I kinda understand what you mean, and think its a step in the right direction. Thanks. i am getting an error though when running your script saying color_list not defined.
think i’ve got a bit to go before it works properly.

cheers

I can’t say I understand entirely what the purpose of the script is, not being an Adobe Illustrator user myself. However, the reason it says “color_list not defined” is that you are attempting to copy the range of colors to the end of said variable without defining the empty list first. I.e. you need

set color_list to {}

before you can start copying lists of colors into it.

The following is a variation on the first half of your script. It’s not much shorter, but does make it easier to expand a user-interrogation more easily, and allows the user to exit the loop as and when, rather than define the number of colors at the outset. You might like to enclose the ‘as integer’ coercion in a try block, in case the user enters a non-numerical value.

set DialogList to {"Enter the pantone color Dave:", "Enter the Spot color's Cyan Value:", "Enter the Spot color's Magenta Value:", "Enter the Spot color's Yellow Value:", "Enter the Spot color's Black Value:"}
set DefaultList to {"P1505", 0, 42, 77, 0}
set TitleList to {"Creating the Color", "Cyan", "Magenta", "Yellow", "Black"}
set ButtonList to {{"OK"}, {"OK"}, {"OK"}, {"OK"}, {"Repeat", "Finished"}}
set ColourList to {}

repeat
	copy {} to end of ColourList
	repeat with i from 1 to count of DialogList
		set Entry to (display dialog (item i of DialogList) default answer (item i of DefaultList) with title (item i of TitleList) buttons (item i of ButtonList) default button (item 1 of (item i of ButtonList)))
		set ThisCol to text returned of Entry
		if i is not equal to 1 then set ThisCol to ThisCol as integer
		copy ThisCol to end of item -1 of ColourList
	end repeat
	if button returned of Entry = "Finished" then exit repeat
end repeat

hi pj

Thanks for your input, i know my script is probably a bit long winded i’m still learning this stuff.
Heres the reasons behind it.
we have between 200 and 1000 illustrator files that need converting from process to spot colors, that come in every week
sometimes its just one color sometimes several. i want the operator Dave! to be able to input the breakdown of the colors (cyan:0,magenta:42 etc…etc… then the script to run
and alter all colors with these values to there equivalent spot color, just not sure how to store the info if there is more than one color.
hope this makes it a little clearer

cheers

Hey Jacques

Fantastic!!! That is absolutely bang on…
I’ve got to say i was really struggling (it was nearly G5 out the window time!!)
I need to run a few more tests, But it pretty much worked first time!
then i’m gunna scrutinize this script to see where i was going wrong.

Thank you!

Yeah, I see a couple of mistakes that I made… but I’m glad to see that things worked out for you.

Here’s what i should have posted.

set the_SD_file to choose file with prompt "Pick some Superdrug Files" with multiple selections allowed
set the_amount to display dialog "How many colors are we converting Today" default answer "1" buttons {"cancel", "convert colors"} default button 2 ¬
	with title "Superdrug Script"
set the_number_of_colors to text returned of result
set color_list to {}
repeat with i from 1 to the_number_of_colors
	set spot_color_name to display dialog "Enter the pantone color Dave:" default answer "P1505" with title "Creating the Color" --with icon 0
	set spot_color to text returned of spot_color_name
	set cyan_value to display dialog "Enter the Spot color's Cyan Value:" default answer "0" with title "cyan"
	set my_cyan to text returned of cyan_value as integer
	set Magenta_value to display dialog "Enter the Spot color's Magenta Value:" default answer "42" with title "magenta"
	set my_mag to text returned of Magenta_value as integer
	set yellow_value to display dialog "Enter the Spot color's Yellow Value:" default answer "77" with title "yellow"
	set my_yellow to text returned of yellow_value as integer
	set black_value to display dialog "Enter the Spot color's Black Value:" default answer "0" with title "black"
	set my_black to text returned of black_value as integer
	--color_list is the list of records
	set end of color_list to {my_spot:spot_color, set_cyan:my_cyan, set_magenta:my_mag, set_yellow:my_yellow, set_black:my_black}
end repeat
tell application "Adobe Illustrator"
	repeat with the_SD_file in the_SD_file
		open the_SD_file
		delete every swatch of current document
		repeat with my_list in color_list --access each color in color_list
			if not (exists spot (my_spot of my_list) in current document) then
				make new spot at beginning of current document with properties ¬
					{name:my_spot of my_list, color type:{spot color}, color:{cyan:set_cyan of my_list, magenta:set_magenta of my_list, yellow:set_yellow of my_list, black:set_black of my_list}}
			end if
			tell application "Adobe Illustrator"
				if (count text frames in document 1) > 0 then
					set textItemCount to count text frames in document 1
					repeat with i from 1 to textItemCount
						try
							set (fill color of every line of text frame i of document 1 ¬
								whose fill color = {class:CMYK color info, cyan:set_cyan of my_list, magenta:set_magenta of my_list, yellow:set_yellow of my_list, black:set_black of my_list}) to {spot:spot spot_color of document 1, tint:50}
						end try
					end repeat
				end if
			end tell
			tell application "Adobe Illustrator"
				try
					--convert to paths (every text frame of document 1)
					set (fill color of every path item of document 1 whose fill color is {class:CMYK color info, cyan:set_cyan of my_list, magenta:set_magenta of my_list, yellow:set_yellow of my_list, black:set_black of my_list}) to {spot:spot spot_color of document 1, tint:100}
				end try
			end tell
		end repeat
		save current document as eps with options {class:EPS save options, compatibility:Illustrator 9, preview:color Macintosh, embed linked files:true, include document thumbnails:true, embed all fonts:true, CMYK PostScript:true, PostScript:level 2} with replacing
		close current document saving no
	end repeat
end tell

Hi Bc

Sorry to disappoint but it didn’t convert both colors when run.
it didn’t error though.

cheers

Maybe I miss understand the intent. When I run it on my machine, I can select two colors and then set the CMYK values, and it sets up two spots in Illustrator with the values that I entered. I’m using CS2 though… maybe that has something to do with it?

I know that the issue has been solved for you, but it’s just one of those challenges… you know? And I may run into a situation where I can use something like that.

Brian

Hi Bc
Your script did create 2 spots in my illustrtor doc, on the file i used i wanted 2 colors converting it only converted one of the colors to one of the spots though
the other was still out of process.

cheers