Copy link to clipboard
Copied
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
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'));
}());
Copy link to clipboard
Copied
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'));
}());
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
var textFramItem = doc.textFrames.add();
better: don't use a class name for your variables
var aTF = doc.textFrames.add();
Copy link to clipboard
Copied
Hi pixxxel schubser​, Still I am not able to get the output. I want to get the all these in Pixel.
Is that Possible?
OMOTI​ Can you please help me to overcome from the error. I have mentioned the screenshot in above post already.
Copy link to clipboard
Copied
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.
- Width
- Height
- 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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now