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

Auto apply paragraph style

Guest
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

Hi all,

I m new to indesign scripting. I need a help to correct my script.

Its a basic scritpt to created to apply paragraph style 1 to the basic paragraph . after doing this, i want to apply the paragraph style 2 created to the next paragraphs likewise and so on.

var myDoc = app.activeDocument;

app.findGrepPreferences = NothingEnum.NOTHING;

app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("[Basic Paragraph]");

var myResult = app.findGrep();

   


app.changeGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.itemByName("Paragraph Style 1");

var myResult1 = app.changeGrep();

    app.findGrepPreferences = NothingEnum.NOTHING; //to clear the selected paragraph panel

    app.changeGrepPreferences = NothingEnum.NOTHING; //to clear the changed paragraph panel


Can anybody help on this, please.

thanks

babylon.

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

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
Advisor ,
Nov 15, 2012 Nov 15, 2012

Copy link to clipboard

Copied

what error does it give??

try this

var doc=app.activeDocument;

function resetOpt(){ // saves the find change options and resets the to default

    var old_fCGOpts=app.findChangeGrepOptions.properties;

    var old_fGPref=app.findGrepPreferences.properties;

    var old_cGPref=app.changeGrepPreferences.properties;

    app.findChangeGrepOptions=NothingEnum.NOTHING;

    app.findGrepPreferences=NothingEnum.NOTHING;

    app.changeGrepPreferences=NothingEnum.NOTHING;

    return [old_fCGOpts,old_fGPref,old_cGPref]

    }

function restoreOpt(myOpt){

    app.findChangeGrepOptions.properties=myOpt[0];

    app.findGrepPreferences.properties=myOpt[1];

    app.changeGrepPreferences.properties=myOpt[2];

    }

var myOpt=resetOpt(); //save and reset Find/Change Options

app.findGrepPreferences.appliedParagraphStyle = doc.paragraphStyles.itemByName("[Basic Paragraph]");

app.changeGrepPreferences.appliedParagraphStyle = doc.paragraphStyles.itemByName("Paragraph Style 1");

var myResult1 = doc.changeGrep();

restoreOpt(myOpt); //restore previous find change options


Votes

Translate

Translate

Report

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
Guest
Nov 16, 2012 Nov 16, 2012

Copy link to clipboard

Copied

your script a wow!

thanks vami.

bobylon

Votes

Translate

Translate

Report

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
Mentor ,
Nov 16, 2012 Nov 16, 2012

Copy link to clipboard

Copied

Hi,

So, if myResult is an array with all textRanges with Basic Paragraph applied

start to iterate it:

....

var ParaStylesToAdd_ArrayOfNames = ["P4", "P3", "P2"];

var counter = ParaStylesToAdd_ArrayOfNames.length;

from (k=0; k<myResult.length; k++)

     {

     myStory = myResult.parentStory;

     myResult.changeGrep();

     basePara = myResult.paragraphs[-1];

     while (counter--)

          {

          basePara = myStory.paragraphs.nextItem(basePara);

          basePara.appliedParagraphStyle = myDoc.paragraphStyles.itemByName(ParaStylesToAdd_ArrayOfNames[counter-1]);

          }

     }

...

Watch two assumings here:

1. there is enough paras in myStory starting from Basic Para ==> to add your next styles.

2. if two or more Basic Paras are in the same MyStory ==> they can't be closer then ParaStylesToAdd_ArrayOfNames.length distance of paragraphs.

Watch also up_side_down order of para names in an array;

rgds

Votes

Translate

Translate

Report

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
Guest
Nov 16, 2012 Nov 16, 2012

Copy link to clipboard

Copied

LATEST

Thanks 30.png

I'll try on yours.

rgds,

boby.

Votes

Translate

Translate

Report

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