Skip to main content
January 24, 2019
Answered

Move RulerOrigin to specific location

  • January 24, 2019
  • 2 replies
  • 1649 views

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-setting-artboard-ruler-origins - 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.

This topic has been closed for replies.
Correct answer CarlosCanto

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;

2 replies

Inspiring
January 25, 2019

if (documents.length > 0) {

    var doc = app.activeDocument;

    doc.rulerOrigin = [50, 50]; // 50 pt, 50 pt

}

have fun

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
January 24, 2019

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;

January 26, 2019

Fab, thanks Carlos!