Copy link to clipboard
Copied
In the document, the origin of coordinates corresponds to the upper left border of the artboard. That is, the coordinates increase vertically downwards and horizontally to the right. But when I place text in the specified coordinates, for example:
textFrame.position = [100, 100];
then the placed object has completely different coordinates than those I specified.
How can I fix this?
1 Correct answer
Hi @andyf65867865, just further to what @renél80416020 already showed you, have a look at this experiment:
I start with a new document which has one 100x100pt artboard (see attached demo.pdf), and run this script:
/**
* Experiment showing positions using different
* coordinate systems and ruler origins.
*
* Note that the `position` of each of the four
* triangles is set to [0,0].
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/how-to-place-an-object
...
Explore related tutorials & articles
Copy link to clipboard
Copied
Bonjour!
Quadrant
les quadrants sont numérotés de 1 à 4 (de I à IV) dans le sens direct (anti-horaire), à partir de celui situé dans le quart de plan supérieur de droite.
Sur Illustrator à partir de la version CS5, le système de coordonnées est passé au quatrième quadrant et non plus au premier pour les versions antérieures.
En ce déplaçant vers le bas, on augmente la valeur des ordonnées, et en se déplaçant vers la droite, on augmente celle des abscisses.
Il en est de même dans de nombreux logiciels ainsi que sur les page Web.
Le changement de système de coordonnées ne s’applique pas à la création de scripts, pour les scripts on reste au premier quadrant.
vous pouvez ainsi conserver d’anciens scripts. Toutefois, lorsque vous transformez des objets à l’aide de scripts, la valeur de l’ordonnée diffère de la valeur que vous avez définie dans l’interface utilisateur d’Illustrator. Par exemple, si vous appliquez un déplacement de 10 points sur l’axe des ordonnées, pour reproduire le même mouvement à l’aide de scripts, appliquez une transformation de -10 points sur l’axe des ordonnées.
René
Dans un script l’origine est l’origine des règles globales "rulerOrigin" et non pas celle du plan de travail actif.
Pour faire des testes...
// JavaScript Document
// triangle
alert(activeDocument.rulerOrigin);
//activeDocument.rulerOrigin = [0,0];
var ligne = activeDocument.pathItems.add();
ligne.name = "triangle";
ligne.setEntirePath([[12,12],[60,60],[70,30]]);
Copy link to clipboard
Copied
Hi @andyf65867865, just further to what @renél80416020 already showed you, have a look at this experiment:
I start with a new document which has one 100x100pt artboard (see attached demo.pdf), and run this script:
/**
* Experiment showing positions using different
* coordinate systems and ruler origins.
*
* Note that the `position` of each of the four
* triangles is set to [0,0].
* @author m1b
* @discussion https://community.adobe.com/t5/illustrator-discussions/how-to-place-an-object-at-specified-document-coordinates/m-p/14897332
*/
(function () {
var doc = app.activeDocument,
layer = doc.activeLayer,
artboard = doc.artboards[0];
// make some triangles just for showing positions
var docTriangle = drawTriangle(layer),
docTriangleZeroed = drawTriangle(layer),
artboardTriangle = drawTriangle(layer),
artboardTriangleZeroed = drawTriangle(layer);
// give colors to distinguish
docTriangle.fillColor = doc.swatches[4].color;
docTriangleZeroed.fillColor = doc.swatches[5].color;
artboardTriangle.fillColor = doc.swatches[6].color;
artboardTriangleZeroed.fillColor = doc.swatches[7].color;
// keep these so we can clean up afterwards
var originalCoordinateSystem = app.coordinateSystem,
originalDocRulerOrigin = doc.rulerOrigin,
originalArtboardRulerOrigin = artboard.rulerOrigin;
// position the document coordinates triangle
app.coordinateSystem = CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
doc.rulerOrigin = [30, 20];
docTriangle.position = [0, 0];
// position the artboard coordinates triangle
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
artboard.rulerOrigin = [30, 20];
artboardTriangle.position = [0, 0];
// position the document coordinates (zeroed) triangle
app.coordinateSystem = CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
doc.rulerOrigin = [0, 0];
docTriangleZeroed.position = [0, 0];
// position the artboard coordinates (zeroed) triangle
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
artboard.rulerOrigin = [0, 0];
artboardTriangleZeroed.position = [0, 0];
// clean up (leave document settings how we found it)
app.coordinateSystem = originalCoordinateSystem;
doc.rulerOrigin = originalDocRulerOrigin;
artboard.rulerOrigin = originalArtboardRulerOrigin;
})();
/**
* Makes a right-angle triangle path item.
* @param {Document|Layer|GroupItem} container - where to put triangle.
* @param {Number} size - the size, in points, of the triangle.
* @returns {PathItem}
*/
function drawTriangle(container, size) {
size = size || 10;
var triangle = container.pathItems.add();
// note y-axis goes negative in Illustrator
triangle.setEntirePath([[0, 0], [size, 0], [0, -size]]);
triangle.closed = true;
triangle.filled = true;
triangle.stroked = false;
return triangle;
};
I get this result:
If you have a careful look at that you will see that artboard coordinates go from topleft [0,0] with positive Y down, but document coordinates go from bottom left [0,0] with positive Y up. Note that each time I have set the position of each triangle to [0,0], so the change in positions is solely due to coordinateSystem and rulerOrigin.
In your own scripts, my suggestion is—just as my script does here—to explicitly control both the app.coordinateSystem, and either the doc.rulerOrigin, or the artboard.rulerOrigin (depending on the coordinateSystem you choose). And don't forget to clean up afterwards!
- Mark

