I’d love to be able to say EverImageLocation(image1,image2,image3 …) and have a list of all those images returned, respecting Eggplant ordinality.
I’m constantly writing this code:
put EveryImageLocation(image1) into foo
put EveryImageLocation(image2) into bar
put Merge2ListWithEggplantOrdinality(foo,bar) into foobar
Where that last function basically iterates through all the items in each list and sorts them into one big list.
This happens a lot when I’m looking for a control that can either be enabled or disabled. I know that I want the 5th radio button that appears on the screen, but in order to figure out which one the 5th is, I need to find all the enabled and all disabled radio buttons, combine them, and grab the 5th one.
Of course, I can write a function that does this myself. I’m not sure why I havn’t done it yet … and I’m about to. But, none the less, it would be nice to have it built in
Well, if anyone else is dealing with this issue, here is a function to use. The part about building the base path is specific to my setup, but everything else is fairly general.
Basically it combines all the image locations into one list and does a sort that will sort by screen location according to eggplant (left to right, top to bottom).
This is unofficial! If any of the Redstone folks have a better way to accomplish this, maybe they can post it.
put () into finalList
-- Do a bit of work to build the base path
put the target's long name into fullPath
split fullPath with "Scripts"
put item 1 of fullPath & "Images/" & global VersionImgPath into fullPath
-- Find all the locations of each image passed in
repeat with each item of the parameterList
put EveryImageLocation(fullPath & it) &&& finalList into finalList
-- Sort the final list according to eggplant ordinality
if finalList is not empty then
sort finalList by (the second item of each,the first item of each)
This may do it for you:
put EveryImageLocation(image1) &&& \
EveryImageLocation(image2) into foobar
sort the items of foobar by (item 2 of each, item 1 of each)
The &&& operator joins two lists into one. The sort command sorts that list – by using (item 2 of each, item 1 of each) as the value to be sorted, the locations in the list will be sorted by their y (vertical) location (item 2) and within that row by their x location (item 1).
If you do this frequently, writing your own function to combine any lists that are passed to it and return the sorted list is a great idea.
Your function in reply to your own message hadn’t shown up when I composed my answer. Your function looks great – you obviously didn’t need our help!
You say the part about the base path is specific to your setup, but that will probably be helpful to anyone who wants to put this function in a helper suite (which would be a good place for it to go, along with any other general-purpose commands and functions).
If anyone else needs this functionality, just put Chris’s function in a script by the same name (AllImageLocations), drag that script’s suite into the Helpers tab of any suite where you need it, and then call it like this:
put AllImageLocations("image1", "image2", "image3") into locs