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

Add Margins in Illustrator

Explorer ,
Apr 30, 2014 Apr 30, 2014

Copy link to clipboard

Copied

I have made this little script to quickly add margins to an illustrator document and am posting it here to anyone that might find this helpful.

 

The script will bring up a dialog where you can enter the sizes. Checking the equal box makes all sizes the same as the first.

You have the option of using Millimetres, Inches or Pixels for your units and a last option to apply to all artboards or just the active one.

 

The script then adds the guides to a locked layer called 'Margins' for convenience.

 

There are two versions for your taste- The first creates 4 seperate guidelines. The second creates one rectangle guide.

 

#target illustrator

var docRef = app.activeDocument;

var artboardRef = docRef.artboards;

var workingLayer = docRef.activeLayer;

 

//window

var win = new Window('dialog', "Add Margins");

this.windowRef = win;

 

//panels

win.fieldpanel = win.add("panel", undefined, "");

win.radiopanel = win.add("panel", undefined, "");

win.radiopanel2 = win.add("panel", undefined, "");

 

//panel orientation

win.fieldpanel.orientation='row';

win.radiopanel.orientation='row';

win.radiopanel2.orientation='row';

 

//fieldpanel

win.fieldpanel.panel1 = win.fieldpanel.add('panel', undefined, "Left");

win.fieldpanel.panel2 = win.fieldpanel.add('panel', undefined, "Right");

win.fieldpanel.panel3 = win.fieldpanel.add('panel', undefined, "Top");

win.fieldpanel.panel4 = win.fieldpanel.add('panel', undefined, "Bottom");

 

win.fieldpanel.panel1.left_input = win.fieldpanel.panel1.add('edittext', undefined, "0");

win.fieldpanel.panel2.right_input = win.fieldpanel.panel2.add('edittext', undefined, "0");

win.fieldpanel.panel3.top_input = win.fieldpanel.panel3.add('edittext', undefined, "0");

win.fieldpanel.panel4.bottom_input = win.fieldpanel.panel4.add('edittext', undefined, "0");

 

win.fieldpanel.panel1.left_input.characters = 5;

win.fieldpanel.panel2.right_input.characters = 5;

win.fieldpanel.panel3.top_input.characters = 5;

win.fieldpanel.panel4.bottom_input.characters = 5;

 

win.fieldpanel.check1 = win.fieldpanel.add('checkbox', undefined, "Equal");

 

//radiopanel

win.radiopanel.radio1 = win.radiopanel.add('radiobutton',undefined, "mm");

win.radiopanel.radio2 = win.radiopanel.add('radiobutton',undefined, "in");

win.radiopanel.radio3 = win.radiopanel.add('radiobutton',undefined, "px");

 

//radiopanel2

win.radiopanel2.radio1 = win.radiopanel2.add('radiobutton',undefined, "All Artboards");

win.radiopanel2.radio2 = win.radiopanel2.add('radiobutton',undefined, "Active Artboard");

 

//select first radio buttons

win.radiopanel.radio1.value = true;

win.radiopanel2.radio1.value = true;

 

//ok button

win.okbutton = win.add('button', undefined, "Ok");

 

//disable fields with checkbox and equal values

win.fieldpanel.check1.onClick = function() {

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

   

    win.fieldpanel.panel2.right_input.enabled = false;

    win.fieldpanel.panel3.top_input.enabled = false;

    win.fieldpanel.panel4.bottom_input.enabled = false;

  } else {

    win.fieldpanel.panel2.right_input.enabled = true;

    win.fieldpanel.panel3.top_input.enabled = true;

    win.fieldpanel.panel4.bottom_input.enabled = true;

  }

};

 

//sync values while checked

win.fieldpanel.panel1.left_input.onChanging = function (){

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

  }

};

 

//event listener for ok button

win.okbutton.onClick = function(){

  var leftvalue = win.fieldpanel.panel1.left_input.text;

  var rightvalue = win.fieldpanel.panel2.right_input.text;

  var topvalue = win.fieldpanel.panel3.top_input.text;

  var bottomvalue = win.fieldpanel.panel4.bottom_input.text;

 

  if(win.radiopanel.radio1.value) {

    var multiplier = 2.834645669291339

  }

  if(win.radiopanel.radio2.value) {

    var multiplier = 72

  }

  if(win.radiopanel.radio3.value) {

    var multiplier = 1

  }

 

  //close window

  win.close();

 

  //make a margins layer

  var guideLayer = docRef.layers.add();

  guideLayer.name = "Margins";

 

 

  if(win.radiopanel2.radio1.value) {

  

    //repeat for each artboard

    for(i=0;i<artboardRef.length;i++){

 

      //get artboard size

      var left=artboardRef[i].artboardRect[0];

      var top=artboardRef[i].artboardRect[1] ;

      var right=artboardRef[i].artboardRect[2] ;

      var bottom=artboardRef[i].artboardRect[3] ;

 

 

      //create lines

      var lineLeft = docRef.pathItems.add();

      var lineRight = docRef.pathItems.add();

      var lineTop = docRef.pathItems.add();

      var lineBottom = docRef.pathItems.add();

 

      //set line points

      var leftmargin = (leftvalue * multiplier);

      var rightmargin = (rightvalue * multiplier);

      var topmargin = (topvalue * multiplier);

      var bottommargin = (bottomvalue * multiplier);

     

      //set line points

      lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);

      lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);

      lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);

      lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);

     

      //make lines guides

      lineLeft.guides = true;

      lineRight.guides = true;

      lineTop.guides = true;

      lineBottom.guides = true;

    };

  } else {

    //get artboard size

    var activeAB = docRef.artboards[docRef.artboards.getActiveArtboardIndex()]; // get active AB

    var left = activeAB.artboardRect[0];

    var top = activeAB.artboardRect[1] ;

    var right = activeAB.artboardRect[2] ;

    var bottom = activeAB.artboardRect[3] ;

 

    //create lines

    var lineLeft = docRef.pathItems.add();

    var lineRight = docRef.pathItems.add();

    var lineTop = docRef.pathItems.add();

    var lineBottom = docRef.pathItems.add();

 

    //set line points

    var leftmargin = (leftvalue * multiplier);

    var rightmargin = (rightvalue * multiplier);

    var topmargin = (topvalue * multiplier);

    var bottommargin = (bottomvalue * multiplier);

 

    //set line points

    lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);

    lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);

    lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);

    lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);

 

    //make lines guides

    lineLeft.guides = true;

    lineRight.guides = true;

    lineTop.guides = true;

    lineBottom.guides = true;

  };

 

  //lock margins layer and activate original layer

  guideLayer.zOrder (ZOrderMethod.SENDTOBACK);

  guideLayer.locked = true;

  docRef.activeLayer = workingLayer;

 

};

 

win.show();

 

 

Box Margin Version:

#target illustrator

var docRef = app.activeDocument;

var artboardRef = docRef.artboards;

var workingLayer = docRef.activeLayer;

 

//window

var win = new Window('dialog', "Add Margins");

this.windowRef = win;

 

//panels

win.fieldpanel = win.add("panel", undefined, "");

win.radiopanel = win.add("panel", undefined, "");

win.radiopanel2 = win.add("panel", undefined, "");

 

//panel orientation

win.fieldpanel.orientation='row';

win.radiopanel.orientation='row';

win.radiopanel2.orientation='row';

 

//fieldpanel

win.fieldpanel.panel1 = win.fieldpanel.add('panel', undefined, "Left");

win.fieldpanel.panel2 = win.fieldpanel.add('panel', undefined, "Right");

win.fieldpanel.panel3 = win.fieldpanel.add('panel', undefined, "Top");

win.fieldpanel.panel4 = win.fieldpanel.add('panel', undefined, "Bottom");

 

win.fieldpanel.panel1.left_input = win.fieldpanel.panel1.add('edittext', undefined, "0");

win.fieldpanel.panel2.right_input = win.fieldpanel.panel2.add('edittext', undefined, "0");

win.fieldpanel.panel3.top_input = win.fieldpanel.panel3.add('edittext', undefined, "0");

win.fieldpanel.panel4.bottom_input = win.fieldpanel.panel4.add('edittext', undefined, "0");

 

win.fieldpanel.panel1.left_input.characters = 5;

win.fieldpanel.panel2.right_input.characters = 5;

win.fieldpanel.panel3.top_input.characters = 5;

win.fieldpanel.panel4.bottom_input.characters = 5;

 

win.fieldpanel.check1 = win.fieldpanel.add('checkbox', undefined, "Equal");

 

//radiopanel

win.radiopanel.radio1 = win.radiopanel.add('radiobutton',undefined, "mm");

win.radiopanel.radio2 = win.radiopanel.add('radiobutton',undefined, "in");

win.radiopanel.radio3 = win.radiopanel.add('radiobutton',undefined, "px");

 

//radiopanel2

win.radiopanel2.radio1 = win.radiopanel2.add('radiobutton',undefined, "All Artboards");

win.radiopanel2.radio2 = win.radiopanel2.add('radiobutton',undefined, "Active Artboard");

 

//select first radio buttons

win.radiopanel.radio1.value = true;

win.radiopanel2.radio1.value = true;

 

//ok button

win.okbutton = win.add('button', undefined, "Ok");

 

//disable fields with checkbox and equal values

win.fieldpanel.check1.onClick = function() {

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

   

    win.fieldpanel.panel2.right_input.enabled = false;

    win.fieldpanel.panel3.top_input.enabled = false;

    win.fieldpanel.panel4.bottom_input.enabled = false;

  } else {

    win.fieldpanel.panel2.right_input.enabled = true;

    win.fieldpanel.panel3.top_input.enabled = true;

    win.fieldpanel.panel4.bottom_input.enabled = true;

  }

};

 

//sync values while checked

win.fieldpanel.panel1.left_input.onChanging = function (){

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

  }

};

 

//event listener for ok button

win.okbutton.onClick = function(){

  var leftvalue = win.fieldpanel.panel1.left_input.text;

  var rightvalue = win.fieldpanel.panel2.right_input.text;

  var topvalue = win.fieldpanel.panel3.top_input.text;

  var bottomvalue = win.fieldpanel.panel4.bottom_input.text;

 

  if(win.radiopanel.radio1.value) {

    var multiplier = 2.834645669291339

  }

  if(win.radiopanel.radio2.value) {

    var multiplier = 72

  }

  if(win.radiopanel.radio3.value) {

    var multiplier = 1

  }

 

  //close window

  win.close();

 

  //make a margins layer

  var guideLayer = docRef.layers.add();

  guideLayer.name = "Margins";

 

 

  if(win.radiopanel2.radio1.value) {

  

    //repeat for each artboard

    for(i=0;i<artboardRef.length;i++){

 

      //get artboard size

      var top=artboardRef[i].artboardRect[1] ;

      var left=artboardRef[i].artboardRect[0];

      var width=artboardRef[i].artboardRect[2]-artboardRef[i].artboardRect[0];

      var height=artboardRef[i].artboardRect[1]-artboardRef[i].artboardRect[3];

     

      //set margin sizes

      var leftmargin = (leftvalue * multiplier);

      var rightmargin = (rightvalue * multiplier);

      var topmargin = (topvalue * multiplier);

      var bottommargin = (bottomvalue * multiplier);

     

      //create box

      var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);

      box.fillColor = box.strokeColor = new NoColor();

 

      //make box guides

      box.guides = true;

    };

  } else {

    //get artboard size

    var activeAB = docRef.artboards[docRef.artboards.getActiveArtboardIndex()]; // get active AB

    var left = activeAB.artboardRect[0];

    var top = activeAB.artboardRect[1] ;

    var width = activeAB.artboardRect[2]-activeAB.artboardRect[0];

    var height = activeAB.artboardRect[1]-activeAB.artboardRect[3];

   

    //set margin sizes

    var leftmargin = (leftvalue * multiplier);

    var rightmargin = (rightvalue * multiplier);

    var topmargin = (topvalue * multiplier);

    var bottommargin = (bottomvalue * multiplier);

   

    //create box

    var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);

    box.fillColor = box.strokeColor = new NoColor();

 

    //make box guides

    box.guides = true;

  };

 

  //lock margins layer and activate original layer

  guideLayer.zOrder (ZOrderMethod.SENDTOBACK);

  guideLayer.locked = true;

  docRef.activeLayer = workingLayer;

 

};

 

win.show();

 

TOPICS
Scripting

Views

9.2K

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
Adobe
Community Expert ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

nice, thanks for sharing.

may I suggest something? combine them into one!!

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 ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

Yes that would be sensible! don't know why I didn't...

 

Here is a combined script:

 

#target illustrator

var docRef = app.activeDocument;

var artboardRef = docRef.artboards;

var workingLayer = docRef.activeLayer;

 

//window

var win = new Window('dialog', "Add Margins");

this.windowRef = win;

 

 

//panels

win.fieldpanel = win.add("panel", undefined, "Sizes");

win.radiopanel = win.add("panel", undefined, "Units");

win.optionpanel = win.add("panel", undefined, "Options");

win.optionpanel.radiopanel2 = win.optionpanel.add("panel", undefined, "Artboard");

win.optionpanel.radiopanel3 = win.optionpanel.add("panel", undefined, "Margin Type");

 

 

//panel orientation

win.fieldpanel.orientation='row';

win.radiopanel.orientation='row';

win.optionpanel.radiopanel2.orientation='row';

win.optionpanel.radiopanel3.orientation='row';

win.optionpanel.orientation='row';

 

//fieldpanel

win.fieldpanel.panel1 = win.fieldpanel.add('panel', undefined, "Left");

win.fieldpanel.panel2 = win.fieldpanel.add('panel', undefined, "Right");

win.fieldpanel.panel3 = win.fieldpanel.add('panel', undefined, "Top");

win.fieldpanel.panel4 = win.fieldpanel.add('panel', undefined, "Bottom");

 

win.fieldpanel.panel1.left_input = win.fieldpanel.panel1.add('edittext', undefined, "0");

win.fieldpanel.panel2.right_input = win.fieldpanel.panel2.add('edittext', undefined, "0");

win.fieldpanel.panel3.top_input = win.fieldpanel.panel3.add('edittext', undefined, "0");

win.fieldpanel.panel4.bottom_input = win.fieldpanel.panel4.add('edittext', undefined, "0");

 

win.fieldpanel.panel1.left_input.characters = 5;

win.fieldpanel.panel2.right_input.characters = 5;

win.fieldpanel.panel3.top_input.characters = 5;

win.fieldpanel.panel4.bottom_input.characters = 5;

 

win.fieldpanel.check1 = win.fieldpanel.add('checkbox', undefined, "Equal");

 

//radiopanel

win.radiopanel.radio1 = win.radiopanel.add('radiobutton',undefined, "mm");

win.radiopanel.radio2 = win.radiopanel.add('radiobutton',undefined, "in");

win.radiopanel.radio3 = win.radiopanel.add('radiobutton',undefined, "px");

 

//radiopanel2

win.optionpanel.radiopanel2.radio1 = win.optionpanel.radiopanel2.add('radiobutton',undefined, "All Artboards");

win.optionpanel.radiopanel2.radio2 = win.optionpanel.radiopanel2.add('radiobutton',undefined, "Active Artboard");

 

//radiopanel3

win.optionpanel.radiopanel3.radio1 = win.optionpanel.radiopanel3.add('radiobutton',undefined, "Margin Lines");

win.optionpanel.radiopanel3.radio2 = win.optionpanel.radiopanel3.add('radiobutton',undefined, "Margin Box");

 

//select first radio buttons

win.radiopanel.radio1.value = true;

win.optionpanel.radiopanel2.radio1.value = true;

win.optionpanel.radiopanel3.radio1.value = true;

 

//buttons

win.okbutton = win.add('button', undefined, "Ok");

 

 

 

//disable fields with checkbox and equal values

win.fieldpanel.check1.onClick = function() {

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

 

    win.fieldpanel.panel2.right_input.enabled = false;

    win.fieldpanel.panel3.top_input.enabled = false;

    win.fieldpanel.panel4.bottom_input.enabled = false;

  } else {

    win.fieldpanel.panel2.right_input.enabled = true;

    win.fieldpanel.panel3.top_input.enabled = true;

    win.fieldpanel.panel4.bottom_input.enabled = true;

  }

};

 

//sync values while checked

win.fieldpanel.panel1.left_input.onChanging = function (){

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

  }

};

 

//event listener for ok button

win.okbutton.onClick = function(){

  var leftvalue = win.fieldpanel.panel1.left_input.text;

  var rightvalue = win.fieldpanel.panel2.right_input.text;

  var topvalue = win.fieldpanel.panel3.top_input.text;

  var bottomvalue = win.fieldpanel.panel4.bottom_input.text;

 

  if(win.radiopanel.radio1.value) {

    var multiplier = 2.834645669291339

  }

  if(win.radiopanel.radio2.value) {

    var multiplier = 72

  }

  if(win.radiopanel.radio3.value) {

    var multiplier = 1

  }

 

  //make a margins layer

  var guideLayer = docRef.layers.add();

  guideLayer.name = "Margins";

 

 

  if(win.optionpanel.radiopanel2.radio1.value) {

 

    //repeat for each artboard

    for(i=0;i<artboardRef.length;i++){

 

      //get artboard size

      var left = artboardRef[i].artboardRect[0];

      var top = artboardRef[i].artboardRect[1] ;

      var right = artboardRef[i].artboardRect[2] ;

      var bottom = artboardRef[i].artboardRect[3] ;

      var width = artboardRef[i].artboardRect[2]-artboardRef[i].artboardRect[0];

      var height = artboardRef[i].artboardRect[1]-artboardRef[i].artboardRect[3];

 

      //create lines

      var lineLeft = docRef.pathItems.add();

      var lineRight = docRef.pathItems.add();

      var lineTop = docRef.pathItems.add();

      var lineBottom = docRef.pathItems.add();

 

      //set margin values

      var leftmargin = (leftvalue * multiplier);

      var rightmargin = (rightvalue * multiplier);

      var topmargin = (topvalue * multiplier);

      var bottommargin = (bottomvalue * multiplier);

 

      if(win.optionpanel.radiopanel3.radio1.value) {

        //set line points

        lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);

        lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);

        lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);

        lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);

 

        //make lines guides

        lineLeft.guides = true;

        lineRight.guides = true;

        lineTop.guides = true;

        lineBottom.guides = true;

      } else {

        //create box

        var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);

        box.fillColor = box.strokeColor = new NoColor();

 

        //make box guides

        box.guides = true;

      };

    };

  } else {

    //get artboard size

    var activeAB = docRef.artboards[docRef.artboards.getActiveArtboardIndex()]; // get active AB

    var left = activeAB.artboardRect[0];

    var top = activeAB.artboardRect[1] ;

    var right = activeAB.artboardRect[2] ;

    var bottom = activeAB.artboardRect[3] ;

    var width = activeAB.artboardRect[2]-activeAB.artboardRect[0];

    var height = activeAB.artboardRect[1]-activeAB.artboardRect[3];

 

    //create lines

    var lineLeft = docRef.pathItems.add();

    var lineRight = docRef.pathItems.add();

    var lineTop = docRef.pathItems.add();

    var lineBottom = docRef.pathItems.add();

 

    //set margin values

    var leftmargin = (leftvalue * multiplier);

    var rightmargin = (rightvalue * multiplier);

    var topmargin = (topvalue * multiplier);

    var bottommargin = (bottomvalue * multiplier);

 

    if(win.optionpanel.radiopanel3.radio1.value) {

      //set line points

      lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);

      lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);

      lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);

      lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);

 

      //make lines guides

      lineLeft.guides = true;

      lineRight.guides = true;

      lineTop.guides = true;

      lineBottom.guides = true;

    } else {

      //create box

      var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);

      box.fillColor = box.strokeColor = new NoColor();

 

      //make box guides

      box.guides = true;

    };

  };

 

  //lock margins layer and activate original layer

  guideLayer.zOrder (ZOrderMethod.SENDTOBACK);

  guideLayer.locked = true;

  docRef.activeLayer = workingLayer;

 

  //close window

  win.close();

};

 

win.show();

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 ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

thanks, much more efficient.

thanks

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
New Here ,
Feb 21, 2017 Feb 21, 2017

Copy link to clipboard

Copied

I know it's been a few years, but I just discovered your script.  Very handy.  Thank you!!

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 Beginner ,
Nov 24, 2022 Nov 24, 2022

Copy link to clipboard

Copied

thanks so much for this!!!! In AI 2023 it only works on a single page (not "all artboards") and nothing shows when I choose "margin lines", but with active artboard and margin box selected it will save me hours of work each month! Thanks again.

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 ,
Nov 24, 2022 Nov 24, 2022

Copy link to clipboard

Copied

the forum migration to a new platform a couple of years ago messed up some of the scripts. Try copying the script again, I just fixed it.

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
New Here ,
Apr 03, 2024 Apr 03, 2024

Copy link to clipboard

Copied

thanks, this works much better - only problem now is on large documents. For example, a 110" square ai doc, if I set the margins to 6", they actuually appear at what looks to be 49" in. 

 

I'm unable to get illustrator 28.1 to snap to guides properly so it's hard to tell exactly the size.

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 ,
Apr 03, 2024 Apr 03, 2024

Copy link to clipboard

Copied

for large canvas try using a 10th of your value, 0.6"

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 Beginner ,
Apr 08, 2024 Apr 08, 2024

Copy link to clipboard

Copied

Thanks for the script, been needing almost this exact setup for the start of something else. Is there anyway to get it so that when I enter 1 and click equal, it now puts a guide at each side and top/bottom at 1 inch, but i also need it to do it at.25 and .5 inch as well as the 1. Is it possible to get all 3 guides placed with one entry? 1st pic is current output, 2nd is what im needing for the guides

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 ,
Apr 08, 2024 Apr 08, 2024

Copy link to clipboard

Copied

LATEST

here you go, this version will add 3 guides per side, full size as entered in the UI, then 2 more at half the previous size. ie if you enter 1/2", then two more guides will be created at 1/4" and 1/8"

 

// add guides by eiranix
// https://community.adobe.com/t5/illustrator-discussions/add-margins-in-illustrator/m-p/14543246#M403970

// v2 - this version will create 3 guides per side as per defaultfrzzkd6qqsht request

var docRef = app.activeDocument;

var artboardRef = docRef.artboards;

var workingLayer = docRef.activeLayer;

 

//window

var win = new Window('dialog', "Add Margins");

this.windowRef = win;

 

 

//panels

win.fieldpanel = win.add("panel", undefined, "Sizes");

win.radiopanel = win.add("panel", undefined, "Units");

win.optionpanel = win.add("panel", undefined, "Options");

win.optionpanel.radiopanel2 = win.optionpanel.add("panel", undefined, "Artboard");

win.optionpanel.radiopanel3 = win.optionpanel.add("panel", undefined, "Margin Type");

 

 

//panel orientation

win.fieldpanel.orientation='row';

win.radiopanel.orientation='row';

win.optionpanel.radiopanel2.orientation='row';

win.optionpanel.radiopanel3.orientation='row';

win.optionpanel.orientation='row';

 

//fieldpanel

win.fieldpanel.panel1 = win.fieldpanel.add('panel', undefined, "Left");

win.fieldpanel.panel2 = win.fieldpanel.add('panel', undefined, "Right");

win.fieldpanel.panel3 = win.fieldpanel.add('panel', undefined, "Top");

win.fieldpanel.panel4 = win.fieldpanel.add('panel', undefined, "Bottom");

 

win.fieldpanel.panel1.left_input = win.fieldpanel.panel1.add('edittext', undefined, "1");

win.fieldpanel.panel2.right_input = win.fieldpanel.panel2.add('edittext', undefined, "0");

win.fieldpanel.panel3.top_input = win.fieldpanel.panel3.add('edittext', undefined, "0");

win.fieldpanel.panel4.bottom_input = win.fieldpanel.panel4.add('edittext', undefined, "0");

 

win.fieldpanel.panel1.left_input.characters = 5;

win.fieldpanel.panel2.right_input.characters = 5;

win.fieldpanel.panel3.top_input.characters = 5;

win.fieldpanel.panel4.bottom_input.characters = 5;

 

win.fieldpanel.check1 = win.fieldpanel.add('checkbox', undefined, "Equal");

 

//radiopanel

win.radiopanel.radio1 = win.radiopanel.add('radiobutton',undefined, "mm");

win.radiopanel.radio2 = win.radiopanel.add('radiobutton',undefined, "in");

win.radiopanel.radio3 = win.radiopanel.add('radiobutton',undefined, "px");

 

//radiopanel2

win.optionpanel.radiopanel2.radio1 = win.optionpanel.radiopanel2.add('radiobutton',undefined, "All Artboards");

win.optionpanel.radiopanel2.radio2 = win.optionpanel.radiopanel2.add('radiobutton',undefined, "Active Artboard");

 

//radiopanel3

win.optionpanel.radiopanel3.radio1 = win.optionpanel.radiopanel3.add('radiobutton',undefined, "Margin Lines");

win.optionpanel.radiopanel3.radio2 = win.optionpanel.radiopanel3.add('radiobutton',undefined, "Margin Box");

 

//select first radio buttons

win.radiopanel.radio2.value = true; // inches

win.optionpanel.radiopanel2.radio1.value = true;

win.optionpanel.radiopanel3.radio1.value = true;

 

//buttons

win.okbutton = win.add('button', undefined, "Ok");

 

 

 

//disable fields with checkbox and equal values

win.fieldpanel.check1.onClick = function() {

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

 

    win.fieldpanel.panel2.right_input.enabled = false;

    win.fieldpanel.panel3.top_input.enabled = false;

    win.fieldpanel.panel4.bottom_input.enabled = false;

  } else {

    win.fieldpanel.panel2.right_input.enabled = true;

    win.fieldpanel.panel3.top_input.enabled = true;

    win.fieldpanel.panel4.bottom_input.enabled = true;

  }

};

 

//sync values while checked

win.fieldpanel.panel1.left_input.onChanging = function (){

  if(win.fieldpanel.check1.value){

    var leftvalue = win.fieldpanel.panel1.left_input.text;

    win.fieldpanel.panel2.right_input.text = leftvalue;

    win.fieldpanel.panel3.top_input.text = leftvalue;

    win.fieldpanel.panel4.bottom_input.text = leftvalue;

  }

};

 

//event listener for ok button

win.okbutton.onClick = function(){

  var leftvalue = win.fieldpanel.panel1.left_input.text;

  var rightvalue = win.fieldpanel.panel2.right_input.text;

  var topvalue = win.fieldpanel.panel3.top_input.text;

  var bottomvalue = win.fieldpanel.panel4.bottom_input.text;

   // carlos edit for defaultfrzzkd6qqsht, to add 1" but also 1/2" and 1/4"
   var sizehalving = [1,2,2];

    //make a margins layer

    var guideLayer = docRef.layers.add();

    guideLayer.name = "Margins";

   for (var bb=0; bb<sizehalving.length; bb++) {
     leftvalue = leftvalue/sizehalving[bb];
     rightvalue = rightvalue/sizehalving[bb];
     topvalue = topvalue/sizehalving[bb];
     bottomvalue = bottomvalue/sizehalving[bb];

    if(win.radiopanel.radio1.value) {

      var multiplier = 2.834645669291339

    }

    if(win.radiopanel.radio2.value) {

      var multiplier = 72

    }

    if(win.radiopanel.radio3.value) {

      var multiplier = 1

    }

   

    if(win.optionpanel.radiopanel2.radio1.value) {

   

      //repeat for each artboard

      for(i=0;i<artboardRef.length;i++){

   

        //get artboard size

        var left = artboardRef[i].artboardRect[0];

        var top = artboardRef[i].artboardRect[1] ;

        var right = artboardRef[i].artboardRect[2] ;

        var bottom = artboardRef[i].artboardRect[3] ;

        var width = artboardRef[i].artboardRect[2]-artboardRef[i].artboardRect[0];

        var height = artboardRef[i].artboardRect[1]-artboardRef[i].artboardRect[3];

   

        //create lines

        var lineLeft = docRef.pathItems.add();

        var lineRight = docRef.pathItems.add();

        var lineTop = docRef.pathItems.add();

        var lineBottom = docRef.pathItems.add();

   

        //set margin values

        var leftmargin = (leftvalue * multiplier);

        var rightmargin = (rightvalue * multiplier);

        var topmargin = (topvalue * multiplier);

        var bottommargin = (bottomvalue * multiplier);

   

        if(win.optionpanel.radiopanel3.radio1.value) {

          //set line points

          lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);

          lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);

          lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);

          lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);

   

          //make lines guides

          lineLeft.guides = true;

          lineRight.guides = true;

          lineTop.guides = true;

          lineBottom.guides = true;

        } else {

          //create box

          var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);

          box.fillColor = box.strokeColor = new NoColor();

   

          //make box guides

          box.guides = true;

        };

      };

    } else {

      //get artboard size

      var activeAB = docRef.artboards[docRef.artboards.getActiveArtboardIndex()]; // get active AB

      var left = activeAB.artboardRect[0];

      var top = activeAB.artboardRect[1] ;

      var right = activeAB.artboardRect[2] ;

      var bottom = activeAB.artboardRect[3] ;

      var width = activeAB.artboardRect[2]-activeAB.artboardRect[0];

      var height = activeAB.artboardRect[1]-activeAB.artboardRect[3];

   

      //create lines

      var lineLeft = docRef.pathItems.add();

      var lineRight = docRef.pathItems.add();

      var lineTop = docRef.pathItems.add();

      var lineBottom = docRef.pathItems.add();

   

      //set margin values

      var leftmargin = (leftvalue * multiplier);

      var rightmargin = (rightvalue * multiplier);

      var topmargin = (topvalue * multiplier);

      var bottommargin = (bottomvalue * multiplier);

   

      if(win.optionpanel.radiopanel3.radio1.value) {

        //set line points

        lineLeft.setEntirePath([[left + leftmargin, top], [left + leftmargin, bottom]]);

        lineRight.setEntirePath([[right - rightmargin, top], [right - rightmargin, bottom]]);

        lineTop.setEntirePath([[left, top - topmargin], [right, top - topmargin]]);

        lineBottom.setEntirePath([[left, bottom + bottommargin], [right, bottom + bottommargin]]);

   

        //make lines guides

        lineLeft.guides = true;

        lineRight.guides = true;

        lineTop.guides = true;

        lineBottom.guides = true;

      } else {

        //create box

        var box = docRef.pathItems.rectangle (top - topmargin, left + leftmargin, width - rightmargin - leftmargin, height - topmargin - bottommargin);

        box.fillColor = box.strokeColor = new NoColor();

   

        //make box guides

        box.guides = true;

      };

    };

  }; // end carlos edit 

  //lock margins layer and activate original layer

  guideLayer.zOrder (ZOrderMethod.SENDTOBACK);

  guideLayer.locked = true;

  docRef.activeLayer = workingLayer;

 

  //close window

  win.close();

};

 

win.show();

 

 

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