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!
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");
};
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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 )