6 Replies Latest reply on Jan 25, 2011 10:51 AM by tansk02

    selected language from dropdown

    tansk02

      Hi All,

       

      I need your help. See my below code, which I write to identify if my document language is not matched with my dropdown selected language.

       

      The problem is, when I run my code (see below) everytime it shows me my document applied language multiple time i.e., and not comparing my document language with dropdown selected language.

       

      Spanish

      Spanish    

      Spanish

      Spanish

      Spanish

      Spanish

      Spanish

       

       

      Please help me.

       

      Tansk

       

       

       

      ///my code start

       

      if  (myDialog.searchWrongLanguage.value == true){

      var myDoc=app.activeDocument;

      var myLanSelec=myDialog.myDlist.DropDownList1.selectedIndex;

      var myLangApplied=myDoc.paragraphStyles;

      for (oneStyle=1;oneStyle<myLangApplied.length;oneStyle++)

      if (myLangApplied[oneStyle]!=myLanSelec)

      {

      write(myLangApplied[oneStyle].appliedLanguage.name)

      }

      }

       

      //my code end

        • 1. Re: selected language from dropdown
          [Jongware]-9BC6tI Level 4

          That's because you write out the bad language immediately, so if this fires ten times, for ten different paragraph styles, it always shows ten strings -- whether the language is the same or not. "write" doesn't have a memory.

           

          Instead, store the results into an array, and display that when all is checked. Before storing you should check if the new value already is in the array:

           

          var resultList = []; // empty array

           

          for (oneStyle=1;oneStyle<myLangApplied.length;oneStyle++)
          if (myLangApplied[oneStyle]!=myLanSelec)
          {

            addThis = true;

            for (check=0; check<resultList.length; check++)

              if (resultList[check] == myLangApplied[oneStyle[.appliedLanguage.name)

              {

                 addThis = false;

                 break;

              }

            if (addThis)
              resultList.push(myLangApplied[oneStyle].appliedLanguage.name);
          }

          write (resultList.join(\r));

          1 person found this helpful
          • 2. Re: selected language from dropdown
            tansk02 Level 1

            Hi Jongware,

             

            Thanks for your answer.

             

            As you suggested, I modified my code as below. But it shows me all the langaugaes used in the document. Whereas I need to compare my document languages with my dropdown selection. So that it will show only other than my selected language.

             

            I know you can help me on this. Please suggest.

             

             

             

            var myDoc=app.activeDocument;

            var myLanSelec=myDialog.myPanel1.Group2.Group4.DropDownList1.selectedIndex;

            var myLangApplied=myDoc.paragraphStyles;

            var resultList = []; // empty array

            for (oneStyle=1;oneStyle<myLangApplied.length;oneStyle++)

            if (myLangApplied[oneStyle]!=myLanSelec)

            {

            addThis = true;

            for (check=0; check<resultList.length; check++)

            if (resultList[check] == myLangApplied[oneStyle].appliedLanguage.name)

            {

            addThis = false;

            break;

            }

            if (addThis)

            resultList.push(myLangApplied[oneStyle].appliedLanguage.name);

            }

            write (resultList.join("\r"));

            • 3. Re: selected language from dropdown
              [Jongware]-9BC6tI Level 4

              Check what value ends up in "myLanSelec". According to my documentation, "selectedIndex" is a number, so why would you compare it to a language?

               

              Apart from that:

               

              if (myLangApplied[oneStyle]!=myLanSelec)

               

              doesn't work at all. The left half is a paragraph style, the right half is, well, obviously a number, as per above. So you are comparing a number to a paragraph style, they are not equal, and hence *evrything* gets shown.

               

              You should go over the script one line at a time, fixing these obvious errors first.

              • 4. Re: selected language from dropdown
                tansk02 Level 1

                Hi Jongware,

                 

                Thanks for your support.

                 

                Actually I want to search document language other than my selected language from dropdown menu in my entire document.

                 

                I am beginner in scripting, I am trying as you suggested but I could not achieve my target.

                 

                It would be really nice if you could you please write those things in my script as you suggested to me.

                 

                 

                Thanks,

                Tansk

                • 5. Re: selected language from dropdown
                  [Jongware]-9BC6tI Level 4

                  I don't have the time for that.

                   

                  What did you try? How far did you get?

                  • 6. Re: selected language from dropdown
                    tansk02 Level 1

                    Thanks. I am beginner in scripting that is why I am not getting the point.

                     

                    Anyone can help me on this.