Copy link to clipboard
Copied
Hi,
Apologies if this is obvious, but I just can't work it our after four hours of web searching and trial and error.
I see there was a bug submission - https://illustrator.uservoice.com/forums/601447-illustrator-bugs/suggestions/32003332-bug-when-setti... - but I'm not sure if that has been fixed in subsequent versions...
I'm transitioning (it's very trendy these days) from Mac to PC so having to rewrite all my AppleScripts, which I was moderately good at, so I thought JS would be easy - but I just can't get my head around the Germanic-compound-words-syntax of it. Old dog, new tricks life crisis. Meh.
Anyway, my problem is I have a script that changes the Ruler Origin, and Illy tells me it has changed it (see below), but in the physical app, nothing has changed:-
#target illustrator
var aDoc = app.activeDocument
//first pass
aDoc.rulerOrigin = [0,0];
aDoc.artboards.rulerOrigin = [0,0];
$.writeln ("Starting origin 0,0")
$.writeln ("Ruler Origin " + (aDoc.rulerOrigin));
$.writeln ("Page Origin " + (aDoc.pageOrigin));
$.writeln ("Ruler Origin (artboards) " + (aDoc.artboards[0].rulerOrigin));
$.writeln ("Artboard size " + (aDoc.artboards[0].artboardRect));
//second pass
aDoc.rulerOrigin = [100,100];
aDoc.artboards.rulerOrigin = [100,100];
$.writeln (" ")
$.writeln ("Starting origin 100,100")
$.writeln ("Ruler Origin " + (aDoc.rulerOrigin));
$.writeln ("Page Origin " + (aDoc.pageOrigin));
$.writeln ("Ruler Origin (artboards) " + (aDoc.artboards[0].rulerOrigin));
$.writeln ("Artboard size " + (aDoc.artboards[0].artboardRect));
/*
RESULTS:
(all dimensions in points, artboard is 200x400)
First pass:
Starting origin 0,0
Ruler Origin 0,0
Page Origin -206,-196
Ruler Origin (artboards) 0,0
Artboard size 0,400,200,0
Second pass:
Starting origin 100,100
Ruler Origin 100,100
Page Origin -306,-296
Ruler Origin (artboards) 0,0
Artboard size -100,300,100,-100
*/
So the "page" ruler origin is changing, but the "artboards" ruler origin is not.
I'm assuming I need to make use of app.coordinateSystem, CoordinateSystem.DOCUMENTCOORDINATESYSTEM and CoordinateSystem.ARTBOARDCOORDINATESYSTEM, but not sure how.
What I'm trying to do is select a path point (anchor) and have the rulerOrigin moved to that anchor (so that anchor x,y becomes 0,0).
Thanks for your help, Em.
check the below snippet, it doesn't seem to work on the UI but it does move the origin to selection left/top. To see it in action, change to Global rulers manually.
select something before running
...var idoc = app.activeDocument;
var sel = idoc.selection[0];
var ro = idoc.rulerOrigin;
var cs = app.coordinateSystem;
app.coordinateSystem = CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
var posx = sel.position[0];
var posy = sel.position[1];
idoc.rulerOrigin = [posx+ro[0], posy+ro[1]];
//idoc.rulerOrigin = ro;
// a
Copy link to clipboard
Copied
check the below snippet, it doesn't seem to work on the UI but it does move the origin to selection left/top. To see it in action, change to Global rulers manually.
select something before running
var idoc = app.activeDocument;
var sel = idoc.selection[0];
var ro = idoc.rulerOrigin;
var cs = app.coordinateSystem;
app.coordinateSystem = CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
var posx = sel.position[0];
var posy = sel.position[1];
idoc.rulerOrigin = [posx+ro[0], posy+ro[1]];
//idoc.rulerOrigin = ro;
// app.coordinateSystem = cs;
Copy link to clipboard
Copied
Fab, thanks Carlos!
Copy link to clipboard
Copied
CarlosCanto wrote
… it doesn't seem to work on the UI but it does move the origin to selection left/top.
Hi Carlos,
why do you think that it does not work on the UI?
Just tested your snippet with Illustrator CC 2019.
The ruler origin is actually moving after running the snippet from the ESTK.
What's not working instantly is showing the new and updated coordinates in the Properties panel.
However, I changed your snippet just a bit and with the version below the new coordinates are updated in the Properties panel. Don't ask me why this is working.
var idoc = app.activeDocument;
var selection = idoc.selection; // Just added that step.
var sel = selection[0];
var ro = idoc.rulerOrigin;
var cs = app.coordinateSystem;
app.coordinateSystem = CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
var posx = sel.position[0];
var posy = sel.position[1];
idoc.rulerOrigin = [posx+ro[0], posy+ro[1]];
app.coordinateSystem = cs;
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe, I meant the actual Ruler position does not update unless you're using "Global Rulers".
Copy link to clipboard
Copied
Hi Carlos,
yes. Thank you for clarification.
Regards,
Uwe
Copy link to clipboard
Copied
if (documents.length > 0) {
var doc = app.activeDocument;
doc.rulerOrigin = [50, 50]; // 50 pt, 50 pt
}
have fun