11 Replies Latest reply on Dec 6, 2012 5:27 AM by sundar_r

    Alert message!

    sundar_r Level 1

      Hi experts,

       

      This is a simple script to delete unused swatches. I need a clarification regarding the alert message.

      My clarification is: If the document not having unused swatches, the alert should pop-up as "the doc has no unused swatches". As per the below script the alert message shows for every increment (cos it's inside the loop).

       

      What I need is, if the there is no task done the alert should pop=up, else the task should complete without alert.

       

      var mydoc=app.documents.item(0);

      var mydeleteswatches=mydoc.unusedSwatches;

       

      for (i=0;i<mydeleteswatches.length;i++) {

          var mydeleteswatch=mydeleteswatches[i];

         

          if (mydeleteswatch.name!="") {

              mydeleteswatch.remove();

              }

      else {

          alert ("the doc has no unused swatches")

          }

      }

       

       

      Help me out guys!

        • 1. Re: Alert message!
          Peter Kahrel Adobe Community Professional & MVP

          The clarification has nothing to do with the alert message, but with your understanding of for-loops:

           

          if (mydeleteswatches.length == 0) {

             alert (...)

          } else {

             for loop

          }

           

          Peter

          • 2. Re: Alert message!
            sundar_r Level 1

            Yes Kahrel, but I need the alert if there no unused swatches in the doc.

             

            I had modified script as per your review. Correct where I am going wrong.

             

            var mydoc=app.documents.item(0);

            var mydeleteswatches=mydoc.unusedSwatches;

             

             

            if (mydeleteswatches.length==0) {

                alert ("0");

                }

             

            else {

                 for (j=0;j<mydeleteswatches.length;j++) {

                var mydeleteswatch=mydeleteswatches[j];

               

                if (mydeleteswatch.name!="") {

                    mydeleteswatch.remove();

                    }

                }

            }

             

            If I bring the alert inside the function, it's not get pop=up, but the task is perfect.

             

            Thanks much for your kind review.

            • 3. Re: Alert message!
              indegn5

              sundar,

               

              try this da,

               

              var mydoc=app.documents.item(0);

                      var mySwatches = mydoc.unusedSwatches;

                      var name = mySwatches.name;

               

               

              for (i=0;i<mySwatches.length;i++) {

                  var mySwatch=mySwatches[i];

               

               

              if (mySwatch.name!="") {

                      mySwatch.remove();

                      }

              }

               

               

                if (mydoc.unusedSwatches[i] != "") {

                    alert ("doc has no unused swatches")

                    }

               

              please reply me.

               

              babylon.

              • 4. Re: Alert message!
                sundar_r Level 1

                Not working rajni,

                 

                It shows alert, even if the doc has unused swatches.

                 

                Thanks

                • 5. Re: Alert message!
                  [Jongware] Most Valuable Participant

                  So only if there are no unused swatches, the alert should pop up? Then reverse your logic:

                   

                  var mydoc=app.documents.item(0);
                  var mydeleteswatches=mydoc.unusedSwatches;
                  
                  /* insertion */
                  if (mydeleteswatches.length == 0)
                    alert ("the doc has no unused swatches")
                  else
                  /* end insertion */
                  
                  for (i=0;i<mydeleteswatches.length;i++) {
                    var mydeleteswatch=mydeleteswatches[i];
                  
                    if (mydeleteswatch.name!="") {
                      mydeleteswatch.remove();
                    }
                  }
                  
                  • 6. Re: Alert message!
                    sundar_r Level 1

                    Yes Jongware!, I had tried this too as per peter kahrel, even though it's not pop up. I don't know what's happening

                    • 7. Re: Alert message!
                      Cenchen Level 2

                      Try this,

                       

                               

                      var mydoc=app.documents.item(0);
                      var mydeleteswatches=mydoc.unusedSwatches;
                      var flag =0;
                      for (i=0;i<mydeleteswatches.length;i++) {
                          var mydeleteswatch=mydeleteswatches[i];
                          if (mydeleteswatch.name!="") {
                              mydeleteswatch.remove();
                              flag = 1;
                              }
                      }
                      if(flag == 0) {
                          alert ("the doc has no unused swatches")
                      }
                      • 8. Re: Alert message!
                        indegn5 Level 1

                        an incredulous gasp

                         

                        thanks Cenchen,

                         

                        it help me also..

                         

                        boby....!

                        • 9. Re: Alert message!
                          sundar_r Level 1

                          Great cenchen!, simple and good.

                           

                          I have a doubt. What that "flag" means? Is this a similar function as "alert"

                           

                          Thanks much in advance!

                          • 10. Re: Alert message!
                            Cenchen Level 2

                            @sundar

                                 Its temporary flag variable. If unusedSwatches found then flag = 1 else flag =0.

                            1 person found this helpful
                            • 11. Re: Alert message!
                              sundar_r Level 1

                              Wow. Thanks again cenchen.