Skip to main content
Known Participant
November 1, 2014
Answered

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

  • November 1, 2014
  • 1 reply
  • 835 views

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!

This topic has been closed for replies.
Correct answer pixxxelschubser

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

1 reply

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
November 1, 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)) {

Known Participant
November 1, 2014

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

Participant
December 3, 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