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

Help with cleaning up array of pageItems, please.

$
0
0

Hey folks.

 

I have a question that only loosely pertains to illustrator, as I think I'm just missing something really obvious in basic JS logic..

 

I've written a script to create artboards for me that fit tight to the outside of many pageItems. In the first iteration, I wrote the script to look only for groupItems because I was assuming my production artists were doing things properly. Turns out, many of them 'walk to the beat of a different drummer', if you will. So I've decided to give up on changing their habits and take this as an exercise in self improvement with regards to scripting unpredictability.

 

Now I'm rewriting the script to work with any pageItem. The problem I'm running into is the exclusion of a pageItem that is either- A: Completely contained within another object, or B: Shares left && || top && || right && || bottom coordinates (eg. object a has bounds 5, 5, 10, -10 and object b has bounds 5, 4, 9, -9).

 

So far I have a function written to sort through the pageItems and sort them into rows (within a certain tolerance). After i determine all pageItems that are in a particular row, I want to loop that row to check for any items that are completely contained within another object, or share some bounds as the example above. The problem I'm running into is how to properly and efficiently do this check.. I've done this successfully when I'm only looking for something completely contained within, like this:

 

var array = [(all pageItems of given row are pushed here)]

for(a=array.length-1;a>-1;a--){     var curObj = array[a];     var L = curObj.left;     var T = curObj.top;     var R = L + curObj.width;     var B = T - curObj.height;     for(b=array.length-1;b>-1;b--){          var compareObj = array[b];          var CL = compareObj.left;          var CT = compareObj.top;          var CR = CL + compareObj.width;          var CB = CT - compareObj.height;          if(CL > L && CT < T && CR < R && CB > B){               array.splice(b,1);          }     }
}

 

This part works fine, but only because it returns false when a=b (since when a=b it's comparing the same object, so if I include >= or <=, it splices every object from the array and nothing happens).

 

So, my question is, how do I set up that second loop to ignore curObj? My first inclination is to simply splice the curObj before I start the second loop and set the compareObj variable. But there's a good chance that object needs to be compared later.

 

Sorry if that's confusing.. i've been pulling my hair out trying to wrap my head around this (probably really simple) issue.

 

**EDIT**

 

I made a quick visualization for what i'm looking to do. In the attached screenshot I want to loop through this row of objects and splice the black boxes out of the array while leaving the gray boxes.

 

Screen Shot 2015-08-12 at 8.58.55 AM.jpg


Viewing all articles
Browse latest Browse all 12845

Trending Articles



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