Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


How to always use artboard coordinates not

Explorer ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

Hello,

I am using this script part for some testing.

var myDoc = app.activeDocument;
var myLine = myDoc.pathItems.add();
//set stroked to true so we can see the path
myLine.stroked = true;
myLine.setEntirePath([[10, 10], [100, 100], [200, 200]]);

And everything works fine with the new open document. 

But when I open some old file .eps .pdf etc. Then starts doing nonsense.

I notice that in an old file is artboard coordinates are different than global coordinates, and this script create line according to global coordinates, but I need create line according to artboard coordinates.

This is possible, to make the script use artboard coordinates, or set global to the same like artboard coordinates?

TOPICS
How to, Scripting

Views

64

Likes

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
Adobe Community Professional ,
Feb 25, 2021 Feb 25, 2021

Copy link to clipboard

Copied

Some files dont' have an 'artboard' and one gets created for you as per default behavior but the artwork bounds are the 'real' artboard. So with some fomats or file types this would be expected to produce some form of nonsense. However you still may be able to deal with those issues using the properties Document.rulerOrigin and Document.pageOrigin. (I do not know the difference between these, especially since Ai can have multiple artboards, which page's origin is it?) Try alerting those and the differences between the coordinates of those and your 0-points in documents which produce your expected results and the unexpected results. If you determine a rhyme or reason for why some documents may have a different origin, then you can craft a function which either changes the origin(s) or offsets your placed shapes' coordinates to produce the expected placement. Here is also another thread which mentions the origins, you can see some code people used - although it doesn't explain what the difference between pageOrigin and rulerOrigin is, I don't think. https://community.adobe.com/t5/illustrator/change-origin-of-artboard-rulers/m-p/9797681

Likes

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
Enthusiast ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

LATEST

Also, please try this:

 

var items = selection;
var item = items[0];

var p1 = item.position;

alert (p1);

var p2 = app.activeDocument.convertCoordinate(p1, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);

alert (p2);

 

 

It will convert a point, eg. [100,50] between document coordinates and artboard coordinates. (Swap them around to go backwards.) Remember each artboard has it's own coordinates, so it really matters which is the active artboard. You can set the active artboard with app.activeDocument.artboards.setActiveArtboardIndex(index).

 

Edit: I should have mentioned... have a look at app.coordinatesystem. It should tell you which coordinate system is in use.

 

- Mark

Likes

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