Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Dead Loop? How do I jump out and why do I get two results for the same text box?

Guide ,
Jan 01, 2025 Jan 01, 2025

What I'm thinking of is determining if the last row is empty.
If it's empty, set it to footer.
If it's not empty, add one empty row at the end and set the empty row to footer.

 

When you don't expand the text box, it says “empty”. (This is actually wrong.)

When you expand the box, it says “not empty” again.

 

I'm a little confused about functions, methods, and objects.
Also, if you take out the Break, it becomes a dead loop?
How do I get the code after it to run?

 

Please guide me.

Thank you very much.

See attachment for sample. 

“alter” is used for testing. Can be deleted

 

 

 

 

var cell = app.activeDocument.selection[0].parent;
var myTable = cell.parent;

var myFooterRow = myTable.rows[-1];
dupeLastRow(myTable);

function dupeLastRow(p){
	
	var isLastRowEmpty = true;
	for (var j = 0; j < myFooterRow.cells.length; j++) {
		if (myFooterRow.cells[j].contents !== "") {
			isLastRowEmpty = false;
			alert("No-empty");
			break;
		}
		else{
			isLastRowEmpty = true;
			alert("empty");
				break;
		}
	}
	if(isLastRowEmpty = false){
		myTable.rows.add(LocationOptions.AFTER, myTable.rows[-1]);
		myFooterRow = myTable.rows[-1];
	}
	else{
		isLastRowEmpty = true;
		myFooterRow = myTable.rows[-1];
	}
	}

 

 

 

 Unexpanded.jpgExpand fully.jpg

TOPICS
Bug , Feature request , How to , Scripting
504
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2025 Jan 01, 2025

Invisible cells - cells that are in the overset text - your 1st table in the screenshot - or cells that are completely overset - no text inside, just red dot - do not have any contents. 

 

So your if should be:

 

 

    if (myFooterRow.cells[j].texts[0].contents !== "") {

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 01, 2025 Jan 01, 2025

Thnak you.

The judgment seems to be right, for some reason the last "if else" doesn't run

I've deleted break.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 01, 2025 Jan 01, 2025
Oh, I think so.
isLastRowEmpty = false
Should be isLastRowEmpty == false
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 01, 2025 Jan 01, 2025
quote
Oh, I think so.
isLastRowEmpty = false
Should be isLastRowEmpty == false

By @dublove

 

Yes, in JS even in the if, one "=" is "assignment" so you need to use double "==" for comparison. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 02, 2025 Jan 02, 2025

> Invisible cells - cells that are in the overset text - or cells that are completely overset - no text inside, just red dot - do not have any contents. 

 

That's not true: if a cell with content is in an invisible row, its content is returned as if it were visible.

 

Because InDesign pushes everything out of a cell when it's overset, it's difficult to tell the difference between a visible overset cell and a cell in an overset row (an invisible row).

 

One way of making sure that overset rows won't bite you is to expose a table when one or more rows are in overset text. The test is to check how many lines the table's parent paragraph has:

 

if (myTable.storyOffset.paragraphs[0].lines.length > 1) {
  // expose the table by making the text frame taller
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 02, 2025 Jan 02, 2025

I don't really understand it.
Haven't come across an example to test.
Hopefully I'll never run into this mine.

 

It's too hard to try to actively create a bug.
Is this the one below? This one recognizes a “true empty row”.

Anyone have a bug to offer?

069.jpg

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 25, 2025 Jan 25, 2025
LATEST

Hi. - Peter Kahrel 
I never understood how to use what you said.
Just noticed that this code sometimes deletes the last line by mistake.

I would have intended it to be that way:
Determine if the last line is empty, and if it is, turn it directly into a footer.
If it's not empty, add a new line and set it to footer.

Maybe this is unnecessary and dangerous?

Thank you very much

 

For example, below I mention this table.
The total line will be mistaken for a footer, and as a result the content will be deleted.
Very dangerous.

 

 

function dupeLastRow(p){
		var isLastRowEmpty = true;
	for (var j = 0; j < myFooterRow.cells.length; j++) {
		if ((myFooterRow.cells[j].texts[0].contents !== "")&&(myTable.storyOffset.paragraphs[0].lines.length > 1)) {
			isLastRowEmpty = false;
			//alert("No-empty");
			//break;
		}
		else{
			isLastRowEmpty = true;
			//alert("empty");

		}
	}

	if(isLastRowEmpty == false){
		myTable.rows.add(LocationOptions.AFTER, myTable.rows[-1]);
		myFooterRow = myTable.rows[-1];
			//alert("No-empty");
			//break;
	}
	else{
		myFooterRow = myTable.rows[-1];
		//alert(isLastRowEmpty);
	}

	}

 

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines