Skip to content

Instantly share code, notes, and snippets.

@milligramme
Created September 21, 2010 01:27
Show Gist options
  • Save milligramme/588999 to your computer and use it in GitHub Desktop.
Save milligramme/588999 to your computer and use it in GitHub Desktop.
#target "Illustrator"
var doc = app.documents[0];
var topG = getTopGroup(doc.groupItems);
alert("top level group:"+topG.length+ "\r" +
"PageItems:" + doc.pageItems.length + "\r" +
"PathItems:" + doc.pathItems.length + "\r" +
"CompoundPathItems:" + doc.compoundPathItems.length + "\r" +
"GroupItems:" + doc.groupItems.length + "\r" +
"Selection:" + doc.selection.length);
/**
* get top level group items
* @param {Array} group Array of GroupItem
* @returns {Array} tgr Array of top level GroupItem
*/
function getTopGroup (group) {
var tgr=[];
for (var i=0; i < group.length; i++) {
//parent is Layer
if(group[i].parent.typename == "Layer"){
//group is formed with single path item
if(group[i].pathItems.length == 1){
tgr.push(group[i]);
}
//group is formed with compound path item
if(group[i].compoundPathItems.length == 1){
tgr.push(group[i]);
}
//group include any page items(textframe, pathitem)
else if(group[i].pageItems.length != 0){
tgr.push(group[i]);
}
}
}
return tgr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment