Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Finding bounds of nested clipping paths...

New Here ,
Aug 10, 2010 Aug 10, 2010

This topic has been touched on before, muppet & sonic have pointed me in the right direction, but I'm stuck right now....

Seeing as how "saveMultipleArtboards = false" is broken in CS4, and scripting any kind of epsSave results in the artboard size being the bounding box, I am trying to see if I can find out if the "visible to the eye" bounds of artwork exceed the artboard size.

I can easily find non-clipped objects hanging outside the artboard by comparing the document's visible bounds to the artboard size.

Likewise the "visible to the 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 for items on page
if(docRef.pageItems.length != 0){

/////Find out if top item is clipping mask
if(docRef.pageItems[0].typename == "GroupItem"){
if(docRef.pageItems[0].pathItems[0].clipping == true){

////Compare its bounds to 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, this doesn't work if clipping paths are part of a nested groups. Is there a way to see if a clipping path's parent group is within bounds, or parent's parent group etc. is within bounds. I need to find the topmost clipping path that trumps all the others in any nested group.

Is that what recursive functions are for? ,,,,,,,,,,,

Something that can keep looking in a loop within itself?  Very instrospective!

thx

TOPICS
Scripting
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Explorer ,
Aug 11, 2010 Aug 11, 2010

Does this help? I use these to position and find bounds based upon what is visible.

function getRealVisibleBounds(grp) {
     var outerBounds = [];
     for(var i = grp.pageItems.length - 1; i >= 0;i--)  {
          var bounds = [];
          if(grp.pageItems.typename == 'GroupItem') {
               bounds =  getRealVisibleBounds(grp.pageItems);
          }
          else if((grp.pageItems.typename == 'PathItem' || grp.pageItems.typename == 'CompoundPathItem')
               && (grp.pageItems.clipping || !grp.clipped)) {
               bounds = grp.pageItems.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];
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 11, 2010 Aug 11, 2010

thx wysiwygbill, this is halfway there. It's returning the bounds of the clipping path at the bottom of the stack in the group. I need to return the topmost clipping path.... I'll play around a bit to see if I can make it work!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 12, 2010 Aug 12, 2010

It's supposed to return the outermost bounds of the group passed to the routine which might not be the bottom most path. Sections of paths which are hidden from view shouldn't be included which was one of the reasons I wrote it. VisibleBounds by itself was ignoring clipping and basing measurements and positions on the VisibleBounds of the group as a whole didn't reflect what was actually, well, visible.

I posted another version and example in an earlier thread. That version was based on finding actual measurements of the current document selection instead of a specified group object.


Edit: Note that I previously discovered that the Document.PageItems returns objects more than once and used the Layers.PageItems instead. So, if you are using Document.PageItems you might get funny results.

If you still can't get it to work I'll try writing a script to do what you actually asked for.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 12, 2010 Aug 12, 2010

Yup, I will try your earlier script. Part of my problem is all my previous scripting is very linear (I'm a graphic artist, not a programmer), and I'm just learning about functions. This will be a good way to learn, no doubt!

3 hours later.......

Yes, it's working, and not returning the bottom clipping group (which is good), but I can't get it to work if clipping groups are nested, it's returning the total bounds of clips within clips, not the topmost clipping path....

Ideally I want know if artwork (including nested clipping groups within nested clipping groups etc.) is within the artboard bounds (to the naked eye). I used to simply dip into the postcript file with my CS2 script and compare the "bounding box" size to the doc size (in a clumsy but effective way). CS4 has changed all that! I appreciate any help wysiwygbill!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2015 Jan 07, 2015
LATEST

i was just wrestling with this very problem. here's what i ended up with.

this will find the clipping mask that is highest in the layer[0].pathItems index and then stop looking and return the visible bounds of that clipping mask to the variable clipMaskBounds.

this works in CC 2014.. i'm not sure about CS4, though.

var docRef = app.activeDocument;

var topGroup = docRef.layers[0].pathItems;

var clipMaskBounds = x

for (i = 0; i < topGroup.length; i ++){

    if (topGroup.clipping = true){

          clipMaskBounds = topGroup.visibleBounds;

          break;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines