Skip to main content
Participating Frequently
August 25, 2011
Answered

artboards and origin

  • August 25, 2011
  • 1 reply
  • 936 views

Hi, I'm trying to draw some objects to fixed positions on artboards by first setting the document origin to the top - left position of the artboard. However this seems to work for some of the artboards but not for all.

Sample code:

#target illustrator // create artboards var CurrentDoc = app.documents.add ( DocumentColorSpace.CMYK, 595, 841, 12, DocumentArtboardLayout.GridByRow, 50, 6); var artboardRef = CurrentDoc.artboards; // loopt through all artboards for ( var i = 0; i < artboardRef.length; i++ )   {    // set page and ruler origin    var RulerLeft = artboardRef.artboardRect[0];

   var RulerTop  = artboardRef.artboardRect[1] ;    CurrentDoc.rulerOrigin = [RulerLeft,RulerTop];    CurrentDoc.pageOrigin  = [RulerLeft,RulerTop];      //add text to artboard    var cTextRef = CurrentDoc.textFrames.add();    cTextRef.textRange.characterAttributes.textFont=app.textFonts.getByName("Verdana");    cTextRef.textRange.characterAttributes.size = 27;    cTextRef.contents = "ArtBoard: "+ (i+1);    cTextRef.left = +55;    cTextRef.top = -64;    redraw();   }

8 out of 12 artboards get the text at the right position (but not in the right order when I look at the artboards palette). Text for 4 artboards is placed completely outside any of the artboards.

Any help is appreciated,

Michel

This topic has been closed for replies.
Correct answer moluapple

Some Math operation is Ok, no need to set origin.

#target illustrator // create artboards var CurrentDoc = app.documents.add ( DocumentColorSpace.CMYK, 595, 841, 12, DocumentArtboardLayout.GridByRow, 50, 6); var artboardRef = CurrentDoc.artboards; // loopt through all artboards for ( var i = 0; i < artboardRef.length; i++ )   {    // set page and ruler origin    var RulerLeft = artboardRef.artboardRect[0];    var RulerTop  = artboardRef.artboardRect[1] ;    //CurrentDoc.rulerOrigin = [RulerLeft,RulerTop];    //CurrentDoc.pageOrigin  = [RulerLeft,RulerTop];      //add text to artboard    var cTextRef = CurrentDoc.textFrames.add();    cTextRef.textRange.characterAttributes.textFont=app.textFonts.getByName("Verdana");    cTextRef.textRange.characterAttributes.size = 27;    cTextRef.contents = "ArtBoard: "+ (i+1);    cTextRef.left = RulerLeft +55;    cTextRef.top = RulerTop -64;    redraw();   }

1 reply

moluappleCorrect answer
Inspiring
August 26, 2011

Some Math operation is Ok, no need to set origin.

#target illustrator // create artboards var CurrentDoc = app.documents.add ( DocumentColorSpace.CMYK, 595, 841, 12, DocumentArtboardLayout.GridByRow, 50, 6); var artboardRef = CurrentDoc.artboards; // loopt through all artboards for ( var i = 0; i < artboardRef.length; i++ )   {    // set page and ruler origin    var RulerLeft = artboardRef.artboardRect[0];    var RulerTop  = artboardRef.artboardRect[1] ;    //CurrentDoc.rulerOrigin = [RulerLeft,RulerTop];    //CurrentDoc.pageOrigin  = [RulerLeft,RulerTop];      //add text to artboard    var cTextRef = CurrentDoc.textFrames.add();    cTextRef.textRange.characterAttributes.textFont=app.textFonts.getByName("Verdana");    cTextRef.textRange.characterAttributes.size = 27;    cTextRef.contents = "ArtBoard: "+ (i+1);    cTextRef.left = RulerLeft +55;    cTextRef.top = RulerTop -64;    redraw();   }

msismsisAuthor
Participating Frequently
August 26, 2011

That works, thanks,

Michel