InDesign CS4: Get list of objects with specific fill color

I am trying to get an object reference list of all polygons, ovals, and rectangles with a InDesign CS4 document whose fill color, color properties contains “0.0, 0.0, 0.0, 100.0”?

My current process involves targeting all items and then repeating through groups, subgroups, then determining if it is a rectangle, oval, or polygon. It is extremely slow, and becomes difficult when groups are “pasted into” frames, etc. I was thinking it would be much better to get the object reference of just the polygons and rectangles with that specific CMYK breakdown and then repeat through that list and then act upon them accordingly. The problem is, obtaining that initial list is not that simple?

HI. I know of no way to skip checking through all page items for classes bound in groups or objects containing other objects, but, if you post your code, maybe it could be optimized.

Thank you Marc, this is better than what I previously posted. But it still does not address when groups or objects are “Pasted Into” an oval, rectangle, or polygon. It would be fantastic if somebody could help solve this dilemma I’m having?

global theSel
global theSelRef
global theSubSelRef

on myBlackTest()
	try
		tell application "Adobe InDesign CS4"
			tell document 1
				set theSel to item 1 of selection
				set y to fill color of theSel
				set theTint to properties of y
				set theProps to theTint as list
				set theProps to theProps as string
				if theProps contains "0.00.00.0100.0" then
					-- Here I will test the size of the object and display a warning if the bounds are large enough to pose a potential overprint issue.
					display dialog "Found Black Fill Color"
				end if
			end tell
		end tell
	end try
end myBlackTest

on myBlackGroup1(x)
	tell application "Adobe InDesign CS4"
		tell document 1
			set i to 1
			repeat
				select page item i of x
				set theSubSel to item 1 of selection
				set theClass to class of theSubSel as text
				if theClass contains "group" then
					set x to object reference of selection
					my myBlackGroup1(x)
				end if
				if theClass contains "rectangle" or theClass contains "oval" or theClass contains "polygon" then
					my myBlackTest()
				end if
				set i to i + 1
			end repeat
		end tell
	end tell
end myBlackGroup1




tell application "Adobe InDesign CS4"
	activate
	tell document 1
		repeat with i from 1 to count of page items
			select page item i
			set theSel to item 1 of selection
			set theSelRef to object reference of theSel
			try
				set theClass to class of theSel as text
				if theClass contains "polygon" or theClass contains "rectangle" or theClass contains "oval" then
					--This is a basic item on page that I wish to test, or if 
					my myBlackTest()
				end if
				if theClass contains "group" then
					set x to object reference of selection
					my myBlackGroup1(x)
				end if
			end try
		end repeat
	end tell
end tell

Hi. Unless it’s specifically for testing, I wouldn’t use a selection”that method is slow. You’re currently iterating through page items by index, but it would really be better to iterate directly through all page items, which includes items within groups. A conditional could then weed out groups from that list, allowing you to remove the entire myBlackGroup handler. Rather than the dialog that something is found, I’d set up a list and copy references to found items to it; this is more useful, especially if you need to do something with those objects later.

Thank you VERY much Marc, this is much better. I will also have to test for opacity and blending mode, but that part is easy. Thank you once again!

tell application "Adobe InDesign CS4"
	set myFoundItemsList to {}
	set allPageItems to object reference of all page items of document 1
	repeat with i from 1 to count of items in allPageItems
		try
			set theClass to class of item i of allPageItems as text
		on error
			exit repeat
		end try
		
		if theClass is "rectangle" or theClass is "oval" or theClass is "polygon" then
			try
				set y to fill color of item 1 of item i of allPageItems
				set theTint to properties of y
				set theProps to theTint as list
				set theProps to theProps as text
				set x to fill tint of item i of allPageItems as text
				
				
				if theProps contains "processCMYK0.00.00.0100.0" and x contains "-1.0" then
					set myFoundItem to object reference of item i of allPageItems
					set end of myFoundItemsList to myFoundItem
				end if
			end try
		end if
		
	end repeat
	
	set theCount to count of items in myFoundItemsList
	--I will then cycle through this list of items and check for size parameters and display a warning when conditions are met, not count them.
	display dialog theCount as string
end tell