• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Can not add artboard by jsx?

Explorer ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

code here

 

var doc = app.activeDocument;

var rect = [-7211, 7411,-7111,7211]

doc.artboards.add(rect);

 

Ai File 

got error 

Exception has occurred: 1200
an Illustrator error occurred: 1095724867 ('AOoC')

LoveYou6666_0-1709625083601.png

 

TOPICS
Bug , Feature request , How-to , Import and export , Performance , Scripting , SDK

Views

207

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 05, 2024 Mar 05, 2024

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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 05, 2024 Mar 05, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

@m1b  My Ai is Illustrator 2022 26.5, I can't add a artboard on any position.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

@m1b  you should use my Ai File and execute the script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2024 Mar 05, 2024

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:

Screenshot 2024-03-05 at 22.38.36.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

sir how can i get the Canvas size by jsx. thank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

LATEST

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);

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines