How to get the position of a selected PathItem Illustrator object in pixels using?

I have a simple problem, but I can’t find a way around it: My PathItem and Illustrator indicate that it is in position (781px, 250px).

How can I get these values ​​in jsx?

I noticed that PathItem inherits the position property from PageItem , and the position is a Point , but when I try to print the values, I get undefined:

$.writeln(app.activeDocument.selection[0].position.x);

If I do not specify .x from the line above, I will get it in the console:

521,510

What are these meanings? Are they x, y coordinates? Which part? How to convert to pixels?

Why can't I access the properties x, y / top, left?

I am using Illustrator CS5.

+4
3

@bradido , .

, Illustrator : . , - . Y .

, app.coordinateSystem, , , (doc.convertCoordinate), .

, , x, y Illustrator, ActionScript ( ):

var doc = app.activeDocument;
var hasDocCoords = app.coordinateSystem == CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
var sel = doc.selection;
var selLen = sel.length;
var code = 'var pointsOnMap:Vector.<Vec> = Vector.<Vec>([';
for(var i = 0 ; i < selLen ; i++){
    var pos = hasDocCoords ? doc.convertCoordinate (sel[i].position, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM) : sel[i].position;
    code += 'new Vec('+(pos[0] + (sel[i].width * .5)).toFixed(2) + ' , ' + Math.abs((pos[1] - (sel[i].height*.5))).toFixed(2);//Math.abs(pos-height) - same for both coord systems ?
    if(i < selLen-1) code +=  '),';
    else                 code +=  ')]);pointsOnMap.fixed=true;';
 }
$.writeln(code);

Adobe.

+5

, . , :

function convertPoint(item){
    var pos = doc.convertCoordinate (item.position, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);
    pos[0] += item.width * 0.5;
    pos[1] = Math.abs(pos[1] - (item.height * 0.5));
    return pos;
}

. : .

+2

A point is an array of positions. So, to get the coordinates:

x = app.activeDocument.selection[0].position[0];

y = app.activeDocument.selection[0].position[1];
+1
source

Source: https://habr.com/ru/post/1788748/


All Articles