0

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
    (pgItem.position[1],
    pgItem.position[0],
    pgItem.width,
    pgItem.height);  

    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 '16 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. – usr2564301 May 1 '16 at 10:02
  • I could not CAI and Rad Lexus ..Can you help..are you the author – enisio May 1 '16 at 13:55
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(
pgItem.position[1]+42.52,
pgItem.position[0]-42.52,
pgItem.width+85.04,
pgItem.height+85.04);
  • you couod have put the calculation to a variable instead of hardcoding it. – joojaa May 2 '16 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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