Adobe Illustrator CS5: set selection to every item in a given region

Hello All,
I have been digging through the MacScripter site for a few weeks now, and have found it a great tool for learning AppleScript. The community is great here, thanks for all the help already. :smiley:

Before I begin with my problem, let me guide you to some files that may help with the solution.
https://www.dropbox.com/sh/8sxqwykpeo5f4rr/PleyQ3OTof

This should show 6 files total. 3 saved as selection sample1, and 3 saved as selection sample2. There’s an .ai (Adobe Illustrator) file of each, a jpg, and a smaller jpg showing the layer and text frame breakdown of both ai files.

So, I’m trying to find out how to get AppleScript to set a selection to a particular region of my art board in Illustrator CS5. If you look at the files I linked via dropbox, I need to delete the 2 text frames towards the bottom right of the art board. Where it gets tricky (at least for me) is that this needs to be done in multiple files, and the position/control bounds/visible bounds of each text frame may vary slightly. Also, the names of each text frame may differ from file to file, so I can’t select a text frame by it’s name. This is why I need to select every text frame that falls within a certian ā€˜region’ of the art board. At least, that’s all I can think of at this point.

I know you can set selection to text frames in an EXACT position, with EXACT control bounds, or using EXACT visible bounds. EXAMPLE:

tell application "Adobe Illustrator"
	tell current document
		set selection to every text frame whose position is equal to {478.5, 80.6767578125}
	end tell
end tell

tell application "Adobe Illustrator"
	tell current document
		set selection to every text frame whose control bounds is equal to {472.5, 87.6865234375, 542.5, 11.4189453125}
	end tell
end tell

tell application "Adobe Illustrator"
	tell current document
		set selection to every text frame whose visible bounds is equal to {478.5, 81.6865234375, 541.5, 12.4189453125}
	end tell
end tell


If you run any of those 3 scripts on either of the .ai docs in the dropbox link, it works on the 1st sample doc, but not the 2nd doc. The closest I can think of to what I need (but doesn’t work :/) is:

tell application "Adobe Illustrator"
	tell current document
		set selection to every text frame whose visible bounds is contained by {478.5, 81.6865234375, 541.5, 12.4189453125}
	end tell
end tell

What I am trying to do in the last section of AppleScript I listed, is select everything within the bounds of certian coordinates, rather than select everything that is EQUAL to the coordinates. I think part of my problem is that ā€œis contained byā€ is used to find a file in a folder. I don’t know what else to use, if there is anything. Any help is appreciated, and thanks in advance!

Well to my knowledge NO you can’t supply use a who’s filter and an array of bounds. You will need to iterate the text frames and find the ones that fall within your area.

The sometimes possible way to do this in AI is create a new artboard using given bounds array and then select the items on the artbaord. loop selection removing text frames remove temp artboard.?

Hi. The concept of being contained within requires a four-sided bounds evaluation. Complex whose clauses are also frequently problematic in AI because of how it references items. You could use a whose without a repeat loop in InDesign, but this works for me in AI CS:

tell application "Illustrator CS"'s document 1
	set theBounds to {472.5, 87.6865234375, 542.5, 11.4189453125}
	repeat with index from (count text frames) to 1 by -1
		tell text frame index to if (geometric bounds's item 1 as number ≄ theBounds's item 1 ¬
			and geometric bounds's item 2 as number ≤ theBounds's item 2 ¬
			and geometric bounds's item 3 as number ≤ theBounds's item 3 ¬
			and geometric bounds's item 4 as number ≄ theBounds's item 4) then delete
	end repeat
end tell

Thanks Mark and Marc for your replies and considerations.

I was messing around with the artboard idea, but I Couldn’t figure out how to name an artboard when I created it using the ā€œwith properties:ā€ code. I kept getting an error ā€œCouldn’t get current documentā€ when I tried to apply a name to the new artboard I created.

This seems to be working great for my pruposes. I just cleaned up my numbers a little bit. Thanks for the sample code. I’ve been racking my brain so much on a straight forward way to accomplish this task, that I wasn’t considering using the greater / less than comparisons for each bound individually.
Here’s my code

tell application "Adobe Illustrator"
	tell current document
		set theBounds to {472.5, 92.0, 612.0, 0.0}
		repeat with index from (count text frames) to 1 by -1
			tell text frame index to if (geometric bounds's item 1 as number ≄ theBounds's item 1 ¬
				and geometric bounds's item 2 as number ≤ theBounds's item 2 ¬
				and geometric bounds's item 3 as number ≤ theBounds's item 3 ¬
				and geometric bounds's item 4 as number ≄ theBounds's item 4) then delete
		end repeat
	end tell
end tell

Thanks again to the both of you for all the help! When I’m done with my full script, I’ll see what about posting it on the forum :smiley: