Copy link to clipboard
Copied
Hello
I'm trying to resize my artboard to an exact mm size via a script so then I can add this to a batch i'm trying to achieve.
I've been trying to use the following, but i cant work out how to add the size I want in mm?
Any help?
Thanks
#target illustrator
var doc = app.activeDocument;
var docVB = doc.visibleBounds;
var myVisibleBounds = doc.visibleBounds; //Rect, which is an array;
myVisibleBounds[0] -= 20; //left coordinate (use negative values to add artboard)
myVisibleBounds[1] += 20; //ltop coordinate
myVisibleBounds[2] += 20; //right coordinate
myVisibleBounds[3] -= 20; //bottom coordinate (use negative values to add artboard)
doc.artboards[0].artboardRect = myVisibleBounds;
Copy link to clipboard
Copied
AI does NOT allow measurement units like the othe apps it's points ONLY… SO you can do the math or use UnitValue()
#target illustrator
var mm = 2.834645;
var doc = app.activeDocument;
var myVisibleBounds = doc.visibleBounds; //Rect, which is an array;
myVisibleBounds[0] -= 20*mm; //left coordinate (use negative values to add artboard)
myVisibleBounds[1] += 20*mm; //ltop coordinate
myVisibleBounds[2] += 20*mm; //right coordinate
myVisibleBounds[3] -= 20*mm; //bottom coordinate (use negative values to add artboard)
doc.artboards[0].artboardRect = myVisibleBounds;
Copy link to clipboard
Copied
ah i was only missing the *, thanks this is just what i wanted
Copy link to clipboard
Copied
There is a page of the scriping guide about measurment units when scripting AI… Just 2 methods really…
You were also missing the variable mm and it's value…
Copy link to clipboard
Copied
Hello
So it turns out i'm still struggling with this, i cant get it to the size i need and its driving me mad :s
So the example i'm trying to achieve is
Resize from 860mmx600mm to 700mmx500mm
Thanks for any help!
edit---
im not sure if this is the best way but i have changed
var mm = 1;
just worked out my sizes in points then done the maths to make this work
Copy link to clipboard
Copied
Not to try to answer the original question, but I have been struggling with modifying artboards as well, but in JavaScript. It got a lot easier when I realized that the document and the artboard have different coordinate systems. See Adobe's docs for Document's convertCoordinate() method and the app's coordinateSystem property. You can create a new Point to convert with syntax like "var newLeftTopPoint = Point(leftValue, topValue);" I did not find a way to create a new rect for changing the artboard dimensions, but found that you can make a copy of the existing artboard's rect to modify with converted coordinates, setting it back to the artboard in one operation (you can't change the array elements one at a time directly). There's something about the artoboard rect object that is more involved than simply being an array of four numbers; the reflection API tells you there are properties named 0, 1, 2 and 3, which lets you access the object as if it was an array, but there is more to the object than that.
Copy link to clipboard
Copied
(Oh, and to add to the fun, the artboard coordinate system I think has a positive-down vertical axis but the document coordinate system is positive-up.) Also, the array order of the rect object does seem to be left, top, right, bottom (not sure why Adobe's docs couldn't have mentioned that somewhere).
Copy link to clipboard
Copied
(Sorry, I spoke too soon about up and down question of the axes. I was confused by a negative value in converted artboard coords I saw for the doc origin of 0,0, which had a negative value in the doc I was looking at.)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now