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

Working on a script that will add a new artboard and delete the old one if it is not a specific size

Contributor ,
Nov 01, 2014 Nov 01, 2014

var docRef = app.activeDocument;

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM; 

var ab = docRef.artboards[0];

if ((((ab.artboardRect[2] - ab.artboardRect[0]) / 72) == 17) && (((ab.artboardRect[1] - ab.artboardRect[3]) / 72) == 20)) {

// do nothing

}

                 

else {

docRef.artboards.add( [575,1601.78,1799,161.78] );   

docRef.artboards.remove(0);

var abIdx = docRef.artboards.getActiveArtboardIndex(); 

var actAbBds = docRef.artboards[abIdx].artboardRect;

}

I want to say it works about 90% of the time. I have no idea why it doesn't always work, sometimes it will build the other artboard even though it is the correct size and I have no idea why. It is very frustrating haha. If anyone has an idea why it won't always work, please let me know. Thanks in advance!

TOPICS
Scripting
794
Translate
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 , Nov 01, 2014 Nov 01, 2014

Hi djbgraphicdesign,

perhaps this could be a rounding problem.

Please try something like this instead

if ((Math.round((ab.artboardRect[2] - ab.artboardRect[0]) / 72) == 17) && (Math.round((ab.artboardRect[1] - ab.artboardRect[3]) / 72) == 20)) {

Translate
Adobe
Community Expert ,
Nov 01, 2014 Nov 01, 2014

Hi djbgraphicdesign,

perhaps this could be a rounding problem.

Please try something like this instead

if ((Math.round((ab.artboardRect[2] - ab.artboardRect[0]) / 72) == 17) && (Math.round((ab.artboardRect[1] - ab.artboardRect[3]) / 72) == 20)) {

Translate
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
Contributor ,
Nov 01, 2014 Nov 01, 2014

I tried it and tested it about 50 times, it worked every time. Thanks for coming to my rescue again pixxxel!

Translate
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 ,
Dec 03, 2014 Dec 03, 2014

I can see here the artboards.add method used with an array as argument but for me it always (more than 50times:) ) stops executing with

Error 1200: an Illustrator error occurred: 1346458189 ('PARM') error

in Illustrator CS5.1

Translate
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
Contributor ,
Dec 16, 2014 Dec 16, 2014

Darn, I have illustrator 6 and I have never had that problem. I would ask that question again as a new discussion so more people could see it, I'm sure someone out there has the answer. I wish I could help but I have no idea

Translate
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
Contributor ,
Dec 16, 2014 Dec 16, 2014
LATEST

And it looks like you already did and pixxxel answered it haha. I should of checked the discussion board.

Translate
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