3 Replies Latest reply on Aug 9, 2010 7:00 AM by Marijan Tompa [tomaxxi]

    Change a text variable

    chughes133 Level 1

      Hi guys, Im trying to create a script that will change a

      series of predetermined text variables.

      I'm come to a wall where now when I run the script and nothing happens. I did however get the dialogue box to run once.

       

      Here is the script so far. If anyone can tell me how to right align the static text please let me know. Thanks!

       

      function myDisplayDialog()
      {
      var myDialog = app.dialogs.add({name:"Change your text variables"});
      with(myDialog.dialogColumns.add()){
        with(dialogRows.add()){
         with(dialogColumns.add()){
          staticTexts.add({staticLabel:"Meeting Date:", minWidth:500});
         }
         with(dialogColumns.add()){
          var myMeetDate = textEditboxes.add({editContents:"Meeting Date"});
         }
        }
        with(dialogRows.add())
        {
         with(dialogColumns.add())
         {
          staticTexts.add({staticLabel:"Symbol:"});
          with(dialogColumns.add())
          {
           var mySymbol = textEditboxes.add({editContents:"Symbol", minWidth:500});
          }
         }
        }

      }

      var theResult = myDialog.show();
      if(theResult == true){
        var meetD = app.TextVariable.ItemByName ("Meeting Date");
        var symbolO = app.TextVariable.ItemByName ("Symbol");
        meetD.CustomTextVariablePreference.contents = myMeetDate;
        symbolO.CustomTextVariablePreference.contents = mySymbol;
        myDialog.destroy();
      }
      else{
        myDialog.destroy();
        exit();
      }
      return [myMeetDate, mySymbol];

      }
      myDisplayDialog ()

       

      *Edited to update the script, I think this new one is more correct.

        • 1. Re: Change a text variable
          Marijan Tompa [tomaxxi] Level 4

          Hey!

           

          Your syntax for assigning values is not correct. Here is corrected and working version of your script. Notice that script will try to load existing variable values to dialog.

           

          myDisplayDialog();
          
          function myDisplayDialog(){
          
          try{     var meetD = app.textVariables.itemByName("Meeting Date").variableOptions.contents;
                    var symbolO = app.textVariables.itemByName("Symbol").variableOptions.contents;
               }
          catch(_){alert("Variables not found");exit();}
          
          var myDialog = app.dialogs.add({name:"Change your text variables"});
          
               with(myDialog.dialogColumns.add()){
                    with(dialogRows.add()){
                         with(dialogColumns.add()){
                              staticTexts.add({staticLabel:"Meeting Date:", minWidth:444});
                         }
                         with(dialogColumns.add()){
                              var myMeetDate = textEditboxes.add({editContents:meetD, minWidth:100});
                         }
                    }
                    with(dialogRows.add()){
                         with(dialogColumns.add()){
                              staticTexts.add({staticLabel:"Symbol:"});
                              with(dialogColumns.add()){
                                   var mySymbol = textEditboxes.add({editContents:symbolO, minWidth:500});
                              }
                         }
                    }
               }
          
          var theResult = myDialog.show();
          
               if(theResult == true){
                    var meetD = app.textVariables.itemByName("Meeting Date");
                    var symbolO = app.textVariables.itemByName("Symbol");
                    meetD.variableOptions.contents = myMeetDate.editContents;
                    symbolO.variableOptions.contents = mySymbol.editContents;
                    myDialog.destroy();
               }
               else{
                    myDialog.destroy();
               }
          }
          

           

          --

          tomaxxi

          http://indisnip.wordpress.com/

          • 2. Re: Change a text variable
            chughes133 Level 1

            Hello Thank you very much for your help, however it seems that the script did

            not manage to catch the variables when I know for a fact they were present in the document.

            However I took a look at your website on a whim, and its a GREAT website by the way,

            and I found you posted about web variables there. I noted your comment about the document vs app level of the

            variables and i changed the script to suit. Now it works perfectly. Thanks very much tomaxxi!

             

            Do you think this will work in incopy as well?

            • 3. Re: Change a text variable
              Marijan Tompa [tomaxxi] Level 4

              Hey!

               

              Thanks on your reply! I'm glad script works perfectly I have to tell you that I was inspired with your question about variables and wrote down that post. I hope that I will write about adding text variables soon.

               

              I really don't know about InCopy, sorry.

               

              --

              tomaxxi

              http://indisnip.wordpress.com/

              1 person found this helpful