Help to tidy up!

Can anyone suggest how I would go about tidying up the AS below? It’s just to many lines for a relatively simple task!

I tried to use the ‘all page items’ command, but with text frames caught up in the mix, it errors!!!

Thanks in advance.

Jase


tell application "Adobe InDesign CS2"

tell document 1

try
			set RGB_ImagesInRectangles to images of rectangles whose space is "RGB"
		on error
			set RGB_ImagesInRectangles to {}
		end try
		try
			set RGB_ImagesInPolygons to images of polygons whose space is "RGB"
		on error
			set RGB_ImagesInPolygons to {}
		end try
		try
			set RGB_ImagesInRectanglesInGroups to images of (rectangles of all page items) whose space is "RGB"
		on error
			set RGB_ImagesInRectanglesInGroups to {}
		end try
		try
			set RGB_ImagesInPolygonsInGroups to images of (polygons of all page items) whose space is "RGB"
		on error
			set RGB_ImagesInPolygonsInGroups to {}
		end try
		
		try
			set RGB_EPSsInRectangles to EPSs of rectangles whose space is "RGB"
		on error
			set RGB_EPSsInRectangles to {}
		end try
		try
			set RGB_EPSSInPolygons to EPSs of polygons whose space is "RGB"
		on error
			set RGB_EPSSInPolygons to {}
		end try
		try
			set RGB_EPSsInRectanglesInGroups to EPSs of (rectangles of all page items) whose space is "RGB"
		on error
			set RGB_EPSsInRectanglesInGroups to {}
		end try
		try
			set RGB_EPSsInPolygonsInGroups to EPSs of (polygons of all page items) whose space is "RGB"
		on error
			set RGB_EPSsInPolygonsInGroups to {}
		end try
		
		set AllRGB_Pictures to RGB_ImagesInRectangles & RGB_ImagesInPolygons & RGB_ImagesInRectanglesInGroups & RGB_ImagesInPolygonsInGroups & RGB_EPSsInRectangles & RGB_EPSSInPolygons & RGB_EPSsInRectanglesInGroups & RGB_EPSsInPolygonsInGroups
		
		set QTY_AllRGB_Pictures to count of AllRGB_Pictures

end
end

This is just a shortening; I have no understanding as to if this is the best way to get what you are wanting.

set rgbImages to {}

tell application "Adobe InDesign CS2"
	tell document 1 to if it exists then
		tell rectangles to if it exists then set rgbImages to rgbImages & (images whose space is "RGB") & (EPSs whose space is "RGB")
		tell polygons to if it exists then set rgbImages to rgbImages & (images whose space is "RGB") & (EPSs whose space is "RGB")
		tell all page items
			tell rectangles to if it exists then set rgbImages to rgbImages & (images whose space is "RGB") & (EPSs whose space is "RGB")
			tell polygons to if it exists then set rgbImages to rgbImages & (images whose space is "RGB") & (EPSs whose space is "RGB")
		end tell
	end if
end tell

set rgbImageCount to count of rgbImages

I’m not sure I understand your problem with text frames; your use of trys should stifle any errors.