Finding bounds of nested clipping paths...


this topic has been touched on before, muppet & sonic have pointed me in right direction, i'm stuck right now....

 

seeing how "savemultipleartboards = false" broken in cs4, , scripting kind of epssave results in artboard size being bounding box, trying see if can find out if "visible eye" bounds of artwork exceed artboard size.

 

i can find non-clipped objects hanging outside artboard comparing document's visible bounds artboard size.

likewise "visible eye" bounds of clipped objects :

 

var docref = app.activedocument;

docref.rulerorigin = [0,0];

 

////get size of artboard
var mydocsizearray = [0,0,docref.width,docref.height]

 

////check items on page
if(docref.pageitems.length != 0){

 

/////find out if top item clipping mask
if(docref.pageitems[0].typename == "groupitem"){
if(docref.pageitems[0].pathitems[0].clipping == true){

 

////compare bounds doc bounds
var mycliparray = docref.pageitems[0].pathitems[0].visiblebounds
if((mycliparray[1] >  mydocsizearray[3]) || (mycliparray[2] >  mydocsizearray[2]) || (mycliparray[0] < 0) || (mycliparray[3] < 0)){
alert("outside of artboard")
}        
}
}
}

 

however, doesn't work if clipping paths part of nested groups. there way see if clipping path's parent group within bounds, or parent's parent group etc. within bounds. need find topmost clipping path trumps others in nested group.

 

is recursive functions for? ,,,,,,,,,,,

 

something can keep looking in loop within itself?  instrospective!

 

thx

does help? use these position , find bounds based upon visible.

 

function getrealvisiblebounds(grp) {
     var outerbounds = [];
     for(var = grp.pageitems.length - 1; >= 0;i--)  {
          var bounds = [];
          if(grp.pageitems[i].typename == 'groupitem') {
               bounds =  getrealvisiblebounds(grp.pageitems[i]);
          }
          else if((grp.pageitems[i].typename == 'pathitem' || grp.pageitems[i].typename == 'compoundpathitem')
               && (grp.pageitems[i].clipping || !grp.clipped)) {
               bounds = grp.pageitems[i].visiblebounds;
          }
          if (bounds.length > 0) {
               outerbounds = maxbounds(outerbounds,bounds);
          }
     }
     return (outerbounds.length == 0) ? null : outerbounds;
}

function maxbounds(ary1,ary2) {
     var res = [];
     if(ary1.length == 0)
          res = ary2;
     else if(ary2.length == 0)
          res = ary1;
     else {
          res[0] = math.min(ary1[0],ary2[0]);
          res[1] = math.max(ary1[1],ary2[1]);
          res[2] = math.max(ary1[2],ary2[2]);
          res[3] = math.min(ary1[3],ary2[3]);
     }
     return res;
}

function positionvisible(grp,x,y)
{
     var bounds = getrealvisiblebounds(grp);
     var newx = x + (grp.left - bounds[0]);
     var newy = y + (grp.top - bounds[1]);
     grp.position = [newx,newy];
}


More discussions in Illustrator Scripting


adobe

Comments

Popular posts from this blog

How to decompile jsxbin to jsx

Gavik Photoslide GK2: Not able to upload photos - Joomla! Forum - community, help and support

Phoca Guestbook logger registret bruger af - Joomla! Forum - community, help and support