LM:ADDTABLE help

LM:ADDTABLE help

Village_Idiot
Contributor Contributor
4,132 Views
7 Replies
Message 1 of 8

LM:ADDTABLE help

Village_Idiot
Contributor
Contributor

Not sure where I originally found it.  Its Lee Mac's obviously.  I've been using it in a pgms and its been fine but now we want need to make much larger tables and my pgm is running slow.  If I comment out this function it runs very fast.  I came across some comments (one from LEE) about using (vla-put-regeneratetablesuppressed MyTable :vlax-true).  Trouble is the table is never set to a variable and with his swell use of anonymous functions I can't figure out how/where to do it.  Can anyone help or should I punt and struggle through trying to figure out how to build a table myself??

 

;;---------------------=={ Add Table }==----------------------;;
  ;;                                                            ;;
  ;;  Creates a VLA Table Object at the specified point,        ;;
  ;;  populated with title and data                             ;;
  ;;------------------------------------------------------------;;
  ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  ;;------------------------------------------------------------;;
  ;;  Arguments:                                                ;;
  ;;  space - VLA Block Object                                  ;;
  ;;  pt    - Insertion Point for Table                         ;;
  ;;  title - Table title                                       ;;
  ;;  data  - List of data to populate the table                ;;
  ;;------------------------------------------------------------;;
  ;;  Returns:  VLA Table Object                                ;;
  ;;------------------------------------------------------------;;

  (defun LM:AddTable ( space pt title data / _itemp ) (vl-load-com)
   
    (defun _itemp ( collection item )
      (if
        (not
          (vl-catch-all-error-p
            (setq item
              (vl-catch-all-apply 'vla-item (list collection item))
            )
          )
        )
        item
      )
    )

    (
     
      (lambda ( table ) (vla-put-StyleName table (getvar 'CTABLESTYLE)) (vla-SetText table 0 0 title)
        (
          (lambda ( row )
            (mapcar
              (function
                (lambda ( rowitem ) (setq row (1+ row))
                  (
                    (lambda ( column )
                      (mapcar
                        (function
                          (lambda ( item )
                            (vla-SetText table row
                              (setq column (1+ column)) item
                            )
                          )
                        )
                        rowitem
                      )
                    )
                    -1
                  )
                )
              )
              data
            )
          )
          0
        )
        table
        
      )
       
      (
        (lambda ( textheight )
          (vla-AddTable space (vlax-3D-point pt) (1+ (length data)) (length (car data)) (* 1.8 textheight)
            (* textheight
              (apply 'max
                (cons (/ (strlen title) (length (car data)))
                  (mapcar 'strlen (apply 'append data))
                )
              )
            )
          )
        )
        (vla-getTextHeight
          (_itemp
            (_itemp
              (vla-get-Dictionaries
                (vla-get-ActiveDocument (vlax-get-acad-object))
              )
              "ACAD_TABLESTYLE"
            )
            (getvar 'CTABLESTYLE)
          )
          acDataRow
        )
      )
      
    )
    
  )

  (princ)

;<-----------------------------------
0 Likes
Accepted solutions (1)
4,133 Views
7 Replies
Replies (7)
Message 2 of 8

Sea-Haven
Mentor
Mentor

Yes I have made a  table with hundreds of rows. For me I make a table of Title, header and one data row. Then set the suppress, I use vla-insertrow method reading a list and make new rows, filling in cells, then set suppress to False, it is very fast, like one second or two.

 

So I make a table but with no data, then add data, which is slightly different to Lee's method.

0 Likes
Message 3 of 8

Village_Idiot
Contributor
Contributor

In looking further I have found other methods  (poor word choice)ways of doing it.  Including in Lee's pgms.  Many of them set the suppress.  I was just hoping since I already have everything formatted to be run through this function I could somehow add the suppress here.  I'll have to look into your suggestion about initializing a blank table, suppress, then vla-insertrow.  Guessing that could come in handy if I ever need to add a line to an existing table.  I'm using it to create schedules from attributed blocks and as visual aids for drafts people before final export of .csv's to excel, ect.

0 Likes
Message 4 of 8

pbejse
Mentor
Mentor

You are on the right track,  vla-put-regeneratetablesuppressed is the key. In this case  table is the variable name

(lambda ( table ) (vla-put-StyleName table (getvar 'CTABLESTYLE)) (vla-SetText table 0 0 title)
	(vla-put-regeneratetablesuppressed table :vlax-true)
        (
          (lambda ( row )
            (mapcar
              (function
                (lambda ( rowitem ) (setq row (1+ row))
                  (
                    (lambda ( column )
                      (mapcar
                        (function
                          (lambda ( item )
                            (vla-SetText table row
                              (setq column (1+ column)) item
                            )
                          )
                        )
                        rowitem
                      )
                    )
                    -1
                  )
                )
              )
              data
            )
          )
          0
        )
	(vla-put-regeneratetablesuppressed table :vlax-false)
        table
        
      )

Holler if you need help putting it together

 

HTH

 

0 Likes
Message 5 of 8

komondormrex
Mentor
Mentor
Accepted solution

try using extra variable

;;---------------------=={ Add Table }==----------------------;;
  ;;                                                            ;;
  ;;  Creates a VLA Table Object at the specified point,        ;;
  ;;  populated with title and data                             ;;
  ;;------------------------------------------------------------;;
  ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  ;;------------------------------------------------------------;;
  ;;  Arguments:                                                ;;
  ;;  space - VLA Block Object                                  ;;
  ;;  pt    - Insertion Point for Table                         ;;
  ;;  title - Table title                                       ;;
  ;;  data  - List of data to populate the table                ;;
  ;;------------------------------------------------------------;;
  ;;  Returns:  VLA Table Object                                ;;
  ;;------------------------------------------------------------;;

  (defun LM:AddTable ( space pt title data / _itemp tbl) (vl-load-com) ; komondormrex
   
    (defun _itemp ( collection item )
      (if
        (not
          (vl-catch-all-error-p
            (setq item
              (vl-catch-all-apply 'vla-item (list collection item))
            )
          )
        )
        item
      )
    )

    (
     
      (lambda ( table ) (vla-put-StyleName table (getvar 'CTABLESTYLE)) (vla-SetText table 0 0 title)
        (
          (lambda ( row )
            (mapcar
              (function
                (lambda ( rowitem ) (setq row (1+ row))
                  (
                    (lambda ( column )
                      (mapcar
                        (function
                          (lambda ( item )
                            (vla-SetText table row
                              (setq column (1+ column)) item
                            )
                          )
                        )
                        rowitem
                      )
                    )
                    -1
                  )
                )
              )
              data
            )
          )
          0
        )
        table
        
      )
       
      (
        (lambda ( textheight )
      (setq tbl (vla-AddTable space (vlax-3D-point pt) (1+ (length data)) (length (car data)) (* 1.8 textheight) ; komondormrex
            (* textheight
               (apply 'max
                (cons (/ (strlen title) (length (car data)))
                  (mapcar 'strlen (apply 'append data))
                )
             )
            )
          )
        )
      (vla-put-regeneratetablesuppressed tbl :vlax-true) ; komondormrex
      tbl                                                ; komondormrex
        )
        (vla-getTextHeight
          (_itemp
            (_itemp
              (vla-get-Dictionaries
                (vla-get-ActiveDocument (vlax-get-acad-object))
              )
              "ACAD_TABLESTYLE"
            )
            (getvar 'CTABLESTYLE)
          )
          acDataRow
        )
      )
    )
  (vla-put-regeneratetablesuppressed tbl :vlax-false)  ; komondormrex
)
0 Likes
Message 6 of 8

Village_Idiot
Contributor
Contributor

You guys are the best!  I just replaced it with the solution form komondormrex.  Works sooooooo much faster.  Thank you so much.  Now to dig through it and try to  understand what you did. I will certainly look in to pbejse's option as well.  I need to take the time to get better at understanding the whole lambda thing anyway.  lol

0 Likes
Message 7 of 8

pbejse
Mentor
Mentor

@Village_Idiot wrote:

....Trouble is the table is never set to a variable and with his swell use of anonymous functions I can't figure out how/where to do it.  Can anyone help or should I punt and struggle through trying to figure out how to build a table myself?? 


 

The snippet i posted is basically the same thing with very limited changes to the original code and also does not require introducing a new variable. And I'm thinking that would help you figure out by yourself as a learning curve. Anyhoo, glad you found a solution.

 

Message 8 of 8

Sea-Haven
Mentor
Mentor

Here is a snippet of code inserting rows based on a block list of attributes, as mentioned may be hundreds.

 

(setq row 1 rowht  (vla-GetRowHeight objtable 1))

(foreach room lst1
  (vla-InsertRows objtable row rowht 1)
  (vla-settext objtable row 0 (car room))
  (vla-settext objtable row 1 (nth 2 room))
  (vla-settext objtable row 2(nth 3 room))
  (setq row (1+ row))
)

 

Just a comment one of my make tables you can select as many blocks of various names and a table is made with the blocks sorted and counted with up to 5 levels deep based on attribute values.

 

eg 5 attributes

Door Silver 2000 1000 24

Door Silver 2040 1000 15

Sink Ceramic 900x450 12

Sink Stainless 900x450 10

and so on

0 Likes