Skip navigation
Currently Being Moderated

about paragraph style?

Jan 24, 2012 3:31 AM

Hello ,

i want to check wheather particular style is present in the document.if present then i want to apply another style.

is any method in the indesign script which will find and replce particular style in the document?

 
Replies
  • Currently Being Moderated
    Jan 24, 2012 3:39 AM   in reply to govind_85

    You can do this in the find-change dialog box (no script needed). Set a paragraph style you want to find and the one you want to replace it with. Put nothing into the find what and change to fields.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 24, 2012 8:57 AM   in reply to govind_85

    Here's a simple example:

    var doc = app.activeDocument;
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("Header");
    app.changeTextPreferences.appliedParagraphStyle = doc.paragraphStyles.item("Subheader");
    doc.changeText();
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    

     

    It changes paragraph style Header with Subheader

    If you want to reference a paragraph style in a group, you can do this like so:

    app.findTextPreferences.appliedParagraphStyle = doc.paragraphStyleGroups.item("Headers").paragraphStyles.item("Header");
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 24, 2012 10:04 AM   in reply to Kasyan Servetsky

    And if you're operating in an environment where you know that you don't have any paragraph styles with the same names stored in different groups, and you want to reference a paragraph style that is somewhere in the document, without knowing what group it's in, you can use this recursive function to find it:

     

    var findParagraphStyle = function( obj, name ) {
        var style = obj.paragraphStyles.itemByName( name );
        if (!style.isValid) {
            for (var i = 0; i < paragraphStyleGroups.length; i += 1) {
                style = findParagraphStyle( obj.paragraphStyleGroups[i], name );
            }
        }
        return style; //     If we haven't found a style with name "name", 
                            //     findParagraphStyle will return an invalid object.
    };
     
    app.findTextPreferences.appliedParagraphStyle = findParagraphStyle( doc, "Header" );
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points