Skip to main content
ShynnSup
Inspiring
March 12, 2019
Answered

Script Artboard to "Fit to Artwork Bounds" on multiple files

  • March 12, 2019
  • 3 replies
  • 3559 views

Hi guys!

I was wondering if someone could help me by providing some insight into writing a simple script that fits the artboard to the artwork bounds on multiple files.

I currently do this by shift + o > select "Fit to Artwork Bounds" > ctrl + s. You can imagine this becomes very tedious when one has 100+ pdfs.

I imagine the script could create a folder at a standard directory and just save the new pdfs with same name there, or maybe add a prefix like "_edited" to differentiate them from the original pdfs.

Any insight would mean a tremendous help!

Thanks in advance,

Shynn

This topic has been closed for replies.
Correct answer CarlosCanto

try recording an action, then play said action in batch mode.

3 replies

Inspiring
March 12, 2019

Hi,

I am doing somewhat similar to your task.

The main things are

a) find all - or some - files in a folder

if(app.documents.length)

        var p = app.documents[0].fullName.path;

else

        p = undefined;

var where = new Folder(p).selectDlg('work files');

var ai_files = where.getFiles('*.ai');

b) open a file inside a loop, and change it

for(var n = 0 ; n < ai_files.length ; n++)

{    var doc = app.open(ai_files);

    var abi = doc.artboards.getActiveArtboardIndex();

    doc.selectObjectsOnActiveArtboard();

    doc.fitArtboardToSelectedArt(abi);

}

You will need to design a strategy (such as storing to a different folder and removing the original, or ignoring the file if a processed file is in the output folder)

You will need to consider possible errors (stuff cannot be selected because it is hidden or locked)

Srishti Bali
Community Manager
Community Manager
March 12, 2019

Discussion moved to Illustrator Scripting

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
March 12, 2019

try recording an action, then play said action in batch mode.

ShynnSup
ShynnSupAuthor
Inspiring
March 12, 2019

Tried that, the action recorder does not record the "fit to artwork bounds" option of the arboard tools.

Participant
March 12, 2019

Try to insert as menu item?