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];
Start here to get an idea of how to proceed with your script.
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
Copy link to clipboard
Copied
Hi @CarlosCanto
Could you show me?
Copy link to clipboard
Copied
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.
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)
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Start here to get an idea of how to proceed with your script.
Copy link to clipboard
Copied
Thank you so much @jduncan