Copy link to clipboard
Copied
I get the third merged cell as null. Why is that?
Please to get the error First create new document and table 3 by 3 and merge and select cells like screenshot. Execute the script.
var sel = app.selection[0];
var queuedCells = getQueuedCells ([sel]);
function getQueuedCells (deepCells) {
var queuedCells = new Array;
if (deepCells.length > 0) {
targetIndex = null;
targetIndex = deepCells[0].parentRow.index;
for (var dcs = 0; dcs < deepCells.length; dcs++) {
for (var dcc = 0; dcc < deepCells[dcs].cells.length; dcc++) {
alert ("(deepCells[" + dcs + "].cells[" + dcc + "] != null) " + (deepCells[dcs].cells[dcc] != null));
if (targetIndex == deepCells[dcs].cells[dcc].parentRow.index) {
queuedCells.push (deepCells[dcs].cells[dcc]);
}
}
}
}
return queuedCells;
}
Also I posted as a bug here:
1 Correct answer
Well, seems you discovered a bug!
I have no idea if this can be fixed or will be fixed.
Also tested and I see exactly the same. Let's name the column A,B,C and the cells 1,2,3 in a row. Then selected cells are:
A2, A3, B2 merged with B3 will only return two [object Cell] when we work with app.selection[0]. Yes, this must be a bug. Only A2 and A3 are returned by scripting.
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
Hi @dulajun ,
what will be returned with:
app.selection[0].cells.everyItem().getElements();
Is it an array of three cells?
Or will InDesign crash?
( Had something like this in a slightly different situation when working with merged cells. )
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
InDesign application doesn't crash.
But it's supposed to be three cells according to the selected ones.
My script returned three cells but the third is null.
I tried to add
.everyItem().getElements();
and I get tow elements without the third merged one.
Copy link to clipboard
Copied
I executed the following code and get 2 in first screenshot and 3 in the second.
var r = app.selection[0].cells.everyItem().getElements();
alert (r.length);
Copy link to clipboard
Copied
Well, seems you discovered a bug!
I have no idea if this can be fixed or will be fixed.
Also tested and I see exactly the same. Let's name the column A,B,C and the cells 1,2,3 in a row. Then selected cells are:
A2, A3, B2 merged with B3 will only return two [object Cell] when we work with app.selection[0]. Yes, this must be a bug. Only A2 and A3 are returned by scripting.
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
Wheras app.selection[0].cells.length returns 3.
Crazy…
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
Hi @dulajun ,
seems that this bug is very old.
Just tested with InDesign CS6 and its all the same issue.
Only two out of three cells are returned with: app.selection[0].cells.everyItem() . The only thing is that app.selection[0].cells.length returns the right number.
So one could at least detect that there is a bug if you compare cells.length with cells.everyItem().getElements().length. Both values will not match.
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
Another relevant thread that I think speaks to this bug: https://community.adobe.com/t5/indesign-discussions/weird-behaviour-of-itembyrange-function/m-p/1247...
I have always encountered strange errors when dealing with merged cells. My strategy has always been to record values, unmerge, operate on the known, expected range, and remerge.
Copy link to clipboard
Copied
I just reviewed that topic. But I think the difference is that what we've brought up here involves a software bug rather than a functional logical bug.

