Skip to main content
Inspiring
December 27, 2018
Question

Illustrator: MultiExporter-Tool: Change script to add image dimensions

  • December 27, 2018
  • 1 reply
  • 8704 views

The MultiExporter tool  can generate png's of all artboards in your document.

The png's get the same name as the artboards.

The JavaScript code for the MultiExporter tool can be found here:

https://gist.github.com/larrybotha/5baf6a9aea8da574cbbe

What I want is to add automatically the dimension of the artboard/png to the exported png's.

So instead of file names like Number-1.png, Number-2.png I want file names

like Number-1_900x500.png, Number-2_800x600.png.

So is there anybody who knows if there is a simple possibility to change the script

to get automatically the width and height of the artboard/image in the file name?

This topic has been closed for replies.

1 reply

pixxxelschubser
Community Expert
Community Expert
December 27, 2018

Hi BaCbDc​,

sorry, but for scripters it's not a good manner to rewriting scripts from other developers.

Did you try to reach the developer Matthew Ericson?

Some hints for doing it by yourself:

In most cases you get the artboard size with:

var ab = app.activeDocument.artboards[0];

var Bds = ab.artboardRect;

alert((Bds[2] - Bds[0]).toFixed (3) + " pt × " + (Bds[1] - Bds[3]).toFixed (3) + " pt");

I did not go to deep into the code, but you have to work with the variable: base_filename

(pay attention: This variable does exists at several places in the script.)

Good luck

BaCbDcAuthor
Inspiring
December 29, 2018

With your hints I have done this beginning at line 356 in MultiExporter.js

           //var base_filename = this.base_path + "/" + this.prefix + artboardName + this.suffix

           

            var ab = app.activeDocument.artboards;

            var Bds = ab.artboardRect;

            //alert((Bds[2] - Bds[0]).toFixed (3) + " pt × " + (Bds[1] - Bds[3]).toFixed (3) + " pt");

            widthofartboard = (Bds[2] - Bds[0]).toFixed (3);

            heightofartboard = (Bds[1] - Bds[3]).toFixed (3);

           

            var base_filename = this.base_path + "/" + this.prefix + artboardName + this.suffix  + "_" +

            parseInt(widthofartboard) + "x" + parseInt(heightofartboard)

            //original:           

            //var base_filename = this.base_path + "/" + this.prefix + artboardName + this.suffix  +

            //docRef.artboards.width + "x" + docRef.artboards.height

Could be bad coded. But it's working. Update: Have just read what the meaning of toFixed is (number of places between 0 and 20 after the decimal point). So with toFixed(0) I think I don't need parseInt anymore.