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

Position object in Extendscript Toolkit not making sense.

Explorer ,
Sep 28, 2018 Sep 28, 2018

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.

TOPICS
Scripting
1.8K
Translate
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
Adobe
Community Expert ,
Sep 28, 2018 Sep 28, 2018

Please check the artboard zero point and or the document origin

Translate
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 ,
Sep 28, 2018 Sep 28, 2018

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!"

Capture.JPG

Translate
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 ,
Sep 28, 2018 Sep 28, 2018

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);

Translate
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 ,
Sep 28, 2018 Sep 28, 2018

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.

Translate
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
Valorous Hero ,
Sep 28, 2018 Sep 28, 2018

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.

Translate
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 ,
Sep 29, 2018 Sep 29, 2018

Sooo... "Sometimes" doesn't seem like a very good thing for writing scripts.

Translate
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 ,
Sep 29, 2018 Sep 29, 2018

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)?

Translate
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 ,
Sep 29, 2018 Sep 29, 2018

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;

Translate
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 ,
Oct 01, 2018 Oct 01, 2018

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.

Translate
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 ,
Oct 01, 2018 Oct 01, 2018

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?

Translate
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 ,
Oct 01, 2018 Oct 01, 2018

Hi, do you think you can share the file to analyze?

Translate
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 ,
Oct 02, 2018 Oct 02, 2018
Translate
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 ,
Oct 06, 2018 Oct 06, 2018
LATEST

Carlos, did that work for you?

Translate
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