3 Replies Latest reply on Jan 31, 2017 4:44 AM by revathiv80720177

    Error in fitting dragged table using JavaScript - InDesign CC 2015.4

    revathiv80720177 Level 1

      Hi all,


      I have a script for drag, drop and fitting a table. When a normal table is dragged and dropped it fits without any issues. But when I try to drag drop tables of sub-divided rows and columns (super and pivot tables) am getting the following error:


      Error String : The property is not applicable in the current state.

      Error Line:startPt = mySel.tables[j].cells[i].insertionPoints[0].texts[0].horizontalOffset.


      I have mentioned below the script:

       

      //Get the Cell Widths

      var cellWidth = new Array(mySel.tables[j].cells.length);

      for( var i = 0; i< mySel.tables[j].cells.length ;i++ )

      {

      if(mySel.tables[j].cells[i].insertionPoints.length>0)

      {

      if(mySel.tables[j].cells[i].insertionPoints[0].texts.length>0)

      {

      var newWidth;

      var startPt,endPt;

      newWidth = mySel.tables[j].cells[i].leftInset + mySel.tables[j].cells[i].rightInset;

      mySel.tables[j].cells[i].insertionPoints[0].texts[0].recompose();

      try{

      startPt = mySel.tables[j].cells[i].insertionPoints[0].horizontalOffset;

      endPt = mySel.tables[j].cells[i].texts[mySel.tables[j].cells[i].texts.length-1].endHorizontalOffs et;

      }

      catch(errCode){startPt=0;endPt=0;}


      var len = endPt - startPt;

      newWidth = newWidth+ len;

      cellWidth[i] = newWidth;

      }

      }

      }


      //Fit header Column First

      for( var i = 0; i< mySel.tables[j].columns.length ;i++ )

      {

      if(mySel.tables[j].cells[i].insertionPoints.length>0)

      {

      if(mySel.tables[j].cells[i].insertionPoints[0].texts.length>0)

      {

      var newWidth;

      var startPt,endPt;

      newWidth = mySel.tables[j].cells[i].leftInset + mySel.tables[j].cells[i].rightInset;

      startPt = mySel.tables[j].cells[i].insertionPoints[0].texts[0].horizontalOffset;

      //this line shows error

      endPt = mySel.tables[j].cells[i].texts[mySel.tables[j].cells[i].texts.length-1].endHorizontalOffs et;

      var len = endPt - startPt;

      newWidth = newWidth+ len;

      //mySel.tables[j].cells[i].parentColumn.width=newWidth;


      if(mySel.tables[j].cells[i].leftInset<=0)

      {

      newWidth=newWidth*100;

      mySel.tables[j].cells[i].parentColumn.width = newWidth; //alert(table.cells[i].parentColumn.width);

      }


      else if(mySel.tables[j].cells[i].leftInset<100)

      {

      // newWidth=newWidth*10;

      mySel.tables[j].cells[i].parentColumn.width = newWidth; //alert(table.cells[i].parentColumn.width);

      }

      }

      }

      }

       

       

       

      Thanks and Regards,

      Revathi V

        • 1. Re: Error in fitting dragged table using JavaScript - InDesign CC 2015.4
          Loic.Aigon Adobe Community Professional

          Check

           

          $.writeln( mySel.isValid);

          $.writeln( mySel.tables[j].isValid );

          $.writeln( mySel.tables[j].cells[i].isValid );

          $.writeln( mySel.tables[j].cells[i].insertionPoints[0].isValid );

          $.writeln( mySel.tables[j].cells[i].insertionPoints[0].texts[0].isValid );

          $.writeln( mySel.tables[j].cells[i].insertionPoints[0].texts[0].horizontalOffset );

           

          Then you will see who is guilty here.

           

          If you use the ESTK,  simply use $.bp(); then investigate in the data panel

          • 2. Re: Error in fitting dragged table using JavaScript - InDesign CC 2015.4
            Laubender Adobe Community Professional & MVP

            Hi Revathi,

            you want to get access to the value of horizontalOffset of the first insertion point in a cell.

            This value is only available if the insertion point in the cell can show.

             

            So "The property is not applicable in the current state." could mean that the cell is overset and property overflow returns true.

             

            Here a case where the insertion point cannot show, because the cell is of fixed height and the point size of the text is too large.

            From my German InDesign also showing the Story Editor window. "Übersatz" means "overflow" or "overset".1-SecondCell-Overset.png

            If I run the following snippet on that selection my German InDesign will answer with a German version of your error message:

            "Diese Eigenschaft ist im aktuellen Status nicht zutreffend."

             

            try{
            app.selection[0].tables[0].cells[1].insertionPoints[0].horizontalOffset
            }catch(e)
            {
                alert(e.message);
                $.writeln(e.message);
            };
            

             

            2-SecondCell-Overset-ErrorMessage.png

            Maybe at first glance you will not see the "red dot" in the cell showing the cell overflows, because the contents is empty?
            Like that:

             

            3-variant-SecondCell-Overset-NoContents.png

            Note: The end of story marker is also missing in the cell.

            Because you cannot see the end of the story. And the culprit here is an insertion point that is formatted with 32 pt and cell is of fixed height.

             

            Also look for other formatting in your table cell that would force overset cells.

             

            Regards,
            Uwe

            • 3. Re: Error in fitting dragged table using JavaScript - InDesign CC 2015.4
              revathiv80720177 Level 1

              Hi Aigon and Uwe,

               

              Thanks for your response.

              The error has been fixed.But facing another error.

              I have written my script as:

               

              //Fit header Column First

              .

              .

              .

              .

               

                var newWidth;

                var startPt,endPt;

                newWidth = mySel.tables[j].cells[i].leftInset + mySel.tables[j].cells[i].rightInset;

                // startPt = mySel.tables[j].cells[i].insertionPoints[0].texts[0].horizontalOffset;

                   // endPt  = mySel.tables[j].cells[i].texts[mySel.tables[j].cells[i].texts.length-1].endHorizontalOffs et;

                   try {

                       startPt = table.cells[i].insertionPoints[0].texts[0].horizontalOffset;

                       endPt = table.cells[i].insertionPoints[table.cells[i].insertionPoints.count() - 1].texts[table.cells[i].texts.length - 1].endHorizontalOffset;

                   }

                   catch (errCode) { startPt = 0; endPt = 0; }// I have modified this part

                .

              .

              .

              .

               

                }

                }

              }

               

               

              Now I am able to fit tables without any error.When I am trying to fit a table with image I am able to fit it without any error for a normal table.When I am trying to fit a table with sub-divided rows and columns and with images ,Iam getting the following error:

               

              Error String:Invalid width for set property width.Expected unit,but received  "135"

              Error Line: mySel.tables[j].columns[i].width = mySel.tables[j].columns[i].width * 3;

               

              function FitTable (mySel)

              {

                mySel.recompose();

                for( var j = 0; j< mySel.tables.length ; j++ )

                {

                var table = mySel.tables[j];

                for( var i = 0; i< mySel.tables[j].columns.length ;i++ )

                {

               

                   if (mySel.tables[j].columns[i].width < 100) {

                     table.columns[i].width = mySel.tables[j].columns[i].width * 3;   //getting error in this line         

                   }

                   else {

                       table.columns[i].width = mySel.tables[j].columns[i].width;

                    

                   }

                }

               

              Regards,

              Revathi V