Skip to main content
csm_phil
Legend
February 11, 2018
Answered

How to get the Selected Items X, Y position with MM value

  • February 11, 2018
  • 2 replies
  • 7652 views

Hi All,

In Illustrator CS5 version how to get the X, Y position in Millimeter.

In InDesign I can easily get the X,Y position also I can change the ruler origin easily. Illustrator I tried but I failed. Could you please any one guide me.

thx,
csm_phil

This topic has been closed for replies.
Correct answer OMOTI

Hi, csm_phil.

UnitValue class can convert units. Please try this.

(function () {

    var doc = app.activeDocument,

        position = doc.pathItems[0].position;

    $.writeln('X: ' + new UnitValue(position[0], 'pt').as('mm') + ', Y: ' + new UnitValue(position[1], 'pt').as('mm'));

}());

2 replies

Participant
June 7, 2018

Hi Everyone,


I want to get the Position(X,Y) coordinates and Dimension of multiple selected items (mostly rectangles) on top of rectangles or Inside the rectangle. This is the output I wanted to get. Can we get this by using Script. Please help me if you know how to get this output.

Thanks in Advance.

OMOTI
Inspiring
June 8, 2018

Hi, kulchandran.

This is my favorite reference Please read this.

Illustrator Scripting | Adobe Developer Connection

I will give you an easy guide.

var doc = app.activeDocument;

var pathItem = doc.pathItems[0];

Position(X,Y) coordinates

The instance of PathItem has the property about position.

This property is Array.

X: pathItem.position[0]

Y: pathItem.position[1]

Dimension

The instance of PathItem has the property about Dimension.

These properties are Number.

Width: pathItem.width

Height: pathItem.height

When you want to get these output, use TextFrameItem.

var textFramItem = doc.textFramItems.add();

textFramItem.contents = 'Dimension: ' + pathItem.position[0] + ' x ' + pathItem.position[1] + '\n' + 'Cordinates: ' + pathItem.width + ' x ' + pathItem.height;

Participant
June 9, 2018

Hi Omoti,

Thank you for the response. Is this code compatible with Illustrator CS5? When I tried to run the script I am getting error for

"var textFramItem" as Undefined object.

I have no knowledge of scripting and I have used your code in notepad and saved the file with JSX extension "textFramItem.jsx" and got the error while running this script as you can see in the screenshot.

This is the code I have used:

var doc = app.activeDocument;

var pathItem = doc.pathItems[0];

//Position(X,Y) coordinates

//The instance of PathItem has the property about position.

//This property is Array.

X: pathItem.position[0]

Y: pathItem.position[1]

//Dimension

/*The instance of PathItem has the property about Dimension.

These properties are Number.*/

Width: pathItem.width

Height: pathItem.height

//When you want to get these output, use TextFrameItem.

var textFramItem = doc.textFramItems.add();

textFramItem.contents = 'Dimension: ' + pathItem.position[0] + ' x ' + pathItem.position[1] + '\n' + 'Cordinates: ' + pathItem.width + ' x ' + pathItem.height;

Could you please check the error and let me know what's wrong?

OMOTI
OMOTICorrect answer
Inspiring
February 12, 2018

Hi, csm_phil.

UnitValue class can convert units. Please try this.

(function () {

    var doc = app.activeDocument,

        position = doc.pathItems[0].position;

    $.writeln('X: ' + new UnitValue(position[0], 'pt').as('mm') + ', Y: ' + new UnitValue(position[1], 'pt').as('mm'));

}());

csm_phil
csm_philAuthor
Legend
February 12, 2018

Hi OMOTI,

Thank you very much your guidance, I used the position properties, but I get the improper value, now I'm clear.

thx,
csm_phil