🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
9 messages
9 total messages Started by David_Milson Sun, 08 Feb 2009 17:59
Indesign para2txtframe script problem
#1436
Author: David_Milson
Date: Sun, 08 Feb 2009 17:59
35 lines
1488 bytes
Hi,

I've adapted Peter Kahrel's script "footnotes2textframes" for my own problem.
I would like to move paragraphs from a list of figures in a single story to separate textframes. I use these later as captions for image files in a particular book.

Here is my adaptation:

function paragraphs2textframes()
{
var myDoc = app.activeDocument;

// process all
for( var i = 0; i < myDoc.stories[0].paragraphs.length; i++ ) {

// get text of paras in the story
var myParagraphs = myDoc.stories[0].paragraphs[i].contents;
for( var j = 0; j < myParagraphs.length; j++ ) {

// create new text frame for each note and label each frame
myTframe = myDoc.textFrames.add(
{ label : 'temp' + String(i)+String(j) } );

// move paragraph text to frame
myParagraphs[j].texts[0].move( LocationOptions.after, Story);
}
}
}

paragraphs2textframes()

Please help.
Many thanks.
David

INDESIGN CS3; XP; 4GB
Re: Indesign para2txtframe script problem
#1438
Author: Dave_Saunders
Date: Sun, 08 Feb 2009 19:20
26 lines
2154 bytes
You don't say what goes wrong, but it is almost certainly caused by your iterating upwards through the paragraphs. When you move the text of paragraph zero elsewhere, every paragraph in the story shuffles up a position.

Also, you have two iterations through the same paragraphs inside each other, which must also be a cause of a problem or two.

And, "Story" is the name of an object class (in the move statement). You need to be moving to a particular instance of a story (presumabley myTframe.parentStory.

You should close off the for i loop after the grabbing of the contents -- you could also do away with that whole loop and use:

var myParagraphs = myDoc.stories[0].paragraphs.everyItem().contents

Expect that you've used a terribly confusing name for an array of the contents of the paragraphs. Later in the script you completely forget that myParagraphs is an array of strings and try to refer to it as though it were an array of paragraph references. So make it:

var myContents = myDoc.stories[0].paragraphs.everyItem().contents

Now you should use something like:

for (var j = 0; myContents.length > j; j++) {
myTframe = myDoc.textFrames.add({label:'temp' + String(j)});
myParagraphs[0].move(LocationOptions.after, myTframe.parentStory);
}

At least, that's assuming I know what you're trying to do. Your use of the loop inside the loop was doomed to failure because the second time through the story would be empty.

Hope this helps.

Dave
Re: Indesign para2txtframe script problem
#1439
Author: David_Milson
Date: Sun, 08 Feb 2009 20:01
28 lines
1384 bytes
Dear Dave,

Many thanks for your quick reply. As you noticed, yes, I am a beginner to Java, after many hours of repetitive tasks.

I do believe you understand what I'm trying to do, so here goes:

I tried your suggestions, and additionally changed the last myParagraphs to myContents as above, but now get this error on the last line:
myContents[0].move is not a function.

Here is the script now:
function paragraphs2textframes()
{

var myDoc = app.activeDocument;
var myContents = myDoc.stories[0].paragraphs.everyItem().contents;
for( var j = 0; myContents.length>j; j++ )
{

myTframe = myDoc.textFrames.add({ label : 'temp' + String(j) } );

myContents[0].move( LocationOptions.after, myTframe.parentStory);
}
}

paragraphs2textframes()

Thanks for your time.
David
Re: Indesign para2txtframe script problem
#1440
Author: Dave_Saunders
Date: Sun, 08 Feb 2009 20:23
11 lines
996 bytes
You can't move a JavaScript string. You need references to the paragraphs. I think I slightly screwed up above.

Indeed, you don't seem to be using the contents at all, so:

var myParas = myDoc.stories[0].paragraphs;
for (var j = 0; myParas.length > j; j++) {
myTF = myDoc.textFrames.add({label: 'temp' + j}); // String(j) not needed
myParas[0].move(LocationOptions.after.myTF.parentStory;
}

Dave
Re: Indesign para2txtframe script problem
#1442
Author: David_Milson
Date: Sun, 08 Feb 2009 21:36
7 lines
797 bytes
Dear Dave,

Good! My apologies for taking up time on your Sunday.

Now it works, but always through one-half, then stops. The console comes up with 'undefined' for the second half.

David
Re: Indesign para2txtframe script problem
#1443
Author: David_Milson
Date: Sun, 08 Feb 2009 21:42
10 lines
804 bytes
Dave,

I changed the j++ argument to j+1

Works now.

Thanks for your help, and your time.
Can you recommend a good beginner Java book?

David
Re: Indesign para2txtframe script problem
#1444
Author: jongware
Date: Sun, 08 Feb 2009 23:38
16 lines
1111 bytes

      I changed the j++ argument to j+1 Works now.




That's amazing. 'j++' is a shortcut for 'j+1' -- there should not be any difference at all.

      ..a good beginner Java book..




There are tons of sites with good on-line help. You only have to remember that everything relating to browsers is worthless :-)
But tinkering with other people's scripts is a really good way to start programming! "What if I change this ...?"
Re: Indesign para2txtframe script problem
#1298
Author: Fred_Goldman
Date: Mon, 09 Feb 2009 00:02
6 lines
895 bytes
I found this to be a great book:

JavaScript: The Definitive Guide

As jongware said, you can skip all the chapters about Window, Document 
and Frame objects and ignore all the HTML stuff.
Re: Indesign para2txtframe script problem
#1299
Author: Dave_Saunders
Date: Mon, 09 Feb 2009 00:36
7 lines
1132 bytes
Ah. Of course. First, j++ is not equivalent to j+1. It is the equivalent of j = j+1.

The reason you only got half the paragraphs in my version is because each time around the loop the story got shorter by one paragraph and while j went up one, myStory.paragraphs.length came down by one. And so they met half way through the story -- hmm, this is starting to sound like Gerard Hoffnung's famous speech to the Oxford Union.

But in your version, j never changed and so when myStory.paragraphs.length reached zero, the loop stopped.

Dave
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads