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

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

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.

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

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.

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

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.


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