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 Answer
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.– joojaaMay 2, 2016 at 5:07
-
rectangle()
accordingly.