Author Topic: get current text frame  (Read 2600 times)

0 Members and 1 Guest are viewing this topic.

Offline sam452

  • Newbie
  • *
  • Posts: 21
  • Karma: 0
get current text frame
« on: December 26, 2007, 09:28:31 AM »
I'm beginning the task of adapting my QXP scripts to ID3 and have run into this basic problem. When you select text there's an inheritance that you also can acquire the reference to its containing box. I'm not seeing that in ID3 and need a strategy to address that.

In QXP, I would tag some text with a character style sheet called "counter" and since it was selected, rename the box.

Code: [Select]
tell application "QuarkXPress"
tell document 1
set textOBJ to object reference of selection
set character style of textOBJ to character spec "counter"

tell current box
set name to "legend"
end tell
end tell
end tell

Now I want to select text in ID3 the same way, run the script to name the text frame that contains the string the same way, but it's not aware of the text frame it's in.
Code: [Select]
tell application "Adobe InDesign CS3"
tell document 1
set textOBJ to object reference of selection
set applied character style of textOBJ to character style styleName
tell text frame 1
set label to "legend"
end tell --t frame 1
end tell --theDoc
end tell --the application

As you can see, it's not finding text frame 1 because I'm in text mode with the cursor. The examples I've seen begin by creating the text frame and then naming it. I already have the box I need.

As an aside, I'm going to use this labeled box for later production, thanx, sam

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: get current text frame
« Reply #1 on: January 21, 2008, 05:40:11 AM »
An InDesign text can run through multiple text frames. In your script currently 'tell text frame 1' is only for the document . Hence it will apply to the first text frame on the document regardless of what you have selected. The text object you have selected has a property of parent text frames. This is a list of all the text frames the text runs through. The following code will set the label on those text frames.

tell application "Adobe InDesign CS3"
   tell document 1
      set textOBJ to object reference of selection
      set applied character style of textOBJ to character style styleName
      set textFrameList to parent text frames of textOBJ
      repeat with theFrame in textFrameList
         tell theFrame
            set label to "legend"
         end tell
      end repeat
   end tell --theDoc
end tell --the application

If your text is not threaded through multiple frames this will wok for you. If you are threaded and you only want to set the first frae you just need to get the first item from the list.