16 Replies Latest reply on Oct 21, 2016 10:07 AM by cbishop01

    Can someone help me with my Dropdown's

    cbishop01 Level 2

      Here's what i have.  If i place alerts in the functions they display.  I just cannot get these to Run the scripts.  Instead of myDL = app.documents.item(0); i've tried this app.documents.item(0); and so on.  i've also replaced the app.doScript(script4x) with app.documents.item(0) and so on.  Did i set this up wrong?

       

      var dL = w.add ("dropdownlist", undefined, ["Document", "All Documents", "Selection"]);
               dL.selection = 0;
          with (dL) {
      
         dL.onChange = function() {
         var myDL;
         var curSelection1 = this.selection.index;
          //alert ( "You clicked item: "  + this.selection.index );
          switch (curSelection1) {
            case 0:
                app.doScript(script40);
              break;
            case 1:
                app.doScript(script41);
              break;
            case 2:
                app.doScript(script42);
              break;
           }
         function script40(){
        
              myDL = app.documents.item(0);
              
           }
      
         function script41(){ 
             
              myDL = app.documents.everyItem();
      
           }
         function script42(){
              
              myDL = app.selection[0];
      
           }     
         }
      }
      
      

      thanks in advance.

        • 1. Re: Can someone help me with my Dropdown's
          Peter Spier Most Valuable Participant (Moderator)

          Moved to scripting...

          • 2. Re: Can someone help me with my Dropdown's
            cbishop01 Level 2

            THank you Peter. 

            • 3. Re: Can someone help me with my Dropdown's
              Skemicle Level 3

              Remove line 3 and the corresponding closing bracket from line 37.

               

              the with() function is a way to consolidate properties which you don't need. eg:

              with(textFrame){
                  geometricBounds = [0,0,5,5];
                  contents = "Hello World";
              }
              

              and

              textFrame.geometricBounds = [0,0,5,5];
              textFrame.contents = "Hello World";
              

              just so you don't have to type the object repeatedly.

              1 person found this helpful
              • 4. Re: Can someone help me with my Dropdown's
                cbishop01 Level 2

                This is ScriptUI.  I have it at the Bottom of my script. I'll Try your below and let you know.  THanks.

                • 5. Re: Can someone help me with my Dropdown's
                  Skemicle Level 3

                  I saw that as soon as i looked at your script but for some reason i continued to extensively test your coding without removing it myself.

                  • 6. Re: Can someone help me with my Dropdown's
                    Skemicle Level 3

                    I know it's script UI and set as 'palette' type.. If it weren't the alerts wouldn't have shown either .

                     

                    I'm pretty sure the way it was with the with() function your code for function script40() would have been dL.app.documents.item(0). which wouldn't provide any results.

                    • 7. Re: Can someone help me with my Dropdown's
                      Skemicle Level 3

                      I may be "making an *** out of U and ME" but...

                      Before you go into writing the same code 3 times for the different selections.. Look at this script:

                      #targetengine "test"
                      
                      var window = new Window('palette', "Test");
                      with(window){
                          var drop = add('dropdownlist', undefined, ["Add \"Cat\"", "Add \"Dog\"", "Add \"Mouse\""]);
                      }window.show()
                      drop.onChange = function getSelection(){var userSelected = drop.selection.index;
                      
                      switch(userSelected){
                      case 0:
                          addWord("Cat");
                          break;
                      case 1:
                          addWord("Dog");
                          break;
                      case 2:
                          addWord("Mouse");
                          break;
                      }}
                      
                      function addWord(word){
                          app.selection[0].contents = word;
                      }
                      

                      Where each case calls the same function but the variable "word" is assigned differently depending on the call to the function within the cases

                      so for you if you are writing the same script for the different selections you could use

                      case 0:
                           script40(app.documents.item(0));
                           break;
                      case 1:
                           script40(app.documents.everyItem());
                           break;
                      case 2:
                           script40(app.selection[0]);
                           break;
                      function script40(myDL){
                           //script here
                      }
                      

                      and the variable 'myDL' would be set to whichever case was used

                      1 person found this helpful
                      • 8. Re: Can someone help me with my Dropdown's
                        cbishop01 Level 2

                        What i'm trying to do is add functionality to the Dropdown.  I can get it to display alerts.  But i cannot get things to per "document, All Documents, Selection."  Ex i'm trying to get my search and other parts of the script to work for the quoted words in this explanation. I have a Check box that activates for all documents i'm just trying to add 2 more functions "Document, selection." and make it nicer looking with the Drop down.  So what i tried to do is modify my Listbox portion of the script and add a drop down.  that is what the above code was.  When i try to add the code you shared it stopped working and my script wont run.

                        • 9. Re: Can someone help me with my Dropdown's
                          cbishop01 Level 2

                          Let me try what you just added.

                          • 10. Re: Can someone help me with my Dropdown's
                            Skemicle Level 3

                            For me.. removing the with function and changing the cases as I suggested to all call the same function with myDL variable, gave functionality to the desired selection:

                            #targetengine "Testing"
                            var w = new Window('palette', "test")
                            var dL = w.add ("dropdownlist", undefined, ["Document", "All Documents", "Selection"]);
                            dL.selection = 0;
                            dL.onChange = function(){
                                var myDL;
                                var curSelection1 = this.selection.index;
                                //alert ("You clicked item: "+ this.selection.index );
                                switch (curSelection1){
                                    case 0:
                                        script40(app.documents.item(0));
                                        break;
                                    case 1:
                                        script40(app.documents.everyItem());
                                        break;
                                    case 2:
                                        script40(app.selection[0]);
                                        break;
                                }
                            }function script40(myDL){
                                app.findGrepPreferences = null;
                                app.findGrepPreferences.findWhat = "found";
                            
                                app.changeGrepPreferences.changeTo = "changed";
                            
                                myDL.changeGrep();
                            }w.show()
                            

                            Does that not work for you?

                            • 11. Re: Can someone help me with my Dropdown's
                              cbishop01 Level 2

                              It does now.  THank you so much.  IF i have any other questions i'll let you know.  I'm going to try and merge this into my script to see if will work like i'm wanting.  Thanks again..

                              • 12. Re: Can someone help me with my Dropdown's
                                cbishop01 Level 2

                                I think i found my problem.  I cannot activate this Dropdown in my Script. And i believe its because my Script i'm using it in is a dialog and not a palette.  and it will not allow the action to fire while the main script is open.

                                • 13. Re: Can someone help me with my Dropdown's
                                  Skemicle Level 3

                                  Yeah, documents can't be edited while a modal dialog or alert is open in order to make edits while a dialog is up it must be non-modal.. which is what a 'palette' type window is.

                                  • 14. Re: Can someone help me with my Dropdown's
                                    cbishop01 Level 2

                                    I'm trying to figure out how to still use dropdown menu's and activate after i click on the OK button.  I'm not sure if this can be done with a dialog.  If this will not work let me know and i'll stop trying.  I cannot switch this to a palette.  Everytime i do it stops the script from working.  I'm guessing i have some parts of the script that require it to be dialog. 

                                    • 15. Re: Can someone help me with my Dropdown's
                                      Skemicle Level 3

                                      using a modal dialog with the OK button you will not need the onChange event.

                                      var w = new Window('dialog', "test")  
                                      var dL = w.add ("dropdownlist", undefined, ["Document", "All Documents", "Selection"]);  
                                      w.add('button', undefined, "OK");
                                      dL.selection = 0; 
                                      if(w.show() != 1){
                                          exit();
                                      }else{  
                                          var curSelection1 = dL.selection.index;  
                                          switch (curSelection1){  
                                              case 0:  
                                                  script40(app.documents.item(0));  
                                                  break;  
                                              case 1:  
                                                  script40(app.documents.everyItem());  
                                                  break;  
                                              case 2:  
                                                  script40(app.selection[0]);  
                                                  break;
                                          }
                                      }function script40(myDL){  
                                          app.findGrepPreferences = null;  
                                          app.findGrepPreferences.findWhat = "found";  
                                          app.changeGrepPreferences.changeTo = "changed";  
                                          myDL.changeGrep();  
                                      }
                                      
                                      1 person found this helpful
                                      • 16. Re: Can someone help me with my Dropdown's
                                        cbishop01 Level 2

                                        Awesome.  Thank you so much.