Problem referencing text objects in Illustrator CS2

Hello,
I’m having some fun trying to select just the text in an Illustrator CS2 doc using Applescript. When there is no text in the graphic and I run my script, I get all the postscript text info describing all the objects, etc in the doc. I don’t want this. I want the result to be empty if there is no text in the graphic. Below is the Illustrator script part of my larger script that selects all the text. I’m using UI scripting to select the text and it works fine if there is actually one or more text objects in my graphic. But if it’s just a graphic, no text, I end up with the postscript description of the objects. Don’t know why.

I tried looking into referencing just the text objects on the current layer in the current doc but can’t seem to figure out the correct reference based on Adobe’s Applescripting pdf reference for Illustrator.

Anyone know how to reference text objects in illustrator or point me in the right direction?

Tx

Keith

============================
… else if AIfile_name is not “” then --DBASE, PRINT AND BACKUP AI DOC
tell application “Adobe Illustrator”
activate
tell application “System Events”
click menu item “Save” of menu 1 of menu bar item “File” of menu bar 1 of application process “Adobe Illustrator”
click menu item “Text Objects” of menu 1 of menu item “Object” of menu 1 of menu bar item “Select” of menu bar 1 of application process “Adobe Illustrator”
end tell
copy
set the_text to the clipboard
print document AIfile_name
close current document saving no
end tell

Model: G5
Browser: Safari 417.9.3
Operating System: Mac OS X (10.4)

Hi
Not exactly sure if this is what you want but try this

tell application "Illustrator CS"
	activate
	set thisDoc to current document
	set theTexts to every text frame of thisDoc
	set selection to theTexts 
end tell

Hi,
your script part worked great thanks! I never find the simple way. ;-0

What I’m doing with the illustrator graphics is that I’m dbasing them in a Filemaker Pro dbase where I extract all the text of the graphic and place it in an extract text field, get the open Illustrator doc name, place it in a text field and then copy and paste the graphic into a container field. What happens when I have no text in the graphic though is that the entire postscript description of the graphic is placed in the extract text field. Wonder what’s going on there? Hmmm…

Keith

Hi pidge,
This works very well, but I am stuck when a layer is hidden or a layer has hidden objects. Obviously I don’t want either to be part of the selection. I just want to bypass those hidden layers or objects. Can you help me out?

Thanks,
Jeff

Hi jeff

I’m struggling a little bit with the hidden layers bit it doesn;t seem to be playing nice with my mac.
However this little snippet should cover you where the text items themselves are just hidden.

tell application "Adobe Illustrator"
	activate
	set thisDoc to current document
	set theTexts to ((every text frame of thisDoc) whose hidden is false)
	set selection to theTexts
end tell

i’ll keep having a crack at the hidden layer problem :confused:

Hi jeff

I think this should get the text ignoring the hidden layers for you.

tell application "Adobe Illustrator"
	activate
	set thisDoc to current document
	set t to get container of every text frame of thisDoc
	repeat with i in t
		delay 2
		if visible of i is true then
			set selection to every text frame of i
		end if
	end repeat
end tell

it obviously uses a repeat loop so you have to reiterate thru the text to select it rather than selecting it all at once!
i put a delay in just so i could see it select the text one after another. you can remove it!

Hi Pidge,
This works very well, except I seem to run into a problem with group items. Illustrator can’t get visible of a text frame that is within a group item.

So for example, this snippet will work for text within a group. I know my question may appear very remedial to you. but how can I combine your code snippet with the snippet below? If you don’t have the time to look, it is perfectly fine. I am very content with what I have. The group issue is very minimal.

Thanks,
Jeff

tell application "Illustrator CS"
	activate
	set thisDoc to current document
	try
		set tg to get container of every group item of thisDoc
		repeat with i in tg
			delay 1
			if visible of i is true then
				set selection to every text frame of every group item of i
			end if
		end repeat
	end try
end tell

Hi Jeff

it is a little bit awkward this i think.
the hidden doesn’t like it when layers are switched off and the layers
don’t like hidden items :confused:

the only way i can think of doing this (and it might not be right for your needs) is
switch all layers on! before the script is run do what you need to do then switch them back off again.
its not perfect by any means, but should work.

i also tried deleting the switched off layers and may have inadvertently found a bug, basically illustrator crashes.

group items are only an issue because there on the layer thats switched off if you run this on a doc with all layers switched on and the text in a group it still
picks up the text.

tell application "Adobe Illustrator"
	set selection to every text frame of document 1 whose hidden is false
end tell

Hi Pidge,
I will be honest with you. It actually makes more sense to do the “unhide then rehide” approach. So I am very pleased with everything the way it now stands.

The intent was to hide a font from being detected by InDesign’s Preflight check when it sees placed .ai files. Don’t even ask why we would want such a behavior. we use some bizarre logic at times (which is out of my hands). Although, outlining the fonts does provide other good proactive safety measures, i.e., it prevents placed Illustrator artwork from having an excessive stroke cropped, because it may have exceeded the artwork’s bounding box. That’s an issue that has been around for quite some time. So in conclusion, it is good that the script is outlining text even for layers not yet visible. Because in theory they may be visible in the future if an operator decides to unhide the layer.

Great work with all of this. Thank you very much.
-Jeff