Thread View: adobe.scripting.indesign
21 messages
21 total messages
Started by Diane King
Thu, 05 Feb 2009 15:33
Trying to get an old script to work in CS3
Author: Diane King
Date: Thu, 05 Feb 2009 15:33
Date: Thu, 05 Feb 2009 15:33
37 lines
2924 bytes
2924 bytes
I have a script that somebody wrote for me some time back (I think when I was still in CS2) that finds a paragraph style and pulls that text out and places it in an anchored text box with an assigned object style. It was written for a specific job, but I'm trying to update it to use generally because I have a project that crosses my plate on a fairly regular basis that has paragraphs that need to be pulled out into anchored text boxes . Only problem is the script no longer works. I was able to find a few of the syntax errors and correct them myself (such as findPreferences to findTextPreferences), but I'm no scripter and the script still will not work. I don't know what else to do but post it here and beg for help. Would someone please look at it and see if it is something simple that can be reworded to make it work? It's currently stopping at line 6 "myDoc.search" I'm still in CS3. Thanks!
//find paragraph style text and replace with text in anchored text frame
myDoc = app.activeDocument
myPstyle = myDoc.paragraphStyles.itemByName("Teaching Tip");
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedParagraphStyle = myPstyle;
myFinds = myDoc.search("", false, false, undefined, {appliedParagraphStyle:myPstyle});
for (var j = myFinds.length - 1; j >= 0; j--) {
makeAnchor(myFinds[j]);
if ((j > 0) && (j % 100 == 0)) {
myDoc.save(myDoc.fullName);
}
}
function getParentTextFlow(theTextRef) {
// Returns reference to parent story or text of cell, as appropriate
if (theTextRef.parent.constructor.name == "Cell") {
return theTextRef.parent.texts[0];
} else {
return theTextRef.parentStory;
}
}
function makeAnchor(theText) {
// Transfers contents of theText into new anchored frame that replaces theText
var myStory = getParentTextFlow(theText);
var myAnchLocation = theText.insertionPoints[-2].index;
var myTF = myStory.insertionPoints[myAncLocation].textFrames.add();
myStory.recompose();
makeInchWide(myTF);
myTF.applyObjectStyle(myDoc.objectStyles.item("Teacher's Tip", true));
theText.move(LocationOptions.atEnd, myTF.parentStory);
myAnchStory = myTF.parentStory;
theText.move(LocationOptions.atEnd, myAnchStory);
myAnchStory.texts[0].appliedParagraphStyle = myDoc.paragraphStyles.item("Teaching Tip");
}
Re: Trying to get an old script to work in CS3
Author: Olav_Kvern
Date: Thu, 05 Feb 2009 18:50
Date: Thu, 05 Feb 2009 18:50
11 lines
869 bytes
869 bytes
Hi Diane, It's funny--your script is partially updated to CS3 (in that it uses app.findTextPreferences rather than app.findPreferences), but not all the way. There is no "search" method in CS3 and above, so: myFinds = myDoc.findText(); Thanks, Ole
Re: Trying to get an old script to work in CS3
Author: Diane King
Date: Thu, 05 Feb 2009 19:15
Date: Thu, 05 Feb 2009 19:15
5 lines
983 bytes
983 bytes
Ole, I tried to fix it myself and had already changed the findPreferences to findTextPreferences because I found that somewhere on the forum. That's why it was partially updated. I couldn't find what was wrong with line 6, so thanks for the new line. I'll give this a try now. Thanks again!
Re: Trying to get an old script to work in CS3
Author: Diane King
Date: Thu, 05 Feb 2009 19:35
Date: Thu, 05 Feb 2009 19:35
5 lines
959 bytes
959 bytes
OK, now it doesn't understand the contents of the parentheses on the same line. Do I have those arranged wrong? "Invalid value for parameter 'reverse order' of event 'findText'" Sorry, I don't know anything. I'd like to learn, but it's like a foreign language to me.
Re: Trying to get an old script to work in CS3
Author: Diane King
Date: Thu, 05 Feb 2009 19:37
Date: Thu, 05 Feb 2009 19:37
2 lines
744 bytes
744 bytes
hmmm, I put it in with the () like you had typed the line and it ran past that point and stopped at line 28. "myAncLocation is undefined"
Re: Trying to get an old script to work in CS3
Author: Olav_Kvern
Date: Thu, 05 Feb 2009 19:54
Date: Thu, 05 Feb 2009 19:54
15 lines
1676 bytes
1676 bytes
Hi Diane, First, take a look at the findText method under the Document object in the Object Model Viewer--you'll see that findText(), unlike search(), has only one parameter. All of the parameters that search() took in CS2 are now handled by setting preferences properties in CS3. re: "myAncLocation is undefined" There's nothing for it but to debug. Put a breakpoint on that line, then run the script up to that point. Then try stepping through the breakpoint. Does the script fail on the first attempt? If so, then there's something wrong with the text reference you're passing in. If not, then the problem has to do with some unexpected condition in some part of the text. Stepping through the script while watching the variables change and/or using $.writeln() statements to write variable values to the ESTK console will probably reveal the problem. I'm guessing that the trouble lies in the getParentTextFlow function for text in a cell, but I can't quickly tell without having one of your documents. Thanks, Ole
Re: Trying to get an old script to work in CS3
Author: Fred_Goldman
Date: Fri, 06 Feb 2009 00:13
Date: Fri, 06 Feb 2009 00:13
1 lines
816 bytes
816 bytes
It's simply a typo, it should say myAnchLocation.
Re: Trying to get an old script to work in CS3
Author: Diane King
Date: Fri, 06 Feb 2009 00:34
Date: Fri, 06 Feb 2009 00:34
5 lines
1011 bytes
1011 bytes
Fred, Thanks for the link. If I can't get my script to work, I might look into that. My only concern (beyond money, which is extraordinarily tight right now) is whether such plugins would mess up an InCopy workflow, which I heavily use. Harbs has some cool and extremely useful tools there, which make me salivate. Have you used them yourself? Are they easy to use and time savers?
Re: Trying to get an old script to work in CS3
Author: Fred_Goldman
Date: Fri, 06 Feb 2009 08:14
Date: Fri, 06 Feb 2009 08:14
3 lines
858 bytes
858 bytes
BTW, Harbs has a great plugin that does this and more... http://www.in-tools.com/plugin.php?p=18
Re: Trying to get an old script to work in CS3
Author: Harbs
Date: Fri, 06 Feb 2009 08:24
Date: Fri, 06 Feb 2009 08:24
11 lines
1043 bytes
1043 bytes
Diane King wrote: > My only concern (beyond money, which is extraordinarily tight right now) is whether such plugins would mess up an InCopy workflow, which I heavily use. > No. There's no issues (that we know of) with InCopy workflows. (And money is a concern for all of us. No easy solutions there...) ;) -- Harbs http://www.in-tools.com
Re: Trying to get an old script to work in CS3
Author: Fred_Goldman
Date: Fri, 06 Feb 2009 09:46
Date: Fri, 06 Feb 2009 09:46
8 lines
1163 bytes
1163 bytes
I have used them, although never with InCopy. His plugins work with scripts so I highly doubt it would introduce any issues with InCopy. I find them very useful and Harbs has always been great as far as getting back to me quickly if I have had a technical issue. I would, of course, still be happy to try and help you with try to customize your script, this happens to be one of the few areas of InDesign scripting I am a little familiar with.
Re: Trying to get an old script to work in CS3
Author: Peter Kahrel
Date: Fri, 06 Feb 2009 10:40
Date: Fri, 06 Feb 2009 10:40
5 lines
911 bytes
911 bytes
Diana, Have you tried placing the CS2 script in a versioned folder? Create a folder "Version 4.0 Scripts", place the script in there, and run it from there. I'm not sure if that folder should be in any particular place, but as a subfolder of the CS3 scripts folder it should work. Peter
Re: Trying to get an old script to work in CS3
Author: Kasyan_Servetsky
Date: Fri, 06 Feb 2009 12:56
Date: Fri, 06 Feb 2009 12:56
10 lines
857 bytes
857 bytes
I'm not sure if that folder should be in any particular place, but as
a subfolder of the CS3 scripts folder it should work.
The exact path should be:
Adobe InDesign CS3 > Scripts > Scripts Panel > Version 4.0 Scripts
Re: Trying to get an old script to work in CS3
Author: Peter Kahrel
Date: Fri, 06 Feb 2009 15:45
Date: Fri, 06 Feb 2009 15:45
3 lines
686 bytes
686 bytes
Ah -- thanks, Kasyan. Peter
Re: Trying to get an old script to work in CS3
Author: Diane King
Date: Mon, 09 Feb 2009 18:59
Date: Mon, 09 Feb 2009 18:59
8 lines
1478 bytes
1478 bytes
Well, I downloaded the Side Heads trial and just gave it a try and it errored out and dumped the first three sideheads, which were at the beginning of the story. The error: Couldn't Create a Side Head! (Possibly it's the Last Paragraph in the story ...) and then I get a JavaScript Error Number 45, Line 747 Interesting thing is that it appears to be working backwards and the last ones it is doing are the first ones in the story. It deletes the paragraphs but there are no sideheads (and those are the 3 I noticed, I'm worried there might be others). I have to undo it to get the paragraphs back (which reverses the whole thing). There were none at the end of the story so the alert makes no sense to me. Cool idea if I can get it to work. Might be worth it over the script, but I'm going to go ahead and see if I can get the script to work.
Re: Trying to get an old script to work in CS3
Author: Diane King
Date: Mon, 09 Feb 2009 19:32
Date: Mon, 09 Feb 2009 19:32
9 lines
1013 bytes
1013 bytes
Hey, I've put it in the 4.0 Scripts folder and put the syntax back to it's original. I've fixed a few typos that it was erroring on and now it's stopped on line 31 theText.move(LocationOptions.atEnd,myTF.parentStory); saying that "Text cannot be moved to its current location" Can anyone tell me what's wrong with this line? I believe this is the last bit I need to get past to get it to work.
Re: Trying to get an old script to work in CS3
Author: Peter Kahrel
Date: Mon, 09 Feb 2009 19:37
Date: Mon, 09 Feb 2009 19:37
8 lines
843 bytes
843 bytes
Try wrapping the troublesome line in a try-catch statement:
try {theText.move(LocationOptions.atEnd,myTF.parentStory)} catch(_){}
Peter
Re: Trying to get an old script to work in CS3
Author: Olav_Kvern
Date: Mon, 09 Feb 2009 20:00
Date: Mon, 09 Feb 2009 20:00
23 lines
1131 bytes
1131 bytes
Hi Diane, I don't think that Peter's suggestion will work--the text won't move if the line fails (but thanks for helping, Peter!). Instead, I think you need to provide a more "solid" text reference for the move method--I've noticed that using a story does not work in all cases. Try something like this: theText.move(LocationOptions.atEnd,myTF.parentStory.insertionPoints.item(0)); Or: theText.move(LocationOptions.atEnd,myTF.parentStory.texts.item(0)); ...either should work. Thanks, Ole
Re: Trying to get an old script to work in CS3
Author: Harbs
Date: Mon, 09 Feb 2009 23:16
Date: Mon, 09 Feb 2009 23:16
9 lines
936 bytes
936 bytes
Hi Diane, I'm not sure what went wrong based on what you wrote. We would very much like to see any documents in which you get such an error! Please send me an email, and I'll try to see what went wrong. -- Harbs http://www.in-tools.com
Re: Trying to get an old script to work in CS3
Author: Diane King
Date: Tue, 10 Feb 2009 14:51
Date: Tue, 10 Feb 2009 14:51
3 lines
1199 bytes
1199 bytes
Harbs, I cleaned up the document a bit (I was working on top of an old file, importing new text). Once I removed the old text and flowed the new text in place of it, the plugin ran fine. My guess is that it was hanging up because it was operating document wide instead of on just the story and it was trying to work with the side heads that were already created on the older text story. Perhaps you could add an option to the plugin to allow the user to choose only the selected story for the operation.
Re: Trying to get an old script to work in CS3
Author: Harbs
Date: Tue, 10 Feb 2009 18:06
Date: Tue, 10 Feb 2009 18:06
8 lines
882 bytes
882 bytes
Hi Diane, I'm glad you got it working. If you still have that document, I'd still like to see it. We'd like to make the plugin as robust as possible! -- Harbs http://www.in-tools.com
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