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

Artboard size

Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

What´s the error code below... The artboard size no change.

 

var doc = app.activeDocument;
var allPathItems = doc.pathItems;
for (var i = 0; i < allPathItems.length; i++) {
allPathItems[i].selected = true;
}
var sel = doc.selection;
var left = sel[0].left;
var top = sel[0].top;
var right = sel[0].right;
var bottom = sel[0].bottom;
for (var i=1; i<sel.length; i++) {
left = Math.min(left, sel[i].left);
top = Math.min(top, sel[i].top);
right = Math.max(right, sel[i].right);
bottom = Math.max(bottom, sel[i].bottom);
}
doc.artboards[0].artboardRect = [left-20, top-20, right+20, bottom+20];

TOPICS
Scripting

Views

578

Translate

Translate

Report

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

correct answers 1 Correct answer

Engaged , Jan 26, 2023 Jan 26, 2023

Start here to get an idea of how to proceed with your script.

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

to start, sel[0].right and sel[0].bottom return NaN (not a number) since right and bottom properties do not exist

 

to get right and bottom coordinates, use Left coordinate + Selection Width. Similarly Top coordinate - Selection Height

Votes

Translate

Translate

Report

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 ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Hi @CarlosCanto 

Could you show me?

Votes

Translate

Translate

Report

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 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Hi @Julio Ricardo 

I see a bigger problem with your code. It will only work in the end if it is ALWAYS only about pathItems. As soon as compoundPaths, clipping groups, nested groups or other items or effects are present, the script will generate new errors.

 

Question:
How are your files constructed and what exactly is your goal? Fitting the artboard to a selection? Or to the whole document content? Or, or, or ...?

 

Btw - this topic has been discussed here (and in other) forums quite often. So it could well be that there is already a solution to your question.

Votes

Translate

Translate

Report

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 ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

that all objects are selected and that the artboard is larger 10mm for each side (top, bottom, top and bottom)

Votes

Translate

Translate

Report

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 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Always remember: scripts are stupid. They only do what they were written for. However, they always do that well.

 

For this reason, an exact description is extremely important.

 

What elements are in your document? Do you have only one artboard? Or several? Should only one artboard be adapted to its elements? Which one? The active one?

 

Or several artboards to their respective content? Or should a new "superartboard" be created over all elements of all artboards? Or, or, or ...?

 

My script snippet in the post linked by @jduncan  (written in 2021) enlarges the active artboard 10mm around the content of the artboard. But it has the restriction that for example live text is only considered with the size of its selection - and not within the limits of its visible bounds.

Votes

Translate

Translate

Report

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
Engaged ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

LATEST

Yes, @pixxxelschubser is 100% correct and that's why I said: "to get an idea of how to proceed". Most every snippet you find on this forum will have to be adjusted for your specific situation. There are many "gotchas" in Ai scripting that only show up once you think you've got a script done. Good luck!

Votes

Translate

Translate

Report

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
Engaged ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Start here to get an idea of how to proceed with your script.

Votes

Translate

Translate

Report

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 ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

Thank you so much @jduncan 

Votes

Translate

Translate

Report

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