Author Topic: Tables; Column width and Row heights  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Tables; Column width and Row heights
« on: January 18, 2008, 06:00:04 PM »
I'm trying to add the functionality to choose if you want to insert the text in this routine in a table or as plain text, with grid lines drawn around them.

I have been able to insert a table, and fill in the information, but I can change the width of the columns within the code.  I can run the same piece of code after the routine has run, and it will change the width, but I can't do it from within.  I have tried a couple of way, and can't seem to get any to work, so now I have to ask for help.   :-)  I'm having the same problem with the height of each row, but the columns is the main issue I can't solve by myself, and I hope when I do it will lead me to a way to fix the height issue.

Here is the portion of code that inserts the table, fills in the cells, and is supposed to change the width of the columns (highlighted in red).
Code: [Select]
(progn
    (setq MaxCol
        (car
            (vl-sort
                (mapcar 'length StrList)
                '>
            )
        )
    )
    (setq Tbl (vlax-invoke CurSpace 'AddTable StPt (length StrList) MaxCol TxtHt 1.0))
    (vla-SetAlignment Tbl acDataRow acMiddleCenter)
    (vla-put-RegenerateTableSuppressed Tbl :vlax-true)
    (setq RowCnt 0)
    (foreach lst (reverse StrList)
        (setq ColCnt 0)
        (vla-SetRowHeight Tbl RowCnt (* TxtHt 1.25))
        (foreach str lst
            (vla-SetText Tbl RowCnt ColCnt str)
            (if (setq tempList (assoc ColCnt ColStrList))
                (if (> (strlen str) (strlen (cdr tempList)))
                    (setq ColStrList (subst (cons ColCnt str) tempList ColStrList))
                )
                (setq ColStrList (cons (cons ColCnt str) ColStrList))
            )
            (setq ColCnt (1+ ColCnt))
        )
        (setq RowCnt (1+ RowCnt))
    )
[color=red]    (foreach lst (mapcar
                    '(lambda (x / ll ur tempObj)
                        (setq tempObj (vlax-invoke CurSpace 'AddText (cdr x) '(0. 0. 0.) TxtHt))
                        (vla-GetBoundingBox tempObj 'll 'ur)
                        (vla-Delete tempObj)
                        (cons
                            (car x)
                            (*
                                XOffset
                                (abs
                                    (-
                                        (car (safearray-value ll))
                                        (car (safearray-value ur))
                                    )
                                )
                            )
                        )
                    )
                    ColStrList
                )
        (vla-SetColumnWidth Tbl (car lst) (cdr lst))
    )[/color]
    (vla-put-RegenerateTableSuppressed Tbl :vlax-false)
)


Any help is appreciated.  Attached is the file I'm working with now.  Thanks in advance.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Tables; Column width and Row heights
« Reply #1 on: January 19, 2008, 01:09:14 AM »
Tim,
I haven't done anything with ACAD Tables but Peter has. http://forums.augi.com/showthread.php?t=61105&highlight=table&page=2
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4097
  • C3D user & customizer
Re: Tables; Column width and Row heights
« Reply #2 on: January 19, 2008, 07:19:05 PM »
Hi Tim,
Your code is changing the width & height of the cells, but I'm guessing it's not doing what you are expecting it to.

After some testing and adjusting of code, this is what I came up with.....

1. A Table style holds default values for the Text Style & Text Height. These values are used when you create the table.
2. In order to use the Text height you specify in the code, you must tell each cell what that value is to be.
3. The Standard table style uses the Standard Text Style. This may, or may not, be the current style in the drawing. Due to this, the AddText may be using a different Style than the Table's text. This will render your GetBoundingbox values meaningless. So, either change the style in the Cell, or set the Text created by addtext to match the Table's textstyle before you get the BB.
4. The value you use for the column width should be more like the sum of twice that value and the BB width. You currently are multiplying the BB width & the Xfactor.

After making those changes, the Table looks pretty good. If you'd like to see the code I changed I'll post it, but I know how you like to tackle things on your own so I'll wait until you say so. :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Tables; Column width and Row heights
« Reply #3 on: January 19, 2008, 08:15:57 PM »
Thanks guys!  I will look at these things on Monday, and see what I can come up with.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Tables; Column width and Row heights
« Reply #4 on: January 21, 2008, 01:35:25 PM »
So I added code to change the text style to that of the current text style.  I also changed the height to be the height selected, but I can't seem to get it to update the columns width.  Attached is a picture of what it should look like, and what it does.  The one on top is done by selecting to use text and draw the grid, and the bottom is a table.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Tables; Column width and Row heights
« Reply #5 on: January 21, 2008, 02:41:04 PM »
Never mind above.  I had (what we call, friends and I) a scientific moment.  I was multiplying the ratio and the string length, when I need to add them.  It is working better now.  Now with all these options, I might make it dialog based.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.