I need some basic help in understanding how I would clarify group items vs. regular path items in Illustrator.
I would like the below statement to work on all the document’s path items, but exclude any items that happen to be group items. Yes, I know it sounds elementary and should be a one line script? But I am struggling here
tell application "Illustrator CS"
set unpainted to (every path item whose clipping is false and filled is false and class of stroke color is no color info) of document 1
delete unpainted
end tell
Not really, since this would remove practically everything on the layer.
The snippet I am concerned with is part of a much larger script that performs various cleanup tasks on an Illustrator document prior to saving. One such item I would like to have scripted is the removal of all non-painted objects (no fill, no stroke) from the active document. But there are times that I don’t want (non-filled, non-stroked) objects to be removed. One instance is when the object is serving as a clipping mask”in that case the empty path is vital. The other instance, not accounted for, relates to a group of objects. The script I posted is removing path items (more specifically compound path items) that have no fill and no stroke but only when they are part of group.
tell application "Illustrator CS"
tell document 1
delete (every path item whose clipping is false and filled is false and stroked is false)
end tell
end tell
I’m not positive about this, but you may have to loop. I think you would have to make a list of all group items and then check if the current path item is a part of any of the group items (or make a list of all path items that are in a group) and then delete the item if it is not in the list. I say this because if you do a count of every path item in a document it will count all path items whether it is in a group or not.
Pretech,
I would be crazy to doubt you.
I will have to attempt this. I just wasn’t sure if I could assign those specific attributes to only those paths that meet the criteria, and then loop through and check if they exist also as group items. It is tricky, but I will be interesting to try.
I have looked in the past for a easy way to get parent object in this app with no luck. Was hoping to build some sort of handler but my skills were lacking. Every attempt can’t get class as string etc. Then java has “parent.constructor.name” wow.!! no index number just type as name cool. A loop is required for what I wanted but “herrmueller” thank you very much I may give this app another try whilst trying to learn AS. With a quick play I came up with this.
tell application "Illustrator CS"
tell document 1
set selection to {}
set x to {}
set unpainted to every path item whose (filled is false and stroked is false)
repeat with i from 1 to count of unpainted
set selection to item i of unpainted
do javascript "app.selection[0].parent.constructor.name" show debugger on runtime error
set pathsParent to the result as string
if pathsParent is not "GroupItem" then -- Could add more or's here if required
copy (item i of unpainted) to end of x
end if
set selection to {}
end repeat
delete x
end tell
end tell
Whoo! this thread suddenly is seeing a lot more interest…
Not sure if this is the one! but it was giving me same results as mark’s
tell application "Illustrator CS"
tell document 1
tell layer 1
delete (every path item whose clipping is false and filled is false and stroked is false)
end tell
end tell
end tell
i know my second attempt was deleting the un-painted items in the group this leaves them alone aswell now…
assuming it works you would have to repeat thru the layers if it was a multi layered doc.
Pidge,
This is perfect! And I have also learned a bit in the process which is always a plus.
I will be honest, I have never really done a repeat function without the help from others. This one I tried on my own and it appears to work.
If for some reason someone seems something very wrong with my code, could they please let me know?
Regardless, thank you everyone!!!
-Jeff
tell application "Illustrator CS"
tell document 1
repeat with i from 1 to count of layers
tell layer i
delete (every path item whose clipping is false and filled is false and stroked is false)
end tell
end repeat
end tell
end tell