Skip navigation
Currently Being Moderated

Not correct CellColNum in FirstCell of SubCol

Aug 2, 2012 4:43 AM

Tags: #table #graphic #cell #subcol

Hello everybody,

 

I try to find out in which column of a table my grafic is placed. I like to adjust each column width depending on the grafic and document size.

The code example at the end of this post just displays my problem.

 

The script is:

- parsing through all grafics

- checking if FrameParent is FO_SubCol

- putting the FirstCell of the SubCol in an object

- calculates the new widths of the column (the example does not include the whole code)

- using the Cell.CellColNum to find the index (vcounter) for the column width in Tbl.TblColWidths

- setting the new TblColWidths

 

The problem:

 

vcounter is always=0, although the grafic is in the second or third column

I expected

0 for column 1

1 for column 2

2 for column 3

 

 

Where is my misunderstandig of the  SubCol, Cell objects?

 

Best Regards

 

hetshjd

 

 

 

 

 

var vGraphic =app.ActiveDoc.FirstGraphicInDoc;

 

 

while(vGraphic.ObjectValid()){   

      vTextLocObj = new TextLoc (vGraphic.FrameParent , 0);

 

     if(vTextLocObj.obj.InTextObj!=null){

           if(vTextLocObj.obj.InTextObj.type==Constants.FO_SubCol)

           {          

              vSubCol= vTextLocObj.obj.InTextObj;

             vCell=vSubCol.FirstCell;

              vTbl=vCell.CellRow.RowTbl;

 

              if(vTbl.TblNumCols<=1){

                  vColWidth=55* docobj.ViewDisplayUnits;

              }      

              else{

                 vColWidth=(130/vTbl.TblNumCols) * docobj.ViewDisplayUnits;                 

              }

            vCounter=vCell.CellColNum;

            vWidths=vTbl.TblColWidths;

            vWidths[vCounter]=vColWidth;

            vTbl.TblColWidths=vWidths;

            }

       }

   vGraphic =vGraphic.NextGraphicInDoc;

}

 
Replies
  • Currently Being Moderated
    Aug 6, 2012 6:15 AM   in reply to hetshjd

    Hi hetshjd,

     

    I got to messing around with this and I'm just as confused as you are. The FirstCell property appears to return a cell object, but it doesn't seem to be a valid object. None of the properties seem to work, including CellColNum. If you try the NextCell property to step across the columns, it continues to return additional cell objects that behave the same.

     

    For example, here's some code I ran, where InTextObj is a subcolumn:

     

    cell = tl.obj.InTextObj.FirstCell;

    i = 0;

     

    while(typeof(cell)!= "undefined" && i < 1000)

    {

        i++;

        cell = cell.NextCellInRow;

    }

     

    alert(i);

     

    ...that loop runs straight to 1000

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 6:20 AM   in reply to Russ Ward

    Sorry, I didn't finish that before clicking Post.

     

    So, the object returned by FirstCell seems to be bogus. Furthermore, if you do this:

     

    alert(cell.id);

     

    ...you get zero, which implies a bogus object.  Furthermore, I did this with the FDK:

     

      cellId = F_ApiGetId(docId, subcolId, FP_FirstCell);

     

    ....and got a zero for the object handle.

     

    So, I think that FirstCell is not what we think it is, or it is unreliable, or something. I think we need somebody to explain this property to us.

     

    Sorry that I couldn't find the answer, but I wanted to at least report what I discovered.

     

    Russ

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 6, 2012 11:01 AM   in reply to Russ Ward

    It is interesting that this property appears valid with FrameScript. If I insert a table on the first page of a blank FrameMaker 10 document, and click in the paragraph containing the table anchor, I can run this:

     

    Set oPgf = TextSelection.Begin.Object;

    Set oSubCol = oPgf.InTextObj;

    Set oCell = oSubCol.FirstCell;

     

    oCell is a valid object; I can query its properties, display its text, etc. However, if the table has a title, the oCell object will actually be the "cell" containing the table title (which is strange).

     

    I don't think the FirstCell property of the SubCol is what you want to use any way. Why not just start with the table object itself and navigate through the cells? Here is how it would be in FrameScript with the selected table, but you can adapt this to ExtendScript:

     

    Set oDoc = ActiveDoc;

    Set oTbl = oDoc.SelectedTbl;

    Set oCell = oTbl.FirstRowInTbl.FirstCellInRow;

    Loop While(oCell)

      // See if the cell contains an anchored frame.

      Get TextList InObject(oCell.FirstPgf) FrameAnchor NewVar(tTextList);

      If tTextList.Count > 0

        // Do something here.

      EndIf

      Set oCell = oCell.NextCellInTbl;

    EndLoop

     

    Or, if you want to start with a graphic object, do something like this.

     

    // Get the anchored frame containing the graphic.

    Set oAFrame = oGraphic.FrameParent;

    // See if the anchored frame is in table cell.

    If oAFrame.TextLoc.InTextObj.ObjectName = 'Cell'

      Set oCell = oAFrame.TextLoc.InTextObj;

      // Do something here.

    EndIf

     

    Rick Quatro

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 7, 2012 6:15 AM   in reply to hetshjd

    Hi bjoern,

     

    If you want to iterate based on graphics, perhaps you might consider a different approach that doesn't involve the FirstCell property. I think that the CellColNum property is OK... it's the FirstCell property that isn't working or we just don't understand how it works.

     

    Here is a little function I ran to verify that CellColNum does work OK, as long as the cell object is valid. I don't know if this methodology will work in your case, but perhaps it will give you some ideas.

     

    function graphicTableTest()

    {

        var doc = app.ActiveDoc;

        var graphic = doc.FirstGraphicInDoc;

       

        //iterate through all the graphics in the doc

        while(typeof(graphic)!="undefined")

        {

            //for this test, we only care about imported files

            if(graphic.type == Constants.FO_Inset)

            {

                //get the frame parent. If it's an anchored frame, then we want to

                //find out if it's in a table cell or not.

                var aframe = graphic.FrameParent;

               

                if(aframe.type == Constants.FO_AFrame)

                {

                    //get the InTextObj of the paragraph that contains the frame anchor

                    var subcol = aframe.TextLoc.obj.InTextObj;

                   

                    //if it is a table cell, report the column

                    if(subcol.type == Constants.FO_Cell)

                    {

                        alert("Graphic '" + graphic.InsetFile + "' is in a table, column " + subcol.CellColNum);

                    }

                    //otherwise, just report

                    else

                    {

                        alert("Graphic '" + graphic.InsetFile + "' is not in a table");

                    }

                }

            }

            graphic = graphic.NextGraphicInDoc;

        }

    }

     

     

     

    Russ

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2012 5:04 AM   in reply to hetshjd

    Hi bjoern,

     

    For future reference, table cells seem to be some kind of individual text frames within FM, at least as far as internal processing. They behave like text frames, in that movement between them is clunky, they cannot break across pages, etc. So, from a scripting perspective, I think it's common for a property to return a cell object even when you are expecting a text frame, because that's apparently how the table model behaves. Note that much of this is speculation... I didn't write the FM code

     

    Russ

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2012 5:59 AM   in reply to hetshjd

    The documentation is clearly wrong on this: InTextObj does not return a TextFrame object; that is the purpose if the InTextFrame property. It is wrong in the FDK Programmer's Reference, which is probably where the ExtendScript docunentation is derived from. The description for InTextObj is correct under the Pgf object in both ExtendScript and FDK docs:

     

    Subcolumn, footnote, or table cell the paragraph begins in (SubCol, Fn, or Cell).

     

    Rick

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points