Saturday, October 25, 2014

#1 2009-03-23 01:52:57 pm

sam452
Member
From: Nashville
Registered: 2006-12-28
Posts: 96

Indesign CS3: object reference of text

I'm  hoping this is simple. I know I can do a find what in Indesign to find a string and change it. But before I would do that I need to get its horizontal offset and baseline for another purpose.

Thus I want an object reference to a string. If I was in Quark I would get object reference of first text whose it="string" or something like that.

Looking at the Dictionary, I see text is contained by Story so I try that. But I guess my approach is bungled. My blind attempts yield errors. How would you get an object reference of a particular piece of text?

Applescript:


tell application "Adobe InDesign CS3"
   tell every story of document 1
       set a to object reference of first text whose contents = "[Signature 1]" ---> fails here
       set sig1x to horizontal offset of a
       set sig1y to baseline of a
   end tell
end tell

thanks for your time, sam


Filed under: adobe

Offline

 

#2 2009-03-23 03:35:18 pm

Matt-Boy
Member
Registered: 2005-10-21
Posts: 480

Re: Indesign CS3: object reference of text

I was able to get part way. Maybe this will get things rolling. I got it to the point where if you can identify the insertion point of that text, you can get the baseline and horizontal offset:

Applescript:

tell application "Adobe InDesign CS3"
   tell document 1
       set GetTextFirst to (parent story of (every text of (every text frame whose contents contains "[Signature 1]")))
       set sig1x to horizontal offset of (insertion point 20 of item 1 of GetTextFirst)
       set sig1y to baseline of (insertion point 20 of item 1 of GetTextFirst)
   end tell
end tell
{sig1x, sig1y}

Just not sure how to identify the insertion point of the text you are looking for.

For the record, I am also a former Quark scripter now working in InDesign and I usually end up using Find and Replace. The old Quark ways where you could replace "every text whose it is "blah"" in one line doesn't work that way in InDesign.

Hope this helps.

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)

Offline

 

#3 2009-03-23 03:59:16 pm

Jerome
Member
From: Ohio
Registered: 2003-06-13
Posts: 709
Website

Re: Indesign CS3: object reference of text

You could do something like this to get every word of every story whose contents is "[Signature" and work on it from there:

Applescript:

tell application "Adobe InDesign CS3"
   set a to object reference of (words of every story of document 1 whose contents is "[Signature")
   repeat with b in a
       set sig1x to horizontal offset of b
       set sig1y to baseline of b
   end repeat
end tell

I tried using first word in various ways and it seems to return the first story with the word, not the first word of every story.

If you just need the first instance of each you could do something like this:

Applescript:

tell application "Adobe InDesign CS3"
   tell document 1
       set a to (parent story of (every text of (every text frame whose contents contains "[Signature 1]")))
       set b to {}
       repeat with i from 1 to count of a
           set end of b to object reference of (first word of item i of a whose contents is "[Signature")
       end repeat
       repeat with c in b
           set sig1x to horizontal offset of c
           set sig1y to baseline of c
       end repeat
   end tell
end tell

Last edited by Jerome (2009-03-23 04:01:54 pm)


Filed under: adobe

Offline

 

#4 2009-03-23 06:49:05 pm

Marc Anthony
Member
From: Dallas, TX
Registered: 2006-04-27
Posts: 511

Re: Indesign CS3: object reference of text

Whose filtration isn't suited for obtaining references to strings (without clunky workarounds). A found text is a referenced object, hence its foundness.   big_smile

Applescript:

tell application "Adobe InDesign CS3"'s document 1 to set {sig1_HO, sig1_base} to (find text "[Signature 1]")'s item 1's {horizontal offset, baseline}


Filed under: adobe

Offline

 

#5 2009-03-23 08:19:28 pm

Jerome
Member
From: Ohio
Registered: 2003-06-13
Posts: 709
Website

Re: Indesign CS3: object reference of text

Marc Anthony wrote:

Whose filtration isn't suited for obtaining references to strings (without clunky workarounds). A found text is a referenced object, hence its foundness.   big_smile

Applescript:

tell application "Adobe InDesign CS3"'s document 1 to set {sig1_HO, sig1_base} to (find text "[Signature 1]")'s item 1's {horizontal offset, baseline}

getting the following error on testing: Adobe InDesign CS3 got an error: Object contains no text for find/change.


Filed under: adobe

Offline

 

#6 2009-03-23 09:39:59 pm

Marc Anthony
Member
From: Dallas, TX
Registered: 2006-04-27
Posts: 511

Re: Indesign CS3: object reference of text

Hey Jerome,

I typed some of that from memory, so it's possible that I mistyped or incorrectly prioritized something, but I won't have access to CS3 until tomorrow and can't check on that until then. One possible source for the error message is the fact that I didn't error trap; I should've reset the find/change values to nothing. You might want to go in there and manually check that there are no specific search options in affect.

Offline

 

#7 2009-03-24 05:39:56 am

Jerome
Member
From: Ohio
Registered: 2003-06-13
Posts: 709
Website

Re: Indesign CS3: object reference of text

No problem Mark, I was intrigued by what you wrote, I have never used this and it's nice to learn something new.

Offline

 

#8 2009-03-24 08:12:00 am

sam452
Member
From: Nashville
Registered: 2006-12-28
Posts: 96

Re: Indesign CS3: object reference of text

Thanks very much. This looks to be elegant.

I am able to get Marc's snippet to work. It yields {1.255652804298, 7.044191689896} which for the life of me, I cannot determine why Indesign yields this. You cannot see my test document but it's not near it at all and it's the only instance of this string.

My selection snippet yields a more accurate response:

Applescript:


tell application "Adobe InDesign CS3"
   set a to object reference of selection
   set q to {horizontal offset of a, baseline of a}
end tell

it yields the accurate response: {3.0, 3.875651041667}

But the above is not acceptable for automation.

What other info would be needed to help solve this discrepancy? Changing item 1 to 2 yields an expected error. There is no second instance of this string.

thanx, sam


Filed under: adobe

Offline

 

#9 2009-03-24 10:54:39 am

Matt-Boy
Member
Registered: 2005-10-21
Posts: 480

Re: Indesign CS3: object reference of text

I think that form used to work in CS2 but in CS3 you have to set all your find preferences up and then say "find text" to perform the find with the preferences you set up. This seems to work for me. You can change or delete the prefs that don't matter for what you are doing:

Applescript:

tell application "Adobe InDesign CS3"
   set find text preferences to nothing
   set case sensitive of find change text options to false
   set include footnotes of find change text options to false
   set include hidden layers of find change text options to false
   set include locked layers for find of find change text options to true
   set include locked stories for find of find change text options to true
   set include master pages of find change text options to false
   set whole word of find change text options to false
   set find what of find text preferences to "[Signature 1]"
   tell document 1
       set {sig1_HO, sig1_base} to (find text)'s item 1's {horizontal offset, baseline}
   end tell
end tell

{sig1_HO, sig1_base}

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)


Filed under: adobe

Offline

 

#10 2009-03-25 07:07:36 am

sam452
Member
From: Nashville
Registered: 2006-12-28
Posts: 96

Re: Indesign CS3: object reference of text

Yes, thanks to you all. I can confirm this works.

This thread is a keeper as I'm always trying to find strings as objects, thanx, sam

Offline

 

#11 2009-03-25 01:00:25 pm

Jerome
Member
From: Ohio
Registered: 2003-06-13
Posts: 709
Website

Re: Indesign CS3: object reference of text

I second that...Thanks Mark. I don't script much with text but this looks to open up new doors in manipulating text in InDesign.

Jerome

Offline

 

#12 2009-03-27 01:59:01 pm

sam452
Member
From: Nashville
Registered: 2006-12-28
Posts: 96

Re: Indesign CS3: object reference of text

Thanks again. I'm trying to extract more info from the object such as what page/spread it is on and what is its text insertion, or character numbers.

My first attempt was to add its object reference as string, but AS bails because it cannot convert "text from character 1235 to character ..." as string. I thought I could set the beginning of  the text insertion to "word 4  of (object reference as string)"
The parent of the text flow is the document which jumps past the insertion point. As you'll see below, I was trying to use the tell me structure to disassociate it from within its tell structure as the text that makes up the object reference still means "[signature 1]" which has no word 4.

Applescript:


tell application "Adobe InDesign CS3"
   set {find text preferences's find what, find change text options} to {"[Signature 1]", nothing}
   tell document 1 to set {sig1_HO, sig1_base, sig1_textPar, textObjchar} to (find text)'s item 1's {horizontal offset, baseline, parent, object reference}
   set sig1Textframe to parent of textObjchar
   (*
tell me
       set sigChar1 to word 4 of (textObjchar as text) --as integer --word four is "1235"
   end tell
*)

   
end tell

I'm looking through the dictionary and other online guides but their examples fail. I know page/spread is not a property of the text, but I'm trying to move up the parent chain to get to it.

I'm wanting to place an inline graphic above the [Signature 1].

I wouldn't think that all of this is out of scope for the ojbect reference, but I'm not seeing how to glean extra info from it. Thanks for your time, sam

Offline

 

#13 2009-03-27 04:01:00 pm

Jerome
Member
From: Ohio
Registered: 2003-06-13
Posts: 709
Website

Re: Indesign CS3: object reference of text

What you need is the parent (the object reference of the page) of the parent text frames (returned as a list, so you will need item 1 of this). I checked this with a document of 2 pages with a text frame on each that were linked. The returned result is the page that the text is on and not the first one in the frame. You might need to add a loop to make sure that you have the page object by checking it's class. If you need the page number get the name of the parent of (...) If you need the offset in the document use the document offset of the parent of (...)

Applescript:

tell application "Adobe InDesign CS3"
   set {find text preferences's find what, find change text options} to {"[Signature 1]", nothing}
   tell document 1 to set {sig1_HO, sig1_base, sig1_textPar, textObjchar} to (find text)'s item 1's {horizontal offset, baseline, parent, object reference}
   set sig1Textframe to parent of (item 1 of parent text frames) of textObjchar
   (*
tell me
       set sigChar1 to word 4 of (textObjchar as text) --as integer --word four is "1235"
   end tell
*)

   
end tell


Filed under: adobe

Offline

 

#14 2009-03-30 08:40:44 am

sam452
Member
From: Nashville
Registered: 2006-12-28
Posts: 96

Re: Indesign CS3: object reference of text

Many thanks, that takes care of extracting the page number of this object.

Now, I'm trying to extract the text insertion point, or the first character of the "text from character 1245 to character ...."

If I can get it as a string, then I can get "word 4 of object reference as string" to get the placement needed for an insertion point of the inline graphic. Object reference as string yields not "text from character ..." but "[Signature 1]" back. I've played around with options to get this from the object reference itself, but they're failing.

How would you get "1245" from the object reference? many thanx for all help so far, sam

Offline

 

#15 2009-03-30 01:39:24 pm

sam452
Member
From: Nashville
Registered: 2006-12-28
Posts: 96

Re: Indesign CS3: object reference of text

As usual, I was overthinking it.  It came to me a few hours later:

Applescript:


tell application "Adobe InDesign CS3"
   set {find text preferences's find what, find change text options} to {"[Signature 1]", nothing}
   tell document 1 to set {sig1_HO, sig1_base, sig1_textPar, textObjchar} to (find text)'s item 1's {horizontal offset, baseline, parent, object reference}
   set sig1Textframe to parent of (item 1 of parent text frames) of textObjchar
tell beginning of textObjchar to place "path:to:sig.tif" as alias    
end tell

Now, the trick is to find a way to refer to this new graphic rectangle so I can apply some attributes to it. Adding "with properties {…}" didn't cut it. Thanks, sam


Filed under: adobe

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.044 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)