Copy link to clipboard
Copied
I have an object selected in Illustrator.
It's X and Y are 264 and 625.
If I look at the properties of "position" in the data browser it says 102 for left and 906 for top.
If I set the selected object's top to 100 it will jump all the way down and off the artboard to 1431.101.
Any idea on how this is supposed to work? I mean it seems straightforward, the width and height are perfect, but the location is not.
Copy link to clipboard
Copied
Please check the artboard zero point and or the document origin
Copy link to clipboard
Copied
I have done so.
I will admit that artboard (a template I've been having) is different but even a new artboard does wacky things.
Here is the basic "hello world script and it's results":
var myDocument = app.documents.add();
var myTextFrame = myDocument.textFrames.add();
myTextFrame.position = [200,200];
myTextFrame.contents = "Hello World!"
Copy link to clipboard
Copied
Do you use Artboard rulers or Global rulers?
var aDoc = app.activeDocument;
alert ("ruler origin "+aDoc.rulerOrigin);
alert ("page origin "+aDoc.pageOrigin);
alert ("artboard[0] ruler origin "+aDoc.artboards[0].rulerOrigin);
Copy link to clipboard
Copied
They all come up saying 0,0
Ruler Origin 0,0
Page Origin 0,0
artboard[0] ruler origin 0,0
My system is pretty default.
Copy link to clipboard
Copied
Sometimes I have to set the ruler origin to [0, -doc.height] or something like that.
And one very frustrating time I've had some art to paste into somebody's pre-made template which didn't seem to respond at all to the ruler origin and pasted the art half-way above every time. So, I had to just 'go with the flow' and do the next best thing, which is to create a rectangle the size of the target document in previous document, then duplicate it over in order to measure the y difference between where this rectangle landed and the target doc's artboard's top coordinates.
Copy link to clipboard
Copied
Sooo... "Sometimes" doesn't seem like a very good thing for writing scripts.
Copy link to clipboard
Copied
Pixxxel,
I was running the above script on a new blank doc.
I just ran it on the template that I really need to use this on and it comes up with something drastically different:
Ruler Origin 162, -161.727295914426
Page Origin -270,338
artboard[0] ruler origin 0, -0.000500000001
Why would that be and how can I "restore" it back and save it to my template (ait file)?
Copy link to clipboard
Copied
in this last document you posted, is your origin at (0,0) in the User Interface?
if not, you can restore it
aDoc.rulerOrigin = 0;
aDoc.pageOrigin = 0;
getting the right measurements is a bit complicated because Adobe changed the ruler origin from 1st quadrant (positive Y going up) to 4th quadrant (positive Y going down) back in CS5. On top of that, to avoid breaking existing scripts, new documents created by a script, would continue to use the old system positive Y going up (from bottom/left). Existing documents would use the new system, positive Y going down (from top/left).
to get consistent results, use artboard rulers, all values would be relative to the top/left corner of the artboard.
add this line at the beginning of your script
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
Copy link to clipboard
Copied
Ok... couple of things.
I am using rulers and they show 0,0 as the top left of the doc.
Are you saying that the new CS5+ method has the vertical (y axis) going negative as you move down from the top? Because that is my experience on blank new files.
Now regarding my already existing template.
I added that line of code and the only thing that change from my last reported results is:
Page Origin -108,-1193.1006
Other than that things are still those same odd coordinances.
Now, if I add that bit of code to the top of my "hello world" new doc with 200,-200 coordinance it does act correctly.
If I don't use that code the new doc puts the "Hello World" at 200,992?!
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
Code below (as is, puts the text at 200,200 on ruler... but if I comment out that top line I get 200,992 as the place the text goes)
var myDocument = app.documents.add();
var myTextFrame = myDocument.textFrames.add();
myTextFrame.position = [200,-200];
myTextFrame.contents = "Hello World!"
I'm really confused.
Copy link to clipboard
Copied
Another curiosity,
I created this script:
alert(app.coordinateSystem);
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
alert(app.coordinateSystem);
It shows that it was using the "DocumentCoordinateSystem", then shows that it was changed.
But when I run it a second time, it still shows the first alert as DocumentCoordinateSystem.
Does the script not change that to the document permanently?
Copy link to clipboard
Copied
Hi, do you think you can share the file to analyze?
Copy link to clipboard
Copied
Can't figure out a better way to share it, but yeah it's simple enough.https://drive.google.com/open?id=1q-uj0bh4uibPlGiBmyJ9-7OFBAjarT04
https://drive.google.com/open?id=1q-uj0bh4uibPlGiBmyJ9-7OFBAjarT04
Copy link to clipboard
Copied
Carlos, did that work for you?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now