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

Script for X Y coordinates of All Text Objects on a Layer

Explorer ,
Sep 17, 2019 Sep 17, 2019

Copy link to clipboard

Copied

Is there a script that I can run that will give me all of the X Y coordinates of all the text objects on a layer? I need to make bluebrints of hundreds of documents including X Y coordinates of all the text objects, and a script would be a nice way to cut through it!

TOPICS
Scripting

Views

1.4K

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
Engaged ,
Sep 17, 2019 Sep 17, 2019

Copy link to clipboard

Copied

Hi, davidc69929907

 

Is it a script like the one below?

 

var doc = app.activeDocument;
var txf = doc.textFrames;

for(var i=0, len=txf.length; i<len; i++) {
  alert(getInfo(txf[i]));
}

function getInfo(txfObj) {
  var res = [];
  res.push("nombre: "+txfObj.parentPage.name);
  res.push("X1: "+txfObj.visibleBounds[1]);
  res.push("Y1: "+txfObj.visibleBounds[0]);
  return res.join("\r");
};

 

Yusuke S.

Votes

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
Explorer ,
Sep 18, 2019 Sep 18, 2019

Copy link to clipboard

Copied

While this does output some variables, it doesn't let me know which ones, or in what order. I can't seem to find any useful pattern from the output that allows me to use the results the way I need them What I need is to output the X/Y coordinates of every individual text object on a specific layer and have some sort of reference as to that that text object was, for instance it repeats the text within the box and also outputs the X/Y coordinates for that box.

Votes

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
Community Expert ,
Sep 18, 2019 Sep 18, 2019

Copy link to clipboard

Copied

LATEST

Hi David,

you are a bit vague what you like to accomplish.

Do you already know how your sorted output should be organized?

If not it will be impossible to hint to an algorithm that will do what you want.

 

If your problem is how to access "text objects" in InDesign then we certainly can help.

 

1. Perhaps you do not want to access InDesign "text objects". In InDesign text objects have no coordinates.

They live as texts[0] objects in story objects and table cells. Also in notes objects and some other obsure objects.

E.g. see the Document Object Model documentation compiled by Gregor Fellenz:

https://www.indesignjs.de/extendscriptAPI/indesign14/#Text.html

 

2. What you perhaps need are all text frames of a document. Plus perhaps all objects that bear text paths. But I'm not sure about that. How about text contents of tables? Text frames that are grouped? Text frames that are anchored to text? Text frames that may be pasted inside graphic frames? Text in overset? Text frames in overset?

You see, depending on the layout and contents of an InDesign document it could become complicated very fast.

 

One method to gather all text frames and text paths of a document and to write them to an array for further inspection would be to get all Story objects of a document and their textContainers array. All the textContainers arrays of all stories concatenated should give a fine start for a sorting algorithm that can sort by coordinates, by page, by layer, by contents, by (whatever) a text frame or text path can offer as property.

 

https://www.indesignjs.de/extendscriptAPI/indesign14/#Story.html

https://www.indesignjs.de/extendscriptAPI/indesign14/#TextFrame.html

 

To fetch all text containers ( text frames and text paths ) of a document you could work like that:

 

var allTextContainersArray = [];

var allStories = app.documents[0].stories.everyItem().getElements();
var allStoriesLength = allStories.length;

for( var n=0; n<allStoriesLength; n++ )
{
	allTextContainersArray = 
	allTextContainersArray.concat( allStories[n].textContainers );
};

// Then loop the allTextContainersArray
// Be aware that text paths have no coordinates, also text frames in overset text.

 

Regards,
Uwe Laubender

( ACP )

 

 

 

 

Votes

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