Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InDesign javascript scripting

Status
Not open for further replies.

duncdude

Programmer
Jul 28, 2003
1,979
GB
Hi

I wondered whether anyone could help me do the following:

I need to write a Javascript script to iterate through all the text frames of all the pages of the active document

i.e.

Code:
for (p=0; p < app.activeDocument.pages; p++) {
  for (t=0; t < app.activeDocument.pages.textFrames) {
    alert( p,t );
  }
}

This should be very simple - i am just not quite getting my head around the DOM

Can anyone help me?

Many thanks
Duncan

Kind Regards
Duncan
 
((app.documents.length != 0) && (app.selection.length != 0)) {
myDoc = app.activeDocument;

Does that help?
 
Thank you Eugene

This is what i have managed so far:

Code:
var mydoc = app.activeDocument;

var concat = "Duncan => InDesign / javascript automation project\n";

for( var p = 0; p < mydoc.pages.length; p++ ) {
    
	for (var j=0; j < mydoc.pages[p].textFrames.length; j++) {
		
		var X = parseInt( mydoc.pages[p].textFrames[j].geometricBounds[1] );
		var Y = parseInt( mydoc.pages[p].textFrames[j].geometricBounds[0] );
				
		concat += p + "\t" + Y + "\t" + X + "\t" + mydoc.pages[p].textFrames[j].contents + "\n";
		
	}
}

alert( concat );

This loops through all the pages, from the first to the last, and while it is on the page it loops through all the text boxes, returning the page number, x & y coords and the content (and a final new line)

However, i have noticed that it is ignoring grouped items - i will need to improve the script to ungroup everything before any attempt at extraction of all the text - can anyone help me with this?

Finally i need to set the rulers at the 0,0 positon before i start - again, can anyone help?

I have posted the code should anyone wish to make use of it

I hope to finally create a text extraction routine that can truly make sense of items randomly placed on the page - the utilities i have seen just don't work for me as they can return the text in a very awkward order. Basically they don't really manage to sort the items on the page in which i would like them returned

I hope this all makes sense!

Regards
Duncan

Kind Regards
Duncan
 
I think you need professional help. The one person I'm sure could help you with this, and I only know him through his reputation and that is the magnificent Dave Saunders. Perhaps you could look him up and email him your problem, he could charge you for it though, but that's between him and you, should you choose to go that route or if anyone else can offer some light on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top