1 Reply Latest reply on Aug 10, 2010 1:16 PM by Fred Goldman

    I am fresher for javascript

    SachinLara

      Hi all,

       

      This is the first script for me. It successfully run but, I think it contains too many lines. I want to sort into few lines. Please give any alter solution for me for the below script.

       

       

      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "TX";
      app.changeTextPreferences.appliedParagraphStyle = "tx2";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "ul";
      app.changeTextPreferences.appliedParagraphStyle = "unl";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "COMPINSTRUX";
      app.changeTextPreferences.appliedParagraphStyle = "Figure";
      app.documents.item(0).changeText();   
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences.appliedCharacterStyle = "h3";
      app.findGrepPreferences.findWhat = "(.+)";
      app.changeGrepPreferences.appliedCharacterStyle = "h3";
      app.changeGrepPreferences.changeTo = "$0~>";
      app.documents.item(0).changeGrep();
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.findWhat = "^> ";
      app.changeTextPreferences.changeTo = "^>";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.findWhat = " ^>";
      app.changeTextPreferences.changeTo = "^>";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "H1";
      app.changeTextPreferences.appliedParagraphStyle = "h1";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "H2";
      app.changeTextPreferences.appliedParagraphStyle = "h2";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "KTX";
      app.changeTextPreferences.appliedParagraphStyle = "ktx";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "BLEOC";
      app.changeTextPreferences.appliedParagraphStyle = "bleoc";
      app.documents.item(0).changeText();
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      app.findTextPreferences.appliedParagraphStyle = "ALEOC";
      app.changeTextPreferences.appliedParagraphStyle = "aleoc";
      app.documents.item(0).changeText();
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences.appliedParagraphStyle = "objnl";
      app.findGrepPreferences.findWhat = "(\\d+)(\\.) ";
      app.changeGrepPreferences.changeTo = "\t$1$2\t";
      app.documents.item(0).changeGrep();
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences.appliedParagraphStyle = "nleoc";
      app.findGrepPreferences.findWhat = "(\\d+)(\\.) ";
      app.changeGrepPreferences.changeTo = "\t$1$2\t";
      app.documents.item(0).changeGrep();
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
      app.findGrepPreferences.appliedParagraphStyle = "aleoc";
      app.findGrepPreferences.findWhat = "(.\\.) ";
      app.changeGrepPreferences.changeTo = "$1\t";
      app.documents.item(0).changeGrep();
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;

       

       

       

       

       

      Regards

      Siraj

        • 1. Re: I am fresher for javascript
          Fred Goldman Level 3

          You need to make it into a function. This is what I use:

           

           

           

          findGrep("find", "change", "findParagraphStyle", "findCharacterStyle", "changeParagraphStyle", "changeCharacterStyle", "document")
          
          function findGrep(find, change,fps,fcs,cps,ccs,d){
          app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
          find != "find" ? app.findGrepPreferences.findWhat = find : app.findGrepPreferences.findWhat = NothingEnum.nothing ;
          change != "change" ? app.changeGrepPreferences.changeTo = change : app.changeGrepPreferences.changeTo = NothingEnum.nothing;
          fps != "findParagraphStyle" ? app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item(fps) : app.findGrepPreferences.appliedParagraphStyle = NothingEnum.nothing;
          fcs != "findCharacterStyle" ? app.findGrepPreferences.appliedCharacterStyle = myDoc.characterStyles.item(fcs) : app.findGrepPreferences.appliedCharacterStyle =NothingEnum.nothing;
          cps != "changeParagraphStyle" ? app.changeGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item(cps) : app.changeGrepPreferences.appliedParagraphStyle = NothingEnum.nothing;
          ccs != "changeCharacterStyle" ? app.changeGrepPreferences.appliedCharacterStyle = myDoc.characterStyles.item(ccs) : app.changeGrepPreferences.appliedCharacterStyle = NothingEnum.nothing;
          d != "document" ? d.changeGrep() : app.activeDocument.changeGrep();
          }