7 Replies Latest reply on Jun 12, 2008 6:57 PM by sstanleyau

    Need point size for a searched item in InDesign using Applescript

      Hello -

      Newbie to forum, I have Code that worked in old Indesign, But in Cs3 I cannot get the point size from text that I search for in a text frame. How do I get the point size for the first word returned from a text search in a text frame? I am referencing the text frame for the story search, but when I set a variable to the search result to find the first word, it says that it cannot reference the insertion points.

      in Other Words, Can you save search results from a text frame search in a variable or array, and then get the point size from the first word in that variable or array? I am at a loss here

      Any Help Appreciated.

      Mario
        • 1. Re: Need point size for a searched item in InDesign using Applescript
          sstanleyau Level 4
          On 3/6/08 10:10 AM, "Mario Ascoli" <member@adobeforums.com> wrote:<br /><br />> Can you save search results from a text frame search in a variable or array,<br />> and then get the point size from the first word in that variable or array?<br /><br />Yes. Post some of your code...<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
          • 2. Re: Need point size for a searched item in InDesign using Applescript
            Level 1
            Thanks Shane

            am trying to get the previous point size by searching for a character style in a text frame that the user selected. Then I take that old size and add or subtract it to get a new size.

            Any help would be appreciated

            Here is my code:

            --Create a complete character style
            display dialog "Enter a font Size" buttons {"Increase Size", "Decrease Size", "Cancel"} default button "Increase Size"
            set whichButton to (button returned of result)
            if whichButton = "Increase Size" then
            set fontSize to 1 as real
            else if whichButton = "Decrease Size" then
            set fontSize to -1 as real
            end if
            tell application "Adobe InDesign CS3"
            --Clear the existing find text preferences
            -- set find text preferences to nothing

            --Clear the existing change text preferences
            -- set change text preferences to nothing
            set mySelection to selection
            if (count mySelection) > 0 then
            if class of item 1 of mySelection is text frame then
            log mySelection
            set myStory to object reference of item 1 of selection
            try
            set applied character style of find text preferences to "Address"

            set myFoundWords to change text myStory
            set myAddress to item 1 of myFoundWords
            log myAddress
            set oldAddressSize to point size of myAddress
            log oldAddressSize
            set currentAppliedCharacterStyle to applied character style of myAddress
            log currentAppliedCharacterStyle
            end try

            try

            set myBounds to geometric bounds of myStory
            set {a, b, c, d} to myBounds
            set the geometric bounds of myStory to {a, b, c * 3, d}
            set applied character style of find text preferences to "Address"
            set newAddressSize to (fontSize + oldAddressSize)
            log newAddressSize
            set point size of change text preferences to newAddressSize

            change text myStory
            set the geometric bounds of myStory to {a, b, c, d}
            -- end tell
            end try

            try


            set applied character style of find text preferences to "Address Bold"
            set myFoundWords to change text myStory
            set myAddressBold to item 1 of myFoundWords

            set oldAddressBoldSize to point size of myAddressBold

            log oldAddressBoldSize
            end try

            try
            -- tell myStory

            set myBounds to geometric bounds of myStory
            set {a, b, c, d} to myBounds
            set the geometric bounds of myStory to {a, b, c * 3, d}
            set applied character style of find text preferences to "Address Bold"

            set point size of change text preferences to (fontSize + oldAddressBoldSize)
            set leading of change text preferences to (fontSize + oldAddressBoldSize) + 1

            change text myStory
            set the geometric bounds of myStory to {a, b, c, d}
            -- end tell
            end try

            else
            display dialog "Please select a text box" buttons {"Cancel"} default button "Cancel"

            end if
            else
            display dialog "Nothing is selected." buttons {"Cancel"} default button "Cancel"
            end if
            end tell

            -----------------
            I
            • 3. Re: Need point size for a searched item in InDesign using Applescript
              sstanleyau Level 4
              I'm still not clear on what you're after, but I think something like this is<br />it:<br /><br />set myFoundWords to change text myStory<br />repeat with i from 1 to count of myFoundWords<br />set oldAddressSize to point size of item i of myFoundWords<br />set point size of item i of myFoundWords to (oldAddressSize + fontSize)<br />end repeat<br /> <br /><br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
              • 4. Re: Need point size for a searched item in InDesign using Applescript
                Level 1
                Shane

                I tried the code you listed above and it separates the data into items, but I am only getting insertion points and not words.

                My goal is to select a text frame and search for a particular character type. Then select the first word or character in that search result and get its point size. Then I want to add one point size or subtract one point size from that result (old point size) for all the character styles that the previous search found. This used to work in CS1, but broke in CS3. The selected text frame is not allowing me to search the text correctly, but when I highlight the text in the text frame and search, it works correctly. Thanks for any help

                Mario
                • 5. Re: Need point size for a searched item in InDesign using Applescript
                  sstanleyau Level 4
                  On 12/6/08 7:46 AM, "Mario Ascoli" <member@adobeforums.com> wrote:<br /><br />> I tried the code you listed above and it separates the data into items, but I<br />> am only getting insertion points and not words.<br /><br />It should return ranges.<br />> <br />> My goal is to select a text frame and search for a particular character type.<br />> Then select the first word or character in that search result and get its<br />> point size.<br /><br />If you ask for the point size of a range, you get the value for the first<br />character of the range.<br /><br />> Then I want to add one point size or subtract one point size from<br />> that result (old point size) for all the character styles that the previous<br />> search found. <br /><br />So you want to change the point size of the styles?<br /><br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>
                  • 6. Re: Need point size for a searched item in InDesign using Applescript
                    Level 1
                    Shane,<br /><br />Thanks again for your help in this matter.<br /><br />I need to get the point size for an existing character style applied to a set of words. The words should be all the same point size. I then take that point size and add one or subtract one from it. I am using this so that the user does not have to figure out what the original point size is and they can add one higher or lower point size to that existing size. The code as it stands does not find the correct point size, and it also makes the text it has searched for disappear.<br /><br /> Could I send you a sample file so you could see where I am losing the logic for the code? I am stuck on this code for three weeks now. It worked in older version of indesign cs, but not in cs3<br /><br />Thanks,<br />Mario Ascoli <exoar69@yahoo.com>
                    • 7. Re: Need point size for a searched item in InDesign using Applescript
                      sstanleyau Level 4
                      Sure, send me the code, simplified if possible.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>