Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Sort groupItems in array using left coordinate of visible bounds?

$
0
0

Hey all! It's been a while, but I'm back with some more brain busters for you guys.

 

I'm in the process of re-working a script that Silly-V wrote up for me. The goal is to create an artboard around each group item of a document in order from top left to bottom right (as though you were reading a book). (ultimately i would also like to add a provision that precludes the possibility of having one artboard being contained by another artboard, but that's just a luxury that I can try to work out later).

 

Silly's script works great and does exactly what i need it to.. about 60% of the time. The problem comes in when I have a group item that contains a clipping mask. Since the artboards are being created by way of groupItem.visibleBounds, illustrator assumes that the invisible artwork that extends beyond the clipping mask is visible and thus, creates an artboard that is much too large.

 

His version pushes the visible bounds of every groupItem to an array, then sorts the visible bounds by left coordinate, then pushes that subarray to another array and at the end, sorts the arrays vertically by top coordinate.. However, I'm looking to push the actual groupItems into the array instead of just the visible bounds. Then I'd like to sort the array of groupItems by their visible bounds and then I have the option of either creating the artboards in order based on their visible bounds or (the contingency) running a loop to make each groupItem selected=true and using the fitArtboardToSelectedart() command.

 

I'm stuck on how to sort the array of groupItems based on the visible bounds.. Here's what I have so far:

 

my inclination is to set a variable for the visibleBounds of each groupItem of temp (which seems like it would need a loop) but it doesn't make sense to me to loop the sort function...? there's something really big i'm missing here but i can't wrap my head around it.

 

Thanks for any help!

 

function organize(){  var docRef = app.activeDocument;  var layer = docRef.layers[0];  var groups = layer.groupItems;  var currentRowMarker;  var groupList = []; //array of all groupItems  var sortedGroupList = []; //array of subarrays sorted by visible bounds  var temp = []; //temporary array for the current row of groupItems. sort this array from left to right first, then push the entire array into "sortedGroupList"  //populate groupList  for (g=0; g<groups.length; g++){       groupList.push(groups[g]);  }  //set currentRowMarker and compare rest of groupList to top coordinate of visible bounds. push true results to temp array.  for (t=0; t<groupList.length; t++){  temp = [];  currentRowMarker = groupList[t].visibleBounds[1];  temp.push(groupList[t]);  groupList.splice(t,1);       for (c=0; c<groupList.length; c++){            var currentGroup = groupList[c];            var vB = groupList[c].visibleBounds[1];                 if (vB + 20 > currentRowMarker && vB - 20 < currentRowMarker){                      temp.push(currentGroup);                      groupList.splice(c,1);                 }       }  //this is where i'd like to sort the temp array  sortedGroupList.push(temp);  }
}
organize();

Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>