enter image description here

var idoc = app.activeDocument;  

var sel = idoc.selection;  

var blk_color = new CMYKColor();  
blk_color.cyan = 100;  

for (i=0; i<sel.length; i++) 

    var pgItem = sel[i];  
    var bounds = pgItem.geometricBounds;  

    var ipath = idoc.pathItems.rectangle

    ipath.stroked = true;  
    ipath.strokeColor = blk_color;  
    ipath.filled = false;  
    ipath.strokeWidth = 5;  
    ipath.strokeDashes = [10];
  • 1
    This is a basic scripting question and not really design related. All you need to do is change the parameters of rectangle() accordingly.
    – Cai
    May 1, 2016 at 7:41
  • The hardest part is that Illustrator internally works with points only, so you will have to devise some way of recalculating 15mm to a point value.
    – Jongware
    May 1, 2016 at 10:02
  • I could not CAI and Rad Lexus ..Can you help..are you the author
    – enisio
    May 1, 2016 at 13:55

1 Answer 1


The rectangle method of pathItems takes the parameters (top,left,width,height) so all you need to do is offset those values accordingly.

Illustrator works exclusively with points so you need to convert the value from mm to points. 2.834645 points = 1 millimeter so...

15mm = 42.52point (rounded to 2 decimal places)

This should work:

var ipath = idoc.pathItems.rectangle(
  • you couod have put the calculation to a variable instead of hardcoding it.
    – joojaa
    May 2, 2016 at 5:07
  • Is it possible to keep the corners aligned in this script? May 5, 2021 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.