• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Move RulerOrigin to specific location

Explorer ,
Jan 23, 2019 Jan 23, 2019

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.

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 24, 2019 Jan 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;

// a

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 24, 2019 Jan 24, 2019

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2019 Jan 26, 2019

Copy link to clipboard

Copied

Fab, thanks Carlos!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2019 Jan 28, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2019 Jan 28, 2019

Copy link to clipboard

Copied

Hi Uwe, I meant the actual Ruler position does not update unless you're using "Global Rulers".

rulerOrigin.PNG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 28, 2019 Jan 28, 2019

Copy link to clipboard

Copied

LATEST

Hi Carlos,

yes. Thank you for clarification.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

if (documents.length > 0) {

    var doc = app.activeDocument;

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

}

have fun

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines