Sunday, October 17, 2021

#1 2021-09-18 10:46:05 am

Jeffkr
Member
Registered: 2005-11-05
Posts: 486

InDesign Change Point Size of Text - Group Issue

Hello all,
I am struggling to figure out a solution to change all character's point size that fall within a range to become a new size.

For example, I want to change all characters that contain a point size greater than 9.5 and less than 10.5 - (or all characters that are 10 points) to become 11.

The script snippet here works fine when dealing with a simple selection that only contains a few text frames. But it will not work when the selection contains a group and subgroups.

I was hoping somebody knew of a way to drill down to al the characters within a selection regardless if the selection contains a mixture of text frames & groups, or groups within groups, etc.

Any help with this would be Hugely appreciated.

Thanks,
-Jeff

Applescript:

set minFontSize to 9.5
set maxFontSize to 10.5
set theStartSize to 10
set theEndSize to 11

if selection is not {} then
   tell application id "com.adobe.InDesign"
       activate
       tell document 1
           try
               set myChars to (every character of selection whose point size is greater than minFontSize and point size is less than maxFontSize)
           end try
           try
               set (point size of every character of selection whose point size is greater than minFontSize and point size is less than maxFontSize) to theEndSize
           end try
           try
               set (point size of every character of anItem whose point size is equal to theStartSize) to theEndSize
           end try
       end tell
   end tell
end if

set myChars to myChars as string
set myCount to (count of characters of myChars) as string
display dialog myCount & " total characters changed to 11 points" as string

Offline

 

#2 2021-09-18 11:52:06 am

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

Re: InDesign Change Point Size of Text - Group Issue

Hi. I think this should do what you're asking, but I can't anticipate changes that may have been made in your unknown version.

Applescript:

tell application "Adobe InDesign CS3"'s document 1
   set (selection's text frames's parent story's characters whose point size > 9.5 and point size < 10.5)'s point size to 11
end tell

Offline

 

#3 2021-09-18 03:18:06 pm

Jeffkr
Member
Registered: 2005-11-05
Posts: 486

Re: InDesign Change Point Size of Text - Group Issue

Hi Marc,
You have been helping me out for so many years, and I can't thank you enough! What you provided appears to work very well for when the selection only contains a group or multiple groups. where it will fail is when the selection contains a mixture of isolated text frames as well as groups that contain text frames. For those situations, only the group items that contain text frames will have their character's point size changed. The isolated text frame's characters that were also part of the selection do not get re-sized (unfortunately).


Below is my modified script, that appears to work in most instances. What it will do is end with repeating through all the selection items and just target the isolated text frames.

But this still will not address a situation where there is group of text frames that is then grouped to another set of text frames, i.e., a group inside a group. In that situation no character sizes get changed in my script below.


Applescript:

set minFontSize to 9.5 as integer
set maxFontSize to 10.5 as integer
set theStartSize to 10 as integer
set theEndSize to 11 as integer


if selection is not {} then
   tell application "Adobe InDesign CC 2017"'s document 1
       activate
       try
           set (selection's text frames's parent story's characters whose point size > minFontSize and point size < maxFontSize)'s point size to theEndSize
       end try
       try
           set (selection's text frames's parent story's characters whose point size = theStartSize)'s point size to theEndSize
       end try
       repeat with i from 1 to count of items in selection
           set myClass to class of item i of selection
           if myClass is text frame then
               try
                   set (every character of item i of selection whose point size > minFontSize and point size < maxFontSize)'s point size to theEndSize
               end try
               try
                   set (every character of item i of selection whose point size = theStartSize)'s point size to theEndSize
               end try
           end if
       end repeat
   end tell
end if

Last edited by Jeffkr (2021-09-18 03:42:49 pm)

Offline

 

#4 2021-09-18 04:55:58 pm

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

Re: InDesign Change Point Size of Text - Group Issue

You're welcome. If a selection is used, you could iterate through its 'all page items,' which returns a deeper structure than just 'page items.' I would probably target the stories, where it won't matter how deeply anything is grouped, because they're higher in the hierarchy.

Applescript:


tell application "Adobe InDesign CS3"'s document 1
   set (stories's characters whose point size > 9.5 and point size < 10.5)'s point size to 11    
end tell

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)