[ExtendScript] Moving an artboard to the center of a canvas
I would like to move one artboard at the edge of Illustrator's largest area (the canvas) to the center along with its contents via scripting. Is there a clever way to do this?
I currently have the following two algorithms in mind and have been successful in getting them to work.
- Patiently move the items using a method of getting the canvas coordinates developed by OMOTI
- Generate temporary artboards before and after the target artboard, center them with Document.rearrangeArtboards, and then delete the temporary artboards
var doc = app.documents[0] ;
var docArtboards = doc.artboards ;
var targetArtboard = docArtboards[0] ;
var rect = [0, 0, 1, -1] ;
var tempArtboards = [docArtboards.add(rect), docArtboards.add(rect)] ;
doc.rearrangeArtboards(DocumentArtboardLayout.Row) ;
for(var i = tempArtboards.length - 1 ; i >= 0 ; i--) {
tempArtboards[i].remove() ;
}
However, these methods have the following problems.
- Opacity masks do not follow the move (1)
- Document with width and height of 16383 pt will stop with an error (2)
- If not careful about the position of the temporary artboard, the artboard to which PageItem belongs changes, causing an unintended move (2)
Conditions:
- Support Illustrator CS6 (16) through Illustrator 2023 (27)
- Always only one artboard in a document