9 Replies Latest reply on Dec 19, 2012 3:59 AM by shilpa25

    Calling fontStyle from dropdownlist

    shilpa25

      forum,

       

      Can i get some tips about calling "fontstyle" from dropdownlist.

       

      var myDialog = new Window('palette', 'Highlight_fontStyle_Gobally');

      var myGroup = myDialog.add('group', undefined, '');

      var newButton1 = myGroup.add('button', undefined, 'Highlight Words', {name:'Button'});

      var arrays = ["select font style", "Regular", "Medium", "Bold", "Italic", "Bold Italic"];

      var ddown= myGroup.add("dropdownlist", undefined, arrays);

      myDialog.show();

       

       

      newButton1.onClick = function() {

      myCondition = app.activeDocument.conditions.add ({name:"Highlight_Text",

      indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor:UIColors.YELLOW});

       

      if (!myCondition.isValid) {

      app.findGrepPreferences = NothingEnum.nothing;

      app.changeGrepPreferences = NothingEnum.nothing;

      }

      app.findGrepPreferences.fontStyle = "Regular";  //here i have to assign arrays instead of fontStyle: Regular.. ie. app.findGrepPreferences.fontStyle = "arrays.onClick";

      app.changeGrepPreferences.appliedConditions = ["Highlight_Text"];

      app.changeGrep();

       

      please advise,

       

      shil...

        • 1. Re: Calling fontStyle from dropdownlist
          Peter Kahrel Adobe Community Professional & MVP

          Add a dropdownlist from which you can select a font weight. "select font style" isn't part of the array, that appears as a label in your window. Then later you could do something like

           

          app.findGrepPreferences.fontStyle = array.selection.text

           

          By the way, you'd better keep that newButton1.onClick = function() {. . .} inside the window definition.

           

          Peter

          • 2. Re: Calling fontStyle from dropdownlist
            Jump_Over Level 5

            Hi,

             

            First let me ask:

            Is it your goal to highlight every occurence of fontStyle from your array?

            Or is it your goal to highlight chosen one (because there a dialog with droplist)?

             

            I am pretty sure is not possible to assign an array to app.findGrepPreferences.fontStyle, but:

            result of app.findGrep() is an array of texts found, so

            you could create a loop to assign a specific fontStyle step by step and concat "result arrays" into a final one.

             

            Last step would be to set "appliedConditions" to every element of FinalArray.

            Or set this Conditions using changeGrep() inside every step of your loop.

             

            rgds

            • 3. Re: Calling fontStyle from dropdownlist
              shilpa25 Level 1

              Hi Peter & Jump_over,

               

              thanks for your reply,

               

              My goal is to choose 'array' representing fontstyle (regular, or bold, italics etc.,) from the dropdownlist and highlight findwhat.text in the entire document.

               

              you are correct Jump_over,  i cannot assign array in app.findGrepPreferences.fontStyle = arrays.onClick... its my bad idea of choosen arrays as "string" in ........fontStyle = arrays.onClick... as also replied by peter...

               

              what should i do on my goal is the...?

               

              thanks...

              peter & jump_over.... any suggestion from this...

              • 4. Re: Calling fontStyle from dropdownlist
                Peter Kahrel Adobe Community Professional & MVP

                > My goal is to choose 'array' representing fontstyle (regular, or bold, italics etc.,) from the dropdownlist

                 

                Well, add a dropdownlist to your window. See www.kahrel.plus.com/indesign/scriptui.html, p. 37.

                 

                Peter

                • 5. Re: Calling fontStyle from dropdownlist
                  Jump_Over Level 5

                  Hi,

                   

                  ddown.selection.text ==> here is a string taken from your array's chosen element (DropDownList).

                   

                  If any of this string is always equal to some fontStyle name, you can use it to assign to app.findGrepPreferences.fontStyle

                  and run app.changeGrep()

                   

                  rgds

                  • 6. Re: Calling fontStyle from dropdownlist
                    shilpa25 Level 1

                    Hi Jump_over

                     

                    Joyful moment,

                     

                    your tweaks does a great!!!!..

                     

                    thanks you very much

                    1 person found this helpful
                    • 7. Re: Calling fontStyle from dropdownlist
                      shilpa25 Level 1

                      Proud to have your UI guide,,

                       

                      only after seeing your link,, I started this simple UI.... in future I ll be making use of your UI guide.pdf more... very helpful...

                       

                      thanks Peter....

                      • 8. Re: Calling fontStyle from dropdownlist
                        Cenchen Level 2

                        @ shilpa25.

                                       Jump_over also correct. and you need to add add try...catch.. here. otherwise it will throw error while running second time.

                                 

                        var myDialog = new Window('palette', 'Highlight_fontStyle_Gobally');
                        var myGroup = myDialog.add('group', undefined, '');
                        var newButton1 = myGroup.add('button', undefined, 'Highlight Words', {name:'Button'});
                        var arrays = ["select font style", "Regular", "Medium", "Bold", "Italic", "Bold Italic"];
                        var ddown= myGroup.add("dropdownlist", undefined, arrays);
                        myDialog.show();

                        newButton1.onClick = function() {
                        try{ //use try... catch... here
                        myCondition = app.activeDocument.conditions.add ({name:"Highlight_Text",indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, indicatorColor:UIColors.YELLOW});
                        }
                        catch(e){}

                        if (!myCondition.isValid) {
                        app.findGrepPreferences = NothingEnum.nothing;
                        app.changeGrepPreferences = NothingEnum.nothing;
                        }
                        app.findGrepPreferences.fontStyle = ddown.selection.toString() ; // or ddown.selection.text

                        app.changeGrepPreferences.appliedConditions = ["Highlight_Text"];
                        app.changeGrep();
                        }

                        • 9. Re: Calling fontStyle from dropdownlist
                          shilpa25 Level 1

                          correct cenchen,

                          try catch helps to attemp additional fontstyles.

                           

                          thanks