11 Replies Latest reply on Jul 30, 2016 11:14 PM by Al_Nikoros

    Custom calculation script to ignore blank fields

    emilym97521869

      Hello there,

       

      I would love some help in finding out what is not working with my calculation code.

       

      I have 10 fields that I want to add together.  The tricky bit is that the fields data is an smpte code in a hh:mm:ss:ff format so I can't do a standard calculation.

       

      I have the calculation working to subtract one fields value with another (with help previously on here) and I have tweaked the code for this new function.  However the calculation only seems to appear in the required field when I delete the last fields entry - very odd as still includes this deleted data in the calculation?

       

      Not sure how to solve this.

       

      In addition I also need the calculation field to ignore any blank fields if any of the ten fields don't have any value in.

       

      Appreciate any guidance.

       

      I have pasted the code below - This is entered into the 'calculation fields' custom calculation script window.  Using Acrobat Pro XI

       

      var t1 = this.getField("P1.Spawn page.P1.Actions page.CUT 1").value;

      var t2 = this.getField("P1.Spawn page.P1.Actions page.CUT 2").value;

      var t3 = this.getField("P1.Spawn page.P1.Actions page.CUT 3").value;

      var t4 = this.getField("P1.Spawn page.P1.Actions page.CUT 4").value;

      var t5 = this.getField("P1.Spawn page.P1.Actions page.CUT 5").value;

      var t6 = this.getField("P1.Spawn page.P1.Actions page.CUT 6").value;

      var t7 = this.getField("P1.Spawn page.P1.Actions page.CUT 7").value;

      var t8 = this.getField("P1.Spawn page.P1.Actions page.CUT 8").value;

      var t9 = this.getField("P1.Spawn page.P1.Actions page.CUT 9").value;

      var t10 = this.getField("P1.Spawn page.P1.Actions page.CUT 10").value;

       

      if (t1 != 0 && t2 != 0 && t3 != 0 && t4 != 0 && t5 != 0 && t6 != 0 && t7 != 0 && t8 != 0 && t9 != 0 && t10 != 0) {

        event.value = frames_to_timecode (timecode_to_frames(t1) + timecode_to_frames(t2) + timecode_to_frames(t3) + timecode_to_frames(t4) + timecode_to_frames(t5) + timecode_to_frames(t6) + timecode_to_frames(t7) + timecode_to_frames(t8) + timecode_to_frames(t9) + timecode_to_frames(t10));

      }

      else {

          event.value = "";

      }

       

      I also have the following (again thanks to assistance on here) pasted into the document level scripts to work out the smpte code format.

       

      var framerate = 24

       

      function timecode_set_framerate(rate) {

        framerate = rate;

      }

       

      function timecode_get_framerate() {

        return framerate;

      }

       

      function timecode_to_frames(timecode) {

          var a = timecode.split(':');

          return ((Number(a[0])*3600 + Number(a[1])*60 + Number(a[2]))*framerate + Number(a[3]));

      }

       

      function frames_to_timecode(frames) {

        return util.printf("%02d:%02d:%02d:%02d",

          Math.floor(frames / (3600 * framerate)),

          Math.floor((frames / (60 * framerate)) % 60),

          Math.floor((frames / framerate) % 60),

          frames % framerate);

      }