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

Visible bounds includes invisible art from clipping mask

New Here ,
Mar 28, 2022 Mar 28, 2022

I am writing a script that makes fiducials around my design and to save material etc, I am resizing the artboard to the artwork using:

doc.artboards[0].artboardRect = doc.visibleBounds;

It works wonders, except if I have a clipping mask in the document because the "clipped"/invisible art is included in the visibleBounds it seems. Any suggestions on how to fix this?

Udklip.pngBefore making the clipping maskUdklip1.PNGHow it looks after the clipping mask is made and I run my script

 

 

I have the same issue when deselecting everything and using the Artboards -> Fit To Artwork Bounds. However if I select the art and use the exact same function (not Fit to Selected Art) it does it correctly. So it kinda seems like a bug

Udklip2.PNG

TOPICS
Bug , Scripting , Tools
1.4K
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
Community Expert ,
Mar 28, 2022 Mar 28, 2022

I ran into the same problem when creating my MatchObjects script. If you click the link you'll find a "getVisibleBounds" function that should help you out.

https://github.com/joshbduncan/adobe-scripts/blob/main/MatchObjects.jsx

dad x 2. designer. maker. fun haver. ‍
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 ,
Mar 28, 2022 Mar 28, 2022

Hi @jduncan, thanks for the link to your "getVisibleBounds" function. That should be just what @SThornelf needs.

Do you mind me asking, why do you handle CompoundPathItems specially? In my quick testing just now I get correct result simply from CompoundPathItem.geometricBounds. Is there special cases or am I missing something?

- Mark

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 ,
Mar 28, 2022 Mar 28, 2022

Yep, I was trying to catch a bunch of weird edge cases I had encountered and @Disposition_Dev found something that I had missed (linked here).

 

He found that in some cases, compound clipping paths could be comprised solely of groupItems which would cause a runtime error when attempting to get the first pathItem in the compound path. What you are referring to is the fix for this. Here's a link to a file that includes a bunch of weird stuff we used for testing the getVisibleBounds function.

dad x 2. designer. maker. fun haver. ‍
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
Guide ,
Mar 28, 2022 Mar 28, 2022

So you want your artboard to fit the "clipping path" (the path doing the masking)?  If so, presuming this is the first path in the first group in the document (going by your image):

 

doc.artboards[0].artboardRect = doc.groupItems[0].pathItems[0].visibleBounds;

 

 

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 ,
Mar 29, 2022 Mar 29, 2022

this works just fine if the item in question is just a single, regular clipping path. Unfortunately, this doesn't solve the issue of nested clipping paths or clipping paths that are deep inside a group. IMO the only reliable way is to check whether any clipping masks exist and if they do, dig recursively through the object to find the appropriate dimensions.

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 ,
Mar 29, 2022 Mar 29, 2022

Unless I'm missing something, the getVisibleBounds function should work fine in most cases with nested clipping paths and groups. I've tested it with a lot of different "junk" and it seems to get the right bounds most every time. I'm sure there is some weirdness I've yet to encounter (especially from exported files) but so far it has performed well.

 

Just so we are all on the same page, here's the link to a little script that is useful for testing the results of getVisibleBounds. It simply draws small crop marks on the artboard where it determines the visible bounds to be for the selected object.

 

And, here's another test Illustrator file that includes nested clipping paths and groups. Let me know if I'm missing something?

dad x 2. designer. maker. fun haver. ‍
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 ,
Mar 29, 2022 Mar 29, 2022

no you're right. getVisibleBounds() is great. I was replying to femkeblanco's suggestion about just explicitly using the top level pathItem from the given object. 

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 ,
Mar 29, 2022 Mar 29, 2022

Cool! I was concerned I was missing something obvious, and I didn't want to be putting something on here that didn't work. Thanks!

dad x 2. designer. maker. fun haver. ‍
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 ,
Mar 29, 2022 Mar 29, 2022

try this:

var doc = app.activeDocument;
var myArtwork = doc.groupItems[0];
doc.selection = null;
myArtwork.selected = true;
app.executeMenuCommand("Fit Artboard to selected Art");
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 ,
Mar 30, 2022 Mar 30, 2022

I'm new to Javascripts and executeMenuCommand was news to me.

 

Resizing the artboard is done twice

1. to have a way to place the fiducials

2. resizing it to include the fiducials in the artboard.

Your code (or femkeblanco's code for that matter) does not include the fiducials. Guessing because I have made a separate layer for them, but would love to know for sure

 

Your code gave me the clues for the absolutely easiest way to do it (in my case at least) :

app.executeMenuCommand("selectall");
app.executeMenuCommand("Fit Artboard to selected Art");

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 ,
Mar 30, 2022 Mar 30, 2022
LATEST

ah, yes indeed. had i known you wanted to fit the artboard to all artwork i would have written that. I assumed there was other artwork that you didn't necessarily want to include. 

in that case there's actually an even easier way.. we can optimize your code by 50%!! I specifically used "Fit Artboard to selected art" because i thought we were being selective. If you want to just make an artboard around all the art in the document, use this:

 

app.executeMenuCommand("Fit Artboard to artwork bounds");
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