Illustrator CC object count problem

Hi Scripters!

I need a little help with an Illustrator script please.

I have a script which detects if a layer is empty or not.

tell application "Adobe Illustrator"
	tell document 1
		set x to count of every page item of layer 1
		if x = 0 then
			-- Do this
		end if
	end tell
end tell

Works OK for the most part. Until that is, I place a symbol on a layer on it’s own then EXPAND the symbol. The script then will return x=0 for the page item count for that layer.

I had thought that “page item” was a parent name that encompassed all possible types of items.

Can anyone suggest a way of making this script detect everything?

Thanks

Tim

Hi Tim,

This worked for me:

tell application "Adobe Illustrator"
	tell front document
		
		set pageItems to every page item of layer 1
		set pageItemsCount to count of pageItems
		
		if pageItemsCount = 0 then
			display dialog "Here!"
		end if
		
	end tell
end tell

I also tried:

tell application "Adobe Illustrator"
	set z to every page item of every layer of front document
end tell

That gives you a list of all the page items on all the layers. I’ve only given it a quick test though.

One thing I did notice is the way Illustrator handles the layers. Layer 1 seemed to be the layer that’s at the top of the layers list ‘Layers’ palette. They seemed to get numbered from 1 to the number of layers, in your document, going down the list. Even if you shuffle the layers around the top layer in the palette is layer 1.

If you don’t assign a name to the layer it’s called ‘Layer xx’ in the layers palette. However, that’s not the same as referring to the objects on a layer like this:

set pageItems to every page item of layer 1

That seems to be referring to the page items on the object layer 1, not the page items on a layer called ‘Layer 1’.

Do you have multiple layers in the document? If so layer 1 might not be the layer you think it is?

HTH

Hi TecNik

Thanks for you help but my problem remains. Perhaps I didn’t explain it right.

If you run your script it will work OK.

But…

If you place any symbol on the empty layer then expand (or Break Link to) that symbol, then run the script again the script does not register any page items on that layer. Even though there clearly is items there.

For some reason and expanded symbol is not a page item anymore.

I’ll keep looking… Thanks

Tim

Hi. It’ s likely that your expanded item is a group, rather than a path item.

Hi Tim,
D’oh! I’d not expanded the selection :expressionless:
If you do that it’s class changes to a ‘group item’. Marc’s right.

If you try this you can get a list of the group items.

tell application "Adobe Illustrator"
	set theGroupItems to every group item of front document
end tell

HTH

Thanks Guys

Now I am confused.

I have tried

tell application "Adobe Illustrator"
		set theGroupItems to every group item of front document
end tell

and it works fine and returns a nice list of groups. As you rightly said. However the original aim of the script is to find out if layer 1 contains items

so

tell application "Adobe Illustrator"
		set theGroupItems to every group item of layer 1 of front document
end tell

this returns { }. Why does directing the variable towards a layer now return nothing?

Confused…

Hi Tim,
Does this help?


tell application "Adobe Illustrator"
	set groupItemsList to every group item of front document
	set layerName to name of container of container of item 1 of groupItemsList
end tell

You may need to play around with the item number.

HTH

Thanks Tecnik

Yes this does help. I think I can use this.

Not sure how yet, but a least I can identify the layer that an item is on - if indirectly.

I’ll let you know what I come up with.

Thanks.

Tim