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

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

Advocate ,
Feb 11, 2018 Feb 11, 2018

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.

X-Y_Poition.png

thx,
csm_phil

TOPICS
Scripting
7.6K
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

correct answers 1 Correct answer

Contributor , Feb 11, 2018 Feb 11, 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'));

}());

Translate
Adobe
Contributor ,
Feb 11, 2018 Feb 11, 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'));

}());

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
Advocate ,
Feb 11, 2018 Feb 11, 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

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
New Here ,
Jun 07, 2018 Jun 07, 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.

Cordinates.PNG

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
Contributor ,
Jun 08, 2018 Jun 08, 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;

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
New Here ,
Jun 09, 2018 Jun 09, 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;

Error_Script.PNG

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

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 ,
Jun 10, 2018 Jun 10, 2018

var textFramItem = doc.textFrames.add();

better: don't use a class name for your variables

var aTF = doc.textFrames.add();

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
New Here ,
Jun 11, 2018 Jun 11, 2018

Hi pixxxel schubser​, Still I am not able to get the output. I want to get the all these in Pixel.

  1. Width
  2. Height
  3. XY Coordinates

Is that Possible?

OMOTI​ Can you please help me to overcome from the error. I have mentioned the screenshot in above post already.

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 ,
Jun 11, 2018 Jun 11, 2018
LATEST

kulchandran  schrieb

… OMOTI  Can you please help me to overcome from the error. I have mentioned the screenshot in above post already.

I'm not OMOTI. But my previous post should solve the error (change line #21 to):

pixxxel schubser​ schrieb

var textFramItem = doc.textFrames.add();

----------------------------

kulchandran  schrieb

Hi pixxxel schubser, Still I am not able to get the output. I want to get the all these in Pixel.

  1. Width
  2. Height
  3. XY Coordinates

Is that Possible?

Sure. But at first in mm and now in px? What do you really want?

But anyway

// draw a simple rectangle and run the script

(function () {

    var doc = app.activeDocument;

    var pos = doc.pathItems[0].position;

    alert('1)    X: ' + pos[0] + ', Y: ' + pos[1]*-1 );  // always in points

    alert('2)    X: ' + (pos[0]*0.3527778).toFixed(2) + ' mm, Y: ' + (pos[1]*-0.3527778).toFixed(2) + ' mm'); // in mm with unit

    alert('3)    X: ' + new UnitValue(pos[0], 'pt').as('mm').toFixed(2) + ', Y: ' + (new UnitValue(pos[1]*-1, 'pt')).as('mm').toFixed(2) );  // in mm value

    alert('4)    X: ' + new UnitValue(pos[0], 'pt').as('px').toFixed(2) + ', Y: ' + (new UnitValue(pos[1]*-1, 'pt')).as('px').toFixed(2) );  // px and pt  in Illu are the same

   

    alert('5)    width: ' + doc.pathItems[0].width + ', height: ' + doc.pathItems[0].height );  // always in points

}());

Have fun

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