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

Trying to get an old script to work in CS3

Community Beginner ,
Feb 05, 2009 Feb 05, 2009
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);
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");
}
TOPICS
Scripting
1.4K
Translate
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 ,
Feb 05, 2009 Feb 05, 2009
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
Translate
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 Beginner ,
Feb 05, 2009 Feb 05, 2009
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!
Translate
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 Beginner ,
Feb 05, 2009 Feb 05, 2009
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.
Translate
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 Beginner ,
Feb 05, 2009 Feb 05, 2009
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"
Translate
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 ,
Feb 05, 2009 Feb 05, 2009
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
Translate
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
Enthusiast ,
Feb 05, 2009 Feb 05, 2009
It's simply a typo, it should say myAnchLocation.
Translate
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
Enthusiast ,
Feb 05, 2009 Feb 05, 2009
BTW, Harbs has a great plugin that does this and more...

http://www.in-tools.com/plugin.php?p=18
Translate
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 Beginner ,
Feb 05, 2009 Feb 05, 2009
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?
Translate
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
Enthusiast ,
Feb 05, 2009 Feb 05, 2009
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.

They all have 30-day trials so you can give it a go yourself.

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.
Translate
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
LEGEND ,
Feb 06, 2009 Feb 06, 2009
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
Translate
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 ,
Feb 06, 2009 Feb 06, 2009
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
Translate
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
Valorous Hero ,
Feb 06, 2009 Feb 06, 2009
>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
Translate
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 ,
Feb 06, 2009 Feb 06, 2009
Ah -- thanks, Kasyan.

Peter
Translate
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 Beginner ,
Feb 09, 2009 Feb 09, 2009
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.
Translate
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
LEGEND ,
Feb 09, 2009 Feb 09, 2009
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
Translate
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 Beginner ,
Feb 09, 2009 Feb 09, 2009
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.
Translate
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 ,
Feb 09, 2009 Feb 09, 2009
Try wrapping the troublesome line in a try-catch statement:
>try {theText.move(LocationOptions.atEnd,myTF.parentStory)} catch(_){}

Peter
Translate
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 ,
Feb 09, 2009 Feb 09, 2009
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
Translate
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 Beginner ,
Feb 10, 2009 Feb 10, 2009
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.
Translate
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
LEGEND ,
Feb 10, 2009 Feb 10, 2009
LATEST
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
Translate
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