ID cs3: Ungroup a group, and then group it back

I’m trying to do more work on my little project which goes to each each of a document, gets all the text style ranges within each text frame on an arbitrary layer for data that is saved later.
http://bbs.macscripter.net/viewtopic.php?id=24831

It works pretty well, except when said text frames are grouped. It doesn’t see them, like you could in Quark.

Digging around on this site and elsewhere, I’m finding that you can get the class of every page item to see if it’s a group.

It keeps failing, and digging through the properties I’m seeing perhaps the problem is that each group is referencing the spread itself:

My goal is to find each group of items on one layer on each page, ungroup it, take down its object references as a list of lists and continue on my merry way. Before leaving that page, I would work that list of lists to reconstitute each group and move on.

Ideally, I wouldn’t have to do this. Just iterate on each text frame regardless whether it’s grouped or not. Appears not to be.

It seems that the only way to attack it is by doing every page item at once. But even then, I’m not finding a way to address specific groups.

Is this sounding right, or have I got it wrong? thanx, sam

sam,

You would have to have two passes in your item detection, one for ungrouped and another for grouped items. You can get a list of the latter using my example:

tell the active document to set GroupList to layer "Layer Name"'s groups

You’ll face a hurdle with your method, in that groups only exist when they are grouped. Breaking them apart is easy, but, once released, you’ll have to find a way to differentiate what was part of the group from the items that weren’t. You don’t actually have to ungroup frames to operate on their text. I suggest the alternative of working with stories. Unlike frames, stories remain targetable, even when grouped.

Thanks for replying. I was pulled off this project and now must work on it.

Stories are targetable, you say? That sounds like an answer, but I’m having trouble finding its object reference. I need to do this because this string shows up on each page and it must find it on each page independently and update it.


tell application "Adobe InDesign CS3"
	tell spread 1 of document 1
		--set hw1 to parent story whose contents = "Round #:    Date: " << failed
		set hw1 to a reference to (first text whose contents = "Round #:    Date: ") 
--<< returns "text 1 of "" which is not an absolute object reference.
		tell parent story of hw1
			set hw2 to object reference of text whose contents = "Round #:    Date: " 
--<<failed here
		end tell --parent
		--set hw2 to object reference of parent story of hw1 <<failed
		--set contents of hw1 to "Bob" <<ultimately what I want to do
	end tell --s1
end tell

I want to find hw2 on each page and change its contents at will. As you’ll note earlier, the text frame is in a group, so I’m attacking the stories. appreciate any help, sam

If I understand correctly you just need to use ID’s built in Find/Chance features, it looks like Find/Change text should work for your needs. This should get you started, it will find text in groups and inline text boxes on every page of the document. Right now it places the current date as returned by AppleScript after "Date: " in every text box.

set TheDate to (current date) as string
tell application "Adobe InDesign CS3"
	set OldFind to find what of find text preferences
	set find what of find text preferences to "Round #: Date:"
	set theTextObjects to find text document 1
	repeat with aTextObject in theTextObjects
		copy TheDate to end of contents of aTextObject
	end repeat
	set find what of find text preferences to OldFind
end tell

Thank you for replying. I see why you would come to that conclusion. I try not to overwhelm my posts with every bit of info because it puts would-be helpers off.

I need an object reference, because I’m going to get an integer, in this case the round number, from each page in this position and make a decision/dialog with it.

I need to be able to do it just on each independent page, so I’m thinking an absolute reference is needed. It strikes me that it’s less efficient to do all the prep to do a find of the round number just on a single page only. In my research on find change works on a selection or the entire document, not a targeted page?

I know that an absolute reference is possible, I’m not able to find a specific story to do so. Thanks for your suggestion, sam

The above gives you the object reference of the items, then you just need to step through the list and find the page that it is on. Something like this should work:

tell application "Adobe InDesign CS3"
	set OldFind to find what of find text preferences
	set find what of find text preferences to "Round #: Date:"
	set theTextObjects to find text document 1
	repeat with aTextObject in theTextObjects
		set theFrame to item 1 of text containers of parent story of aTextObject -- a list is returned, assuming that these are not linked text frames then you will have a list with a single item which will be the text frame containing the text returned from your search.
		set thePage to 0
		repeat while thePage = 0
			if class of parent of theFrame is page then -- make sure the parent of the text frame is a page
				set thePage to name of parent of theFrame --this is the page number
			else
				set theFrame to parent of theFrame
			end if
		end repeat
		--Do stuff to the text here using the page number returned above and the object reference stored in aTextObject
	end repeat
	set find what of find text preferences to OldFind
end tell

Of course there are other ways to do this as well. This should give you the text frames in groups, more basic than you probably need but should show you the direction:

tell application "Adobe InDesign CS3"
	set TextFrames to every text frame of every group of page 1 of document 1
	set TheText to text of item 1 of TextFrames
	--test to see if text matches and do what you need to it here
end tell