I have a script that that Im playing with at the moment to find/reveal in the GUI a layer or layer set by name search. My questions are if repeat loop contains sub-routine can the sub-route exit the loop. Also if i want to repeat until something is true can the sub-routine return this aswell. This is more of an experiment into sub-routines than anthing else. I can get this to mine down to the 5th level of layer set but don't know how to call out of the repeat if the search is found.
001 tell application "Adobe Photoshop CS2"
002 activate
003 set docRef to the current document
004 tell docRef
005 set Q1 to display dialog "What is the name of the layer" & return & "or layer set you want to find?" & return ¬
006 & "*Note this is NOT case sensitive…" default answer "" with icon note
007 set mySearch to (text returned of Q1) as string
008 set found to false
009 -- repeat until found is true
010 repeat with i from 1 to count of layers
011 my findLIS(docRef, i, mySearch, found)
012 -- set found to the result
013 end repeat
014 -- end repeat
015 end tell
016 end tell
017 --
018 on findLIS(docRef, i, mySearch, found)
019 tell application "Adobe Photoshop CS2"
020 tell docRef
021 try
022 if exists layer set mySearch of layer i then
023 set current layer to the first layer of layer set mySearch of layer i
024 set current layer to layer set mySearch of layer i
025 set found to true
026 exit repeat
027 -- return true as text
028 else if exists layer mySearch of layer i then
029 set current layer to layer mySearch of layer i
030 set found to true
031 exit repeat
032 -- return true as text
033 else if exists layer set of layer i then
034 repeat with j from 1 to (count of layer sets)
035 set SOS1 to name of layer set j of layer i as string
036 my findSOS1(docRef, i, mySearch, SOS1, found)
037 end repeat
038 return false as text
039 end if
040 end try
041 end tell
042 end tell
043 end findLIS
The additional sub-routines are pretty much the same thing just including each sucessive layer set level. Hope I kind of made sence.