Copy link to clipboard
Copied
Good people of the forums,
I am working on a script that simplifies/consolidates art objects in documents that we eventually convert into FXG files. I have run into a strange problem with a compound shape in one document.
Normally upon encountering a "plugin item," the script selects the item and then runs an Expand Appearance so that it can begin to break it down to easier items. In this case, Expand Appearance will not run, because the script seems to be unable to select the plugin item plus all of its children. If I use the Layers palette to select the compound shape manually, outside of the script, Illustrator will select the compound shape and everything contained within it, like normal:
Yet, if I set the 'selected' property to true within the script, it selects the compound shape and any first-level children, but leaves any second level children (children of children) unselected, which makes Expand Appearance disabled:
selection/expansion code looks like this:
doc.pageItems
app.executeMenuCommand('expandStyle')
I thought of putting together a quick function that would accept a page item as an argument and select it along with all of its children, but in the case of plugin items I have been unable to access its children directly since there doesn't appear to be any such thing as [pluginItem].pageItems or [pluginItem].pathItems.
I then figured maybe I could encapsulate the whole mess into a group so that I would have access to the groupObject.pageItems list and could select everything that way, but without selecting all the sub-children objects, Illustrator won't allow me to group them.
I'm starting to feel like Yossarian with this thing.
hmm...interesting, no can do
ok, doing the opposite seems to work, start with everything selected, then in your script check each pageItem, if it is NOT a pluginItem, deselect it.
Copy link to clipboard
Copied
how did you create that pluginItem?
and just to make sure, select your pluginItem and run this script, you do get a "pluginItem", right?
var idoc = app.activeDocument;
var sel = idoc.selection[0];
alert(sel.typename);
Copy link to clipboard
Copied
I was able to replicate your problem,
try this
// select compound shapes with groups and loose items in it
// carlos canto
// http://forums.adobe.com/thread/1392150?tstart=0
var idoc = app.activeDocument;
idoc.pluginItems[0].selected = true;
var temp = idoc.selection[0];
temp.selected = true;
Copy link to clipboard
Copied
Thanks for the reply, Carlos.
I tried selecting the plugin Item via doc.pluginItems[0], and then the temp variable like you wrote. Even with all of that, Illustrator still only selects the 1st and 2nd-level objects, ignoring everything further down.
Part of what makes this script tricky is that it has to process hundreds of old and new artworks by several different artists, so standard practices are difficult to enforce and the script must be able to process all kinds of unexpected art setups. Some of these setups are inefficient, messy, and poorly constructed, but we still have to try to break them down and process them.
In this particular case, we're looking now at having the script run a custom action we wrote that uses the pathfinder to release the compound shape. Problem is, the artist set up this art so that the fill and stroke attributes were assigned to the compound shape, but not the elements contained within it. When we run the release action, we lose all of the fill and stroke information. I'd try to store those values first and then re-apply them later, but with plugin items being as.... well supported... as they are, [pluginItem].fillColor returns undefined.
Copy link to clipboard
Copied
can you share a file with such compound shape to play with? if yes, CS5 please.
Copy link to clipboard
Copied
Sure thing. Here is the difficult shape from the artwork just as it is in the original file, but saved for CS5 (instead of 6).
Copy link to clipboard
Copied
hmm...interesting, no can do
ok, doing the opposite seems to work, start with everything selected, then in your script check each pageItem, if it is NOT a pluginItem, deselect it.
Copy link to clipboard
Copied
Carlos! Thanks so much for your creative thinking. That approach has allowed us to solve the problem. It's still a little annoying that we have to go about it in such a backward fashion, but at least it does the job.
Copy link to clipboard
Copied
you're welcome, glad to help
here's another way,
- create a tempLayer
- create a tempGroup in tempLayer
- move your pluginItem to tempGroup; // to easily move back after expand
- tempLayer.hasSelectedArtwork = true; // this works!!
- expand
to maintain stacking order, you can move a duplicate() of the pluginItem to tempLayer, then after expand, move back to position, and delete original item.
depending on how many items your art has this may be more efficient than looping thru all items, try it with real files and let us know how it goes.
Copy link to clipboard
Copied
Is there caffeine de to access items for beide a pluginItrm. I've noticed when I use pathfinder subtract while holding option on Mac. You create a sort of live subtract. Meaning you can still edit ir.
When I run a script to return the type name, it returns pluginItem. I can't seem to find code to see if there are children. This original thrra was almost 10 years ago. But still couldn't find anything in recent scripting documentation