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

FindChangeByList script

New Here ,
Apr 30, 2009 Apr 30, 2009

I'm trying to use this pre-made script in CS4, and I customized the accompanying .txt file with all our Find-and Replace needs, but when I actually try to the run the script on a document, the following error message comes up:

Error Number: 23

Error String: does not have a value

File: [name and location of jsx file follows]

Line: 159

Source: app.doScript(myString, ScriptLanguage.javascript);

Anyone know how to get past this? It's very hard to see what Line 159 in the script file has to do with anything.

Thanks.

TOPICS
Scripting
29.1K
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 ,
Nov 22, 2009 Nov 22, 2009

Jesse,

What if you try putting all of the defunct styles into one master document, then load all text styles from that into each document before you run the script?

Then, after running the script, you could delete all unused styles and color swatches.

I know it's not as fast or as sexy as scripting it, but if you can't get that to work, it might be worth a try.

Of course, if there is a way to script it, I'd want to know also!

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
New Here ,
Nov 22, 2009 Nov 22, 2009

Thanks so much for your opinion, which is probably what I'd actually do, but

i have a bunch of higher ups who don't want me shaking things up for the

people who don't understand the stuff i've written, so what i'm trying to do

is change the styles without affecting their world. you can see my dilemna.

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 ,
Nov 22, 2009 Nov 22, 2009

Is there a way for this script to ignore any styles that it doesn't find matches for in the document so i don't have to leave a gargantuan list of old styles in my styles panel?

I remade the script a little and now it ignores missing styles. (See the attachment)

Also, looking for a way in GREP to strip all local formatting that doesn't come from style sheets to add into my list. Is there a menu option in GREP for that so i don't have to make it strip bold, then italic, then superior, then caps, etc?

I can't recreate this problem because the script strips all local formatting for me (the same as Alt + Click another paragraph style in InDesign).

Kasyan

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
New Here ,
Nov 23, 2009 Nov 23, 2009

Thanks a ton for that, I assume for the next few months, the old paragraph styles will be reintroduced into the document so often that there'd be no point in deleting them. but this one will be useful when the transition is done but we still have a few stragglers. about the local formatting, you're probably right, i just assumed i had to write a query to remove it.

edit. One last thing I noticed about this script is that it unless you have the text edit cursor placed in the story it searches the whole document is there a way for it to only run on the stories selected by the direct selection tool, so that you could have it run multiple stories but not the whole document?

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 ,
Nov 24, 2009 Nov 24, 2009

I think we can use another approach: find old paragraph one by one, apply new ones removing overrides and deleting old styles.

Here is a script — it's very basic, just to show my idea. At the beginning, there is a list of style names. Each line contains a find-change pair. Replace them with your own style names.

var myParStNames = [
    ["Header Old", "Header New"],
    ["Subheader Old", "Subheader New"],
    ["Body Old", "Body New"],
    ];

var myDoc = app.activeDocument;

for (i = 0; i < myParStNames.length; i++) {
    var myFindStyle = myDoc.paragraphStyles.item(myParStNames[0]);
    var myChangeStyle = myDoc.paragraphStyles.item(myParStNames[1]);
    if (myFindStyle == null || myChangeStyle == null) continue;
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.appliedParagraphStyle = myFindStyle;
    var myFinds = myDoc.findText();
    for (j = 0; j < myFinds.length; j++) {
        try {
            myFinds.applyParagraphStyle(myChangeStyle, true);
            myFindStyle.remove(myChangeStyle);
        }
        catch(e) {}
    }
}

alert("Done.");

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