Skip to main content
dulajun
Inspiring
September 6, 2022
Answered

Cell object is null!

  • September 6, 2022
  • 4 replies
  • 777 views

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:

Cell object is null! – Adobe InDesign (uservoice.com)

This topic has been closed for replies.
Correct answer Laubender

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 )

4 replies

brian_p_dts
Community Expert
Community Expert
September 6, 2022

Another relevant thread that I think speaks to this bug: https://community.adobe.com/t5/indesign-discussions/weird-behaviour-of-itembyrange-function/m-p/12470812#M450154

 

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. 

 

dulajun
dulajunAuthor
Inspiring
September 7, 2022

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.

Community Expert
September 6, 2022

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 )

LaubenderCommunity ExpertCorrect answer
Community Expert
September 6, 2022

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 )

Community Expert
September 6, 2022

Wheras app.selection[0].cells.length returns 3.

Crazy…

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Community Expert
September 6, 2022

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 )

dulajun
dulajunAuthor
Inspiring
September 6, 2022

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.