illustrator target every path item

Hi all,

I’m trying to change the fill colour of every path item on a layer but I’m only having a limited amount of success.

tell application "Adobe Illustrator"
	set pageItems to every page item of layer 1 of current document
	set swatchColor to color of swatch "Light Green" of current document
	
	repeat with thisPageItem in pageItems
		set pathItems to path items of thisPageItem
		repeat with thisPathItem in pathItems
			set fill color of thisPathItem to swatchColor
		end repeat
	end repeat
end tell

The above script works but on layer 1 there’s a group that contains a compound path and another group and I can’t seem to target the path items that are grouped or the compound path. The layer looks like this:

layer1
-------
------------------
------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------
------------------------------

the below object, that are on the same layer as above have there fill colour changed:

layer1
-------
-------
------------------
------------------
------------------
------------------
------------------
------------------
------------------

is there a way I can target every path item regardless of how nested it is? almost like saying:

set pathItems to every path item in entire contents of layer 1 of current document

Many Thanks,
Nik

Hi. Path items are all-inclusive, when not directed to a layer.


tell application "Adobe Illustrator"'s document 1
	set {allofit, theColor, layerTarget} to {path items, swatch "Light Green"'s color, "insert layer name"}
	repeat with something in allofit
		tell something to if its layer's name = layerTarget then set fill color to theColor
	end repeat
end tell

Hi Marc,

that works beautifully, thanks.

I would like to say that I would have got there eventually but realistically I don’t think I would!!!

Many Thanks again,
Nik