3 Replies Latest reply on Mar 3, 2011 1:34 PM by Jo_2005

    Document Title Split String Script to Incorporate in an If Statment

    Jo_2005 Level 1

      Hello,

       

      I have a console script which will extract the file extension from the title in the document properties:

       

      firstWord = this.info.Title.split("."); event.value = firstWord[1];

       

      Example document title is:  DWGTest.idw

       

      After the script is run from the console it will show the file extension correctly as:  idw

       

      I now need to incorporate the script with an if statement and then perform an action.

       

      However after the script is run I get an syntax error.

       

      Can anyone please advise how I can modify the script to work correctly?

       

      // If the title in the document properties contains the file extension idw then create a signature field

       

       

      firstWord = this.info.Title.split("."); event.value = firstWord[1];

      if (firstWord == "idw")

      {

      var numpages = this.numPages;

      for (var i=0; i < numpages; i++)

       

       

      var a = this.addField("Chk R1", "signature", 0,

      [1093, 119.5, 1054.5, 136.5]);

      }

       

      Any assistance will be most appreciated.

       

      Thank you.

       

        • 1. Re: Document Title Split String Script to Incorporate in an If Statment
          George_Johnson MVP & Adobe Community Professional

          Try simplifying it a bit. That code is attempting to add a signature field multiple times to the same location on the first page, assuming there are multiple pages, and the rect doesn't look correct.

           

          var firstWord = info.Title.split(".")[1];
          
          if (firstWord === "idw") {
              addField("Chk R1", "signature", 0, [54.4, 136.5, 93, 119.5]);
          }
          

           

          Note that I changed the field boundaries (left and right side) in an attempt to ensure that the field would be placed on the page. What is the width and height of your pages? The values of the rect can be read as "left side, top, right side, bottom", with the origin (0,0 point) being the lower-left corner of the page. The values are in points and there are 72 points per inch.

          • 2. Re: Document Title Split String Script to Incorporate in an If Statment
            try67 MVP & Adobe Community Professional

            You're misusing firstWord. The split method returns an array, not a string.

             

            For the future, it would be helpful if you also publish the error message

            you're getting, as it usually contains the information necessary to solve

            the problem.

            1 person found this helpful
            • 3. Re: Document Title Split String Script to Incorporate in an If Statment
              Jo_2005 Level 1

              Thank you very much for your help, George.

               

              The script now works, and if the title of the document contains idw as a file extension the signature field will be added.

               

              In regards to the value of the co-ordinates, the document is an A1 sized drawing which originated in inventor.  Hence the idw file extension.

               

              I will be adding to the script if statement shortly to include dwg file extensions for Autocad which will have slightly different co-ordinates for the signature field to that of the inventor drawing.

               

              var firstWord = info.Title.split(".")[1];

              if (firstWord === "idw") {
              addField("Chk R1", "signature", 0, [1093, 119.5, 1054.5, 136.5]);
              }

               

              Thanks once again, your assistance is most appreciated.