Copy link to clipboard
Copied
I'm writing a script that, among other things, arranges artboards. here's the code it uses to move an artboard along with its art:
var doc = app.activeDocument;
//Board Object Constructor
function Board (index){
this.artboard = doc.artboards[index];
this.width = this.artboard.artboardRect[2]-this.artboard.artboardRect[0];
this.height = this.artboard.artboardRect[1]-this.artboard.artboardRect[3];
doc.artboards.setActiveArtboardIndex(index);
doc.selectObjectsOnActiveArtboard();
this.art = app.selection;
app.selection = [];
this.setPosition = function(x,y){
for(var i=0; i<this.art.length; i++){
this.art[i].position = [
this.art[i].left-this.artboard.artboardRect[0]+x,
this.art[i].top-this.artboard.artboardRect[1]+y
];
}
this.artboard.artboardRect=[x,y,x+this.width,y-this.height];
}
}
var boardOne = new Board(0);
var boardTwo = new Board(1);
boardTwo.setPosition(0,0);
boardOne.setPosition(-1000,1000);
The script does it's job as expected, but when I hit ctrl+z after running the script, there seems to be a glitch when reverting back to the previous state. Specifically point-type text does not revert to its previous position. Artboards, shapes, symbols, linked images, single anchor points, and area type will all revert to their previous positions, but point type does not revert.
If the point type was created and/or edited after opening the file, I can continue to press ctrl+z and when i reach a point in the history that affects the point type, it will revert to that state, but the state it was in directly prior to running the script is lost. If the first thing I do after opening a file is run the script, there is no way to restore the text to its previous position without reopening the file.
I'd like to find a way to make ctrl-z fully functional in case the final script has unintended results.
Or use redraw() method after zeroing the selection. It worked, too.
app.selection = [];
redraw();
Copy link to clipboard
Copied
A very old Point Text problem, when after it is created, some of the attributes cannot be freely changed until the text has been resized. You have to do a fake resize for that. Other examples of the trick in my blog.
var doc = app.activeDocument;
var boardOne = new Board(0);
var boardTwo = new Board(1);
boardOne.setPosition(-1000, 1000);
boardTwo.setPosition(0, 0);
//Board Object Constructor
function Board(index) {
this.artboard = doc.artboards[index];
this.width = this.artboard.artboardRect[2] - this.artboard.artboardRect[0];
this.height = this.artboard.artboardRect[1] - this.artboard.artboardRect[3];
doc.artboards.setActiveArtboardIndex(index);
doc.selectObjectsOnActiveArtboard();
this.art = app.selection;
app.selection = [];
this.setPosition = function (x, y) {
for (var i = 0; i < this.art.length; i++) {
// Trick to reset default point text bug
if (this.art[i].kind == 'TextType.POINTTEXT') {
this.art[i].resize(200, 200);
this.art[i].resize(50, 50);
}
this.art[i].position = [
this.art[i].left - this.artboard.artboardRect[0] + x,
this.art[i].top - this.artboard.artboardRect[1] + y
];
}
this.artboard.artboardRect = [x, y, x + this.width, y - this.height];
}
}
Copy link to clipboard
Copied
Hi @Siev, I can confirm I see the same behaviour of the undo not working on Point Text (AI 26.2.1, Mac OS 12.3.1).
@Sergey Osokin, good to know, thanks for the workaround! I had a quick play and noticed that the bug is tied to the
doc.selectObjectsOnActiveArtboard();
method. If you don't use that, the undo works fine. Weird.
- Mark
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Or use redraw() method after zeroing the selection. It worked, too.
app.selection = [];
redraw();
Copy link to clipboard
Copied
Hi @Sergey Osokin I can confirm both those workarounds solve the problem for me, too. Good work!