Thanks! Your method may work best, I'm guessing because of "hasSelectedArtwork". When items are nested, it's causing it not to select everything even with redraws.
Created a mashup of the 2. I still needed a decoy/marker layer to move the plugin item back to. The redraws have been tested against running in an action and succeeds both ways.
function aiDecoyPath(where) {
decoyPath = app.activeDocument.pathItems.rectangle(-50, 50, 100, 100);
decoyPath.name = "DECOY_EMPTY_PATH";
decoyPath.filled = false;
decoyPath.stroked = false;
decoyPath.move(where, ElementPlacement.PLACEBEFORE);
decoyPath.selected = true;
return decoyPath;
}
var idoc = app.activeDocument;
var pI = idoc.pluginItems;
var tempLayer = idoc.layers.add();
tempLayer.name = "PROCESSING"
for (var i = pI.length - 1; i >= 0; i--) {
decoy = aiDecoyPath(pI[i]);
pI[i].move(tempLayer, ElementPlacement.PLACEATEND);
activeDocument.activeLayer.hasSelectedArtwork = true;
redraw();
app.executeMenuCommand("expandStyle");
app.activeDocument.selection[0].move(decoy,ElementPlacement.PLACEAFTER)
redraw();
app.executeMenuCommand("ungroup");
decoy.remove();
app.executeMenuCommand("deselectall");//Adding just to be safe
}
tempLayer.remove();