Script location of object

Community Beginner ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Hi, can I write a jsx script, in ExtendScript toolkit, where I can select an object by name and Illustrator writes me his location, x and y values, in a log or popup message? Thanks in advance

 
 
 
 
TOPICS
How to, Scripting, Tools

Views

109

Likes

Translate

Translate

Report

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

Adobe Community Professional , Mar 11, 2021 Mar 11, 2021
Updated version of @Silly-V by accessing the item by name #target illustrator function test() { var doc = app.activeDocument; try { var item = doc.pageItems['item_name']; //item_name is the name of the item that you see in Layers panel alert("X: " + item.top + ", Y: " + item.left); } catch (e) { alert("No item with name 'item_name' exists") } }; test();

Likes

Translate

Translate
Engaged ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Quick answer is something like:

var item = selection[0]; // first item of selection
alert(item.position);

 

Likes

Translate

Translate

Report

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
Enthusiast ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Or do you mean something like this?  (Put your item's name between the quotation marks.)

alert( app.activeDocument.pageItems["your item's name"].position );

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Here's my version of the same thing.
#target illustrator

function test(){

  var doc = app.activeDocument;

  var item = doc.selection[0];
  alert("X: " + item.top + ", Y: " + item.left);

};

test();

Silly-V_0-1615497852135.png

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

LATEST

Updated version of @Silly-V by accessing the item by name

 

#target illustrator
function test() {
    var doc = app.activeDocument;
    try {
        var item = doc.pageItems['item_name']; //item_name is the name of the item that you see in Layers panel
        alert("X: " + item.top + ", Y: " + item.left);
    } catch (e) {
        alert("No item with name 'item_name' exists")
    }
};

test();

 

Best regards

Likes

Translate

Translate

Report

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