Skip to main content
revathiv80720177
Known Participant
January 27, 2017
Question

Error in fitting dragged table using JavaScript - InDesign CC 2015.4

  • January 27, 2017
  • 2 replies
  • 374 views

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.cells.insertionPoints[0].texts[0].horizontalOffset.


I have mentioned below the script:

//Get the Cell Widths

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

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

{

if(mySel.tables.cells.insertionPoints.length>0)

{

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

{

var newWidth;

var startPt,endPt;

newWidth = mySel.tables.cells.leftInset + mySel.tables.cells.rightInset;

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

try{

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

endPt = mySel.tables.cells.texts[mySel.tables.cells.texts.length-1].endHorizontalOffset;

}

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


var len = endPt - startPt;

newWidth = newWidth+ len;

cellWidth = newWidth;

}

}

}


//Fit header Column First

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

{

if(mySel.tables.cells.insertionPoints.length>0)

{

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

{

var newWidth;

var startPt,endPt;

newWidth = mySel.tables.cells.leftInset + mySel.tables.cells.rightInset;

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

//this line shows error

endPt = mySel.tables.cells.texts[mySel.tables.cells.texts.length-1].endHorizontalOffset;

var len = endPt - startPt;

newWidth = newWidth+ len;

//mySel.tables.cells.parentColumn.width=newWidth;


if(mySel.tables.cells.leftInset<=0)

{

newWidth=newWidth*100;

mySel.tables.cells.parentColumn.width = newWidth; //alert(table.cells.parentColumn.width);

}


else if(mySel.tables.cells.leftInset<100)

{

// newWidth=newWidth*10;

mySel.tables.cells.parentColumn.width = newWidth; //alert(table.cells.parentColumn.width);

}

}

}

}

Thanks and Regards,

Revathi V

This topic has been closed for replies.

2 replies

Community Expert
January 27, 2017

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".

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);

};

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:

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

Loic.Aigon
Legend
January 27, 2017

Check

$.writeln( mySel.isValid);

$.writeln( mySel.tables.isValid );

$.writeln( mySel.tables.cells.isValid );

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

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

$.writeln( mySel.tables.cells.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

revathiv80720177
Known Participant
January 31, 2017

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.cells.leftInset + mySel.tables.cells.rightInset;

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

     // endPt  = mySel.tables.cells.texts[mySel.tables.cells.texts.length-1].endHorizontalOffset;

     try {

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

         endPt = table.cells.insertionPoints[table.cells.insertionPoints.count() - 1].texts[table.cells.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.columns.width = mySel.tables.columns.width * 3;

function FitTable (mySel)

{

  mySel.recompose();

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

  {

  var table = mySel.tables;

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

  {

 

     if (mySel.tables.columns.width < 100) {

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

     }

     else {

         table.columns.width = mySel.tables.columns.width;

      

     }

  }

Regards,

Revathi V