Skip to main content
Inspiring
April 26, 2023
Answered

How to get coordinates of table cell in a multi column text frame

  • April 26, 2023
  • 4 replies
  • 2584 views

Hi All,

 

I am using following code to get the table coordinate as it shown in the info panel.

 

InterfacePtr<ITextStoryThread> storyThread(txtModel->QueryStoryThread(startPos + 1));
if(storyThread){
GridAddress gridAdd;
ParcelKey parcelKey;
 
InterfacePtr<ICellContent> cellcontentp(storyThread, UseDefaultIID());
if(cellcontentp){
gridAdd = cellcontentp->GetGridAddress();
parcelKey = cellcontentp->GetNthParcelKey(0);
}
else {
break;
}
 
InterfacePtr<ITableLayout> tableLayout(tableModel, UseDefaultIID());
if(tableLayout){
ITableLayout::frame_iterator begframeIter = tableLayout->begin_frame_iterator();
ITableLayout::frame_iterator endframeIter = tableLayout->end_frame_iterator();
 
// Having problem in getting ITableFrame directly from the startPos
// So iterate over the table frames to find which one contains the address of our cell content
for(;begframeIter != endframeIter; ++begframeIter){
InterfacePtr<ITableFrame> tableFrame(begframeIter->QueryFrame());
if(tableFrame){
CellParcelAddr cpa(gridAdd, parcelKey);
if(tableFrame->Contains(cpa)){
GridID gridID(cellcontentp->GetGridID());
GridAddress gridAddress(cellcontentp->GetGridAddress());
 
// Till here, the point seems to be right, we need to convert to table and then to frame coords i guess
// InterfacePtr<ITableGeometry> tableGeo(tableModel, UseDefaultIID());
// PMRect cellRect = tableGeo->GetCellBounds(gridAddress);
PMRect cellRect = tableFrame->GetCellBounds(gridAddress);
int32 xPos = cellRect.Left();
int32 yPos = cellRect.Bottom() - cellRect.Height();
}
}
}
}
}
 
Can some suggest a good approach to get the x,y coordinate of table cell in multi column frame.

 

Regards,

Alam

This topic has been closed for replies.
Correct answer Pickory

This should give you the rect relative to parent frame. Seems to work with tables within tables.

 

How you arrive at storythreadp and key is up to you.

 

As Dirk mentioned you will have to consider indents and others.

 

                InterfacePtr<ICellContent> cellcontentp(storythreadp, UseDefaultIID());

                if ( cellcontentp )

.... .... ...

                    PMRect cr = cellcontentp->GetCellPathBounds ( key );

                    PMMatrix m = cellcontentp->GetParcelToFrameMatrix ( key );

                    m.Transform ( &cr );

... ... ...

4 replies

PickoryCorrect answer
Legend
April 29, 2023

This should give you the rect relative to parent frame. Seems to work with tables within tables.

 

How you arrive at storythreadp and key is up to you.

 

As Dirk mentioned you will have to consider indents and others.

 

                InterfacePtr<ICellContent> cellcontentp(storythreadp, UseDefaultIID());

                if ( cellcontentp )

.... .... ...

                    PMRect cr = cellcontentp->GetCellPathBounds ( key );

                    PMMatrix m = cellcontentp->GetParcelToFrameMatrix ( key );

                    m.Transform ( &cr );

... ... ...

alam_84Author
Inspiring
May 4, 2023

Hi Pictory,

 

Thanks for info yes the above code works

After transform api, I checked PMRect cr for left, top, bottom and right

and it gives the cell x,y position but not the x,y position of start of text in each cell.

And I further used following code to get the x,y position from the start of text in each cell

InterfacePtr<ITableModel>tableModel(tableFrame->QueryModel());

if(!tableModel){

break;

}

// Getting cell inset

InterfacePtr<ITableAttrAccessor> attrAccessor(tableModel, UseDefaultIID());

if (!attrAccessor)

break;

 

        InterfacePtr<ITableAttrRealNumber> parentLeftInsetNumber(attrAccessor->QueryCellAttribute(gridAddress, kCellAttrLeftInsetBoss, IID_ITABLEATTRREALNUMBER), UseDefaultIID());

        PMReal parentLeftInset = parentLeftInsetNumber->Get();

 

Regards,

Alam

Legend
May 4, 2023

Look at IWaxLine

 

                        InterfacePtr<ITableModel> tableModel(cellcontentp->GetTableModel(), UseDefaultIID());

                        if ( !tableModel )

                            break;

                        InterfacePtr<ITableAttrAccessor> attrAccessor(tableModel, UseDefaultIID());

                        if ( !attrAccessor )

                            break;

                        InterfacePtr<ITableAttrRealNumber> leftInset((ITableAttrRealNumber*)attrAccessor->QueryCellAttribute

                                                                     (cellcontentp->GetGridAddress(), kCellAttrLeftInsetBoss, IID_ITABLEATTRREALNUMBER));

                        PMReal leftInsetValue = 0;

                        if (leftInset != nil) {

                            leftInsetValue = leftInset->Get();

                        }

 

Legend
April 27, 2023

Not sure whether it is relevant, but I iterate the cells straight from ITableModel.

Using QueryCellContentBoss() I likely end up at the same ICellContent as your cellcontentp.

To the parcel via GetNthParcelKey.

GetParcelToFrameMatrix looks promising (growing tx).

There could be better ways, I've covered only few interfaces.

 

Of course you should also handle overset, graphics cells etc.

Legend
April 27, 2023

Btw, the parcel's GetParcelFrameUID() is the matching kFrameItemBoss (text column) within the kMultiColumnItemBoss (actual text frame) if you prefer to compute on coordinates.

alam_84Author
Inspiring
April 28, 2023

Hi Dirk,

I could get the ITableFrame from api GetParcelFrameUID and if I use GetCellBounds() then it return same top, left for first column in each row whereas left of 2nd and 3rd row should be different.

Let me know the next step that I should follow

Community Expert
April 26, 2023

Oh. Sorry. You are looking for a SDK solution.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

alam_84Author
Inspiring
April 26, 2023

Yes, I am looking for SDk solution.

Legend
April 26, 2023

Have a look at the transforms in ITableFrame.h.

 

virtual PMMatrix GetToFrameMatrix() const = 0;

Community Expert
April 26, 2023

Hi @alam_84 ,

search the InDesign forum, recently we had a solution for this:

 

How to get coordinates of table column or cell
Phil28637952i5ng, Apr 19, 2023
https://community.adobe.com/t5/indesign-discussions/how-to-get-coordinates-of-table-column-or-cell/td-p/13737665

 

Also look into the TableCellBox.jsx script by Marc Autret:

https://github.com/indiscripts/IdGoodies/blob/master/snip/TableCellBox.jsx

 

The Magic Parent Bounding Box
Marc Autret, August 04, 2022

https://www.indiscripts.com/post/2022/08/magic-parent-bounding-box

 

And a discussion in German that inspired Marc Autret at hilfdirselbst.ch:

https://www.hilfdirselbst.ch/foren/Koordinaten_einer_Tabellenzelle_P583998.html

 

Regards,
Uwe Laubender
( Adobe Community Expert )