Copy link to clipboard
Copied
code here
var doc = app.activeDocument;
var rect = [-7211, 7411,-7111,7211]
doc.artboards.add(rect);
got error
There isn't a straightforward way, but I learned this technique from @OMOTI who discovered it and shared it, so thanks to them!
Here it is:
/**
* Returns bounds of canvas,
* ie. the largest artboard
* size possible.
* @author OMOTI
* @discussion https://community.adobe.com/t5/illustrator-discussions/the-initial-value-of-mvaluetx-and-mvaluety/m-p/9646654
* @returns {Array<Number>} - [left, top, right, bottom].
*/
function getCanvasBounds() {
var tempLayer,
tempText,
l
...
Copy link to clipboard
Copied
I tried your code and it worked as expected.
var doc = app.activeDocument;
var rect = [-7211, 7411, -7111, 7211];
doc.artboards.add(rect);
Have you tried it with a different document open? eg. a new document with 1 default artboard?
Also just for troubleshooting, does it stop erroring if you move the position? eg.
var doc = app.activeDocument;
var rect = [-5211, 5411, -5111, 5211];
doc.artboards.add(rect);
- Mark
Copy link to clipboard
Copied
@m1b My Ai is Illustrator 2022 26.5, I can't add a artboard on any position.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi @LoveYou阿逗逼6666, this is what I did:
1. Opened your demo file
2. Created a new artboard as big as I could make it—roughly filling the entire canvas
3. with script I printed it's artboardRect, and I got this:
-6000.34400523281, 7729.91113057397, 10223.684188449, -8501.30828837335
So every time you try to create an artboard bigger than that, it will throw the error.
When I do my previous example it works fine, because -5211 is inside those maximum bounds:
var doc = app.activeDocument;
var rect = [-5211, 5411, -5111, 5211];
doc.artboards.add(rect);
Does that make sense?
- Mark
P.S. this is what I mean by a big artboard the size of the canvas:
Copy link to clipboard
Copied
sir how can i get the Canvas size by jsx. thank you
Copy link to clipboard
Copied
There isn't a straightforward way, but I learned this technique from @OMOTI who discovered it and shared it, so thanks to them!
Here it is:
/**
* Returns bounds of canvas,
* ie. the largest artboard
* size possible.
* @author OMOTI
* @discussion https://community.adobe.com/t5/illustrator-discussions/the-initial-value-of-mvaluetx-and-mvaluety/m-p/9646654
* @returns {Array<Number>} - [left, top, right, bottom].
*/
function getCanvasBounds() {
var tempLayer,
tempText,
left,
top,
LARGEST_SIZE = 16383;
if (!app.documents.length) {
return;
}
tempLayer = app.activeDocument.layers.add();
tempText = tempLayer.textFrames.add();
left = tempText.matrix.mValueTX;
top = tempText.matrix.mValueTY;
tempLayer.remove();
return new Rect(
left,
top,
left + LARGEST_SIZE,
top + LARGEST_SIZE
);
}
// example usage
var rect = getCanvasBounds();
// cover the whole area
app.activeDocument.pathItems.rectangle(rect[1], rect[0], 16383, 16383);