Copy link to clipboard
Copied
Hey guys,
I am trying to reset the ruler of Illustrator to a given (x, y) position from an image.
From what I can see I have this:
function ResetOrigins(doc, bounds) {
preferences.setBooleanPreference("isRulerOriginTopLeft", true);
preferences.setBooleanPreference("isRulerIn4thQuad", true);
var abd = doc.artboards[0];
abd.rulerOrigin = new Array(bounds[0], bounds[1]);
doc.rulerOrigin = new Array(bounds[0], bounds[1]);
}
var lay = activeDocument.layers.getByName("background");
var img = lay.pageItems[0];
ResetOrigins(app.activeDocument, img.position);
But the Y doesn't seem to be working as intended and reset it to the Image's position.
Hi @JSuX, There are some little gotcha's here.
First: you are better off not changing the document's rulerOrigin. If you do, your bounds will also have to be adjusted by the same amount or they will not match your item's bounds anymore. I have commented this line out for now.
Second: Illustrator is a bit confusing about which way the Y axis ascends. In some coordinate systems or contexts it goes up and others down. I have never bothered to understand which is which because, in practice, I'm
...Copy link to clipboard
Copied
Hi @JSuX, There are some little gotcha's here.
First: you are better off not changing the document's rulerOrigin. If you do, your bounds will also have to be adjusted by the same amount or they will not match your item's bounds anymore. I have commented this line out for now.
Second: Illustrator is a bit confusing about which way the Y axis ascends. In some coordinate systems or contexts it goes up and others down. I have never bothered to understand which is which because, in practice, I'm used to flipping the Y when it goes wrong. Which I did here.
Let me know if it works for you.
- Mark
function ResetOrigins(doc, bounds) {
preferences.setBooleanPreference("isRulerOriginTopLeft", true);
preferences.setBooleanPreference("isRulerIn4thQuad", true);
var abd = doc.artboards[0];
var newOrigin = [bounds[0], bounds[1]];
// we want the new ruler position expressed
// in the artboard coordinate system:
newOrigin = doc.convertCoordinate(newOrigin, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);
// if you change doc's rulerOrigin,
// the bounds will now be wrong!
// If you really need to change,
// you can calculate the relative change
// and apply that to the bounds var.
// I've commented this out for now:
// doc.rulerOrigin = [0, 0];
// the Y axis for the artboard is flipped!
abd.rulerOrigin = [newOrigin[0], -newOrigin[1]];
}
var lay = activeDocument.layers.getByName("background");
var img = lay.pageItems[0];
ResetOrigins(app.activeDocument, img.position);
Copy link to clipboard
Copied
This seems to work, thank you for taking the time, @m1b
Copy link to clipboard
Copied
Second: Illustrator is a bit confusing about which way the Y axis ascends. In some coordinate systems or contexts it goes up and others down. I have never bothered to understand which is which because, in practice, I'm used to flipping the Y when it goes wrong. Which I did here.
- Mark
By @m1b
Mark, if I remember correctly, when the Y axis changed direction in CS5, new documents created via a script would behave the way they used to (Y going up). When the script manipulated active documents, Y would increase going down.
Regardless, I always do what you do, I switch direction myself if it goes the wrong way.
Copy link to clipboard
Copied
@m1b , @CarlosCanto ,
How can you make the Y direction go down? I've been trying to adjust this now since I was able to fix the rulers, but the Y param of positions seems to be going from bottom to top.
Copy link to clipboard
Copied
I doubt that you can change the direction. I think you just need to go with how it is. And like Carlos and I said, if you code goes the wrong way, flip the sign on Y. In other words, you change the direction in your code. It's weird, but I've never found it especially frustrating.
- Mark
Copy link to clipboard
Copied
you can change the Y direction. The default is positive Y going down. If in your script Y goes up these lines are probably the cause
preferences.setBooleanPreference("isRulerOriginTopLeft", true);
preferences.setBooleanPreference("isRulerIn4thQuad", true);
check this old thread for more info
Copy link to clipboard
Copied
Thanks @CarlosCanto well now I'm thinking of all my scripts that don't check for this preference before positioning! Haha. Hee. Eeeh.
- Mark
Copy link to clipboard
Copied
Hi Mark, there shouldn't be a need to check, it's been long enough to assume the preference has not been changed by the user to match CS4 coordinate system. But there's a very slim chance nonetheless 🙂
Copy link to clipboard
Copied
Hopefully! Well @JSuX @if you change the preference you will know why some scripts may move things the wrong way.
Copy link to clipboard
Copied
I don't think that those two settings do anything at all
preferences.setBooleanPreference("isRulerOriginTopLeft", true);
preferences.setBooleanPreference("isRulerIn4thQuad", true);
What I am trying to achieve is after placing the (0, 0) on an image's position, for the X to increase from left to right, and for the Y to increase from top to bottom. This should also be reflected in the API when calling an (for example) Image's position. At the moment, no matter how you play around with the two settings, after you change the (0, 0) to be at the top, Y is always increasing from bottom to top.
I guess the alternative of just using the negative Y is all that's left
Find more inspiration, events, and resources on the new Adobe Community
Explore Now