Lists and repeat loop. If n is a number, then n is not a number?

Hi all,

I have been thinking this over and over again. But just don’t get it.
A catalogue. 12 picture boxes on a page with 12 corresponding text boxes.
The user selects some of these 12 picture boxes and then selects a folder with the picture files.
This selection can be (for example) picture box “ThumbPic_07”, “ThumbPic_08” and “ThumbPic_09”.
Users selects three image files and the pics should be placed in the right place. Should be…

Since the list of the selection (SelectedBoxes) is not in the same order as theBoxList (alphabetical) I can’t use this list. So, my idea was to run a repeat loop, check if the item of the selectedBoxes is in theBoxList and then use this box to put the pic in.

Funny thing is (Mmmh… funny. Not.) The results returned are okay. If I change n to thecounter (which counts the pictures already placed) the script does work, but starts to put a pic in ThumbPic_01 instead of _07.
Even if I put a number instead of n, the script is not working.

Now what am I missing in this line?
set thebox to (item 1 of item n of theboxList)

You can find it at the bottom of the script. See also my comments overthere.

Great thanks in advance for those who help me out…
Kjeld

property theboxList : {¬
	{"ThumbPic_01", "ThumbSpec_01"}, ¬
	{"ThumbPic_02", "ThumbSpec_02"}, ¬
	{"ThumbPic_03", "ThumbSpec_03"}, ¬
	{"ThumbPic_04", "ThumbSpec_04"}, ¬
	{"ThumbPic_05", "ThumbSpec_05"}, ¬
	{"ThumbPic_06", "ThumbSpec_06"}, ¬
	{"ThumbPic_07", "ThumbSpec_07"}, ¬
	{"ThumbPic_08", "ThumbSpec_08"}, ¬
	{"ThumbPic_09", "ThumbSpec_09"}, ¬
	{"ThumbPic_10", "ThumbSpec_10"}, ¬
	{"ThumbPic_11", "ThumbSpec_11"}, ¬
	{"ThumbPic_12", "ThumbSpec_12"}}

global SelectedBoxes
global numPicBox
global folderList
global picList
global selPiclist
global thefolder

tell application "QuarkXPress Passport"
	tell document 1
		set SelectedBoxes to (name of every picture box of selection) as list
		set numPicBox to count of items in SelectedBoxes
	end tell
end tell

--Select number of images. Repeat when selected amount of images doesn't correspond with the amount of selected boxes.
set thefolder to (choose folder with prompt "Selecteer de map met afbeeldingen.")
set folderList to (list folder (thefolder as alias) without invisibles)
set theSel to false
repeat while theSel is false
	set picList to (choose from list folderList with prompt "Selecteer " & numPicBox & " afbeeldingen om te plaatsen." with multiple selections allowed)
	set selPiclist to count of items in picList
	if (count of items in picList) is greater than numPicBox then
		display dialog "Je hebt meer afbeeldingen dan het beschikbare aantal kaders geselecteerd." & return & "Selecteer maximaal " & numPicBox & " afbeeldingen."
	end if
	if (count of items in picList) is less than numPicBox then
		display dialog "Je hebt minder afbeeldingen dan het beschikbare aantal kaders geselecteerd." & return & "Selecteer maximaal " & numPicBox & " afbeeldingen."
	end if
	if selPiclist is equal to numPicBox then
		set theSel to true
	end if
end repeat

tell application "QuarkXPress Passport"
	tell document 1
		--try
		set theCounter to 1
		repeat with n from 1 to count theboxList --Repeat 12 times ('cause there are 12 pic boxes)
			--	try
			if (item 1 of item n of theboxList) is in SelectedBoxes then --Everytime when the name of one of the selected boxes is in the picture box list then.
				
				--The following line is causing the trouble. 
				--When replacing n with theCounter puts a picture in the boxes starting with box ThumbPic_01, 
				--while this should be 07 or 09 for example...
				--Also doesn't work when I replace n with 7 or 9.
				set thebox to (item 1 of item n of theboxList)
				tell picture box thebox
					set color to "magenta" -- Just to check if this part works. It does.
					--Put image in box.
					set theImage to (thefolder & (item theCounter of picList) as string)
					set image 1 to alias theImage
					--end try
				end tell
				set theCounter to theCounter + 1
			end if
			--	end try
		end repeat
		--end try
	end tell
end tell
{SelectedBoxes, n, thebox, picList, theImage}

Thanks for the quick response.
Nope. It’s not working. It doesn’t even get the picture box (although the results returned seem to be the same).

kjeld

Error message was something like can’t get/set this into blahblah. (Sorry, working on a Dutch system so the translation is probably not right).
However, I tried to reduce the script. Now I have one working (at least the basics) and one not.
The difference seems to be in the selectedBoxes, but the results returned are the same for both scripts.

This one works:

property theboxList : {¬
	{"ThumbPic_01", "ThumbSpec_01"}, ¬
	{"ThumbPic_02", "ThumbSpec_02"}, ¬
	{"ThumbPic_03", "ThumbSpec_03"}, ¬
	{"ThumbPic_04", "ThumbSpec_04"}, ¬
	{"ThumbPic_05", "ThumbSpec_05"}, ¬
	{"ThumbPic_06", "ThumbSpec_06"}, ¬
	{"ThumbPic_07", "ThumbSpec_07"}, ¬
	{"ThumbPic_08", "ThumbSpec_08"}, ¬
	{"ThumbPic_09", "ThumbSpec_09"}, ¬
	{"ThumbPic_10", "ThumbSpec_10"}, ¬
	{"ThumbPic_11", "ThumbSpec_11"}, ¬
	{"ThumbPic_12", "ThumbSpec_12"}}

set SelectedBoxes to {"ThumbPic_07", "ThumbPic_09"}
--set thebox to "ThumbPic_09"
set picList to {"AC.1.0395.074.eps", "AC.1.0395.075.eps"}
set thefolder to "PS 6.1:043074 NOG catalogus:043074 Scripts:Test afbeeldingen:Achterberg, Roel:Z-W Thumbs:"
--set n to 9

tell application "QuarkXPress Passport"
	tell document 1
		set theCounter to 1
		repeat with n from 1 to count theboxList
			if (item 1 of item n of theboxList) is in SelectedBoxes then
				set thebox to (item 1 of item n of theboxList)
				set theCounter to 1
				tell picture box thebox of current page
					--Put image in box.
					set theImage to ((item theCounter of picList) as string)
					set image 1 to alias ((thefolder & theImage) as string)
				end tell
				set theCounter to theCounter + 1
			end if
		end repeat
	end tell
end tell
{n, thebox, SelectedBoxes}

This one doesn’t:

property theboxList : {¬
	{"ThumbPic_01", "ThumbSpec_01"}, ¬
	{"ThumbPic_02", "ThumbSpec_02"}, ¬
	{"ThumbPic_03", "ThumbSpec_03"}, ¬
	{"ThumbPic_04", "ThumbSpec_04"}, ¬
	{"ThumbPic_05", "ThumbSpec_05"}, ¬
	{"ThumbPic_06", "ThumbSpec_06"}, ¬
	{"ThumbPic_07", "ThumbSpec_07"}, ¬
	{"ThumbPic_08", "ThumbSpec_08"}, ¬
	{"ThumbPic_09", "ThumbSpec_09"}, ¬
	{"ThumbPic_10", "ThumbSpec_10"}, ¬
	{"ThumbPic_11", "ThumbSpec_11"}, ¬
	{"ThumbPic_12", "ThumbSpec_12"}}

--set SelectedBoxes to {"ThumbPic_07", "ThumbPic_09"}
--set thebox to "ThumbPic_09"
set theCounter to 2
set picList to {"AC.1.0395.074.eps", "AC.1.0395.075.eps"}
set thefolder to "PS 6.1:043074 NOG catalogus:043074 Scripts:Test afbeeldingen:Achterberg, Roel:Z-W Thumbs:"
set n to 9

tell application "QuarkXPress Passport"
	tell document 1
		set SelectedBoxes to (name of every picture box in selection)
		set theCounter to 1
		repeat with n from 1 to count theboxList
			if (item 1 of item n of theboxList) is in SelectedBoxes then
				set thebox to (item 1 of item n of theboxList)
				tell picture box thebox of current page
					--Put image in box.
					set theImage to ((item theCounter of picList) as string)
					set image 1 to alias ((thefolder & theImage) as string)
				end tell
				set theCounter to theCounter + 1
			end if
		end repeat
	end tell
end tell
{n, thebox, SelectedBoxes}

Thanks for helping. I have tried again. No errors.
This is the event log for both of them, with your last line incorporated in the second script (same result if I put it in the first one). Everything seems to look fine, besides the fact that it takes twice the first picture.

tell application "QuarkXPress Passport"
	set image 1 of picture box "ThumbPic_07" of current page of document 1 to alias "PS 5.1:Users:kjeld:Desktop:043074 Scripts:Test:Achterberg Roel:Z-W Thumbs:AC.1.0395.074.eps" of picture box "ThumbPic_07" of current page of document 1
	set image 1 of picture box "ThumbPic_09" of current page of document 1 to alias "PS 5.1:Users:kjeld:Desktop:043074 Scripts:Test:Achterberg Roel:Z-W Thumbs:AC.1.0395.074.eps" of picture box "ThumbPic_09" of current page of document 1
end tell

Only thing which comes up in my mind now is that I downloaded the Output Enhancement xtension of Quark. This contains another script.xtn. Maybe this could be the troublemaker?
Unfortunately I don’t have the old extension at home. (If you have one, can you put it somewhere on line or mail me? Sent me a PM an I can give you my mail address).

Besides: I have tried on OS 10.3.9 and 10.4.3, Quark 6.5.

Thanks again,
kjeld

That did the trick Jacques! Thanks for helping me out.
Definitily glad that I can continue with the rest of the script now.

Whenever you’re around in Amsterdam I owe you a drink.

Kjeld