Skip to main content
heyvirgil
Known Participant
October 23, 2019
Question

Is there a script to fit artboard to selected art width only?

  • October 23, 2019
  • 3 replies
  • 1737 views

I'd very much appreciate this, I have basic scripting skills in with adobe, but with photoshop promarily.

I basically have many ai documents with multiple artboards that have padding (lets say the artboards are 75x75 pixels-

what I want to do is resize the artboard to the exact width of the selected art but keep the artboard height intact. Any ideas, thanks in advance. 

This topic has been closed for replies.

3 replies

pixxxelschubser
Community Expert
Community Expert
January 28, 2022

Hi @JoergBrueggemannIHK 

you can find dozens of similar scripts here in the forum.

For example: https://community.adobe.com/t5/illustrator-discussions/selections-to-artboards/m-p/8324026#M152712

 

Please describe what exactly you want. The above mentioned thread may or may not be what you are looking for ...

renél80416020
Inspiring
October 25, 2019

Salut,

Suivant la sélection.

var docRef = app.activeDocument;
var index = docRef.artboards.getActiveArtboardIndex();
    pdtRedim(index,docRef);
function pdtRedim(idx,doc){
  var ab, rect0, rect;
      ab = doc.artboards[idx];
      rect0 = ab.artboardRect;
      doc.fitArtboardToSelectedArt(idx);
      rect = ab.artboardRect;
      rect = [rect[0],rect0[1],rect[2],rect0[3]]
      ab.artboardRect = rect;
}

de elleere

let me know if you get stuck.

par mail

heyvirgil
heyvirgilAuthor
Known Participant
October 25, 2019

Merci! Brilliant!!!!!

CarlosCanto
Community Expert
Community Expert
October 24, 2019

to get you started, instead of using Fit Artboard to selected art, you should change the coordinates of the current artboard corners

to get the current coordinates of the first artboard

var idoc = app.activeDocument;

var ab0 = idoc.artboards[0];

var r = ab0.artboardRect;

var left = r[0];

var top = r[1];

var right = [2];

var bottom = r[3];

 

then, similarly you would get the bounds of your art, use left and right values to apply new coordinates on ab0.

 

let me know if you get stuck.

heyvirgil
heyvirgilAuthor
Known Participant
October 24, 2019

Totally stuck, I get 

Result: undefined

Running what you have above