6 Replies Latest reply on Feb 25, 2016 7:12 AM by tpk1982

    Constant Value in Prompt box

    tpk1982 Level 4

      Hi,

       

      Is it possible to retain the values in prompt box once i entered? I meant it remain the value if i run the script again?

       

      var myWidth=prompt("PLEASE ENTER YOUR TEXT FRAME WIDTH VALUE (IN POINTS)","")
      

       

      For example if i enter 10, next time the default value should be 10.

       

      Screen Shot 2016-02-25 at 5.32.00 PM.png

       

      Not sure we can use const instead of variable (var)?

       

      Regards,

      Karthi

        • 1. Re: Constant Value in Prompt box
          TᴀW Adobe Community Professional & MVP

          Prompt() takes 3 arguments:

           

          a = 10;

          prompt("hello", a, "Script Name");

           

          First, the message, then the default value, and finally the window name (I think this is Windows-only).

           

          HTH,

          Ariel

          • 2. Re: Constant Value in Prompt box
            tpk1982 Level 4

            Hi Ariel,

             

            Thanks for your reply.  I asked this question for my script which converting selected text to table. For this i need to enter the table width. For a book, the values will not be changed. So if i give the first time then it have to take the previous value automatically.

             

            My coding:

             

            app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
            app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
                       
            var myWidth=prompt("PLEASE ENTER YOUR TEXT FRAME WIDTH VALUE (IN POINTS)","")
            if(myWidth!=null)
            {
            myDoc=app.selection[0];
            app.findTextPreferences = null;    app.changeTextPreferences = null; 
            app.selection[0].ruleAbove=false
            app.selection[0].ruleBelow=false
            app.selection[0].convertToTable("\t","\t",1) ;
            app.selection[0].spaceBefore = "0pt";
            app.selection[0].paragraphs[0].tables[0].cells.everyItem().width = (myWidth);
            app.findTextPreferences = null;    app.changeTextPreferences = null; 
            app.findGrepPreferences = null;    app.changeGrepPreferences = null; 
            }
            

             

            Is this possible?

             

            Regards,

            Karthi

            • 3. Re: Constant Value in Prompt box
              TᴀW Adobe Community Professional & MVP

              Just save the value as a document label:

               

              myDoc.insertLabel("KarthiWidth", String(myWidth));

               

              and then extract it when you want to use it:

               

              myWidth = Number(myDoc.extractLabel("KarthiWidth"));

              • 4. Re: Constant Value in Prompt box
                tpk1982 Level 4

                Hi ,

                 

                Sorry to ask the spoon feeding question. This is the first time i am going to use Script label. Is it the way the below coding will work?

                 

                app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS; 
                app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS; 
                myDoc=app.activeDocument;
                var myWidth=prompt("PLEASE ENTER YOUR TEXT FRAME WIDTH VALUE (IN POINTS)","") 
                if(myWidth!=null) 
                { 
                myDoc.insertLabel("KarthiWidth", String(myWidth));
                myWidth = Number(myDoc.extractLabel("KarthiWidth"));
                myDoc=app.selection[0]; 
                app.findTextPreferences = null;    app.changeTextPreferences = null; 
                app.selection[0].ruleAbove=false 
                app.selection[0].ruleBelow=false 
                app.selection[0].convertToTable("\t","\t",1) ; 
                app.selection[0].spaceBefore = "0pt"; 
                app.selection[0].paragraphs[0].tables[0].cells.everyItem().width = (myWidth); 
                app.findTextPreferences = null;    app.changeTextPreferences = null; 
                app.findGrepPreferences = null;    app.changeGrepPreferences = null; 
                } 
                

                 

                Thanks,

                Karthi

                • 5. Re: Constant Value in Prompt box
                  TᴀW Adobe Community Professional & MVP

                  Well, not quite. Before you display the prompt, you want to extract the label. So move line 08 to before 04, and change 04 to something like:

                   

                  myWidth = prompt("PLease enter etc....", myWidth)

                   

                  and then it should work. Obviously, test it first.

                   

                  Ariel

                  • 6. Re: Constant Value in Prompt box
                    tpk1982 Level 4

                    Hi Ariel,

                     

                    Thank a ton. It is working like a charm.

                     

                    Regards,

                    Karthi