creating/modifying table

Discussion in 'AutoCAD' started by elise_moss, Mar 29, 2005.

  1. elise_moss

    elise_moss Guest

    I am trying to automate the process for entering data into an ACAD_TABLE. I read an excel spreadsheet and create a list in lisp then try to populate the table.

    Here are my code snippets:

    **************************
    ;;;placing a table from scratch
    (setq ins-point (getpoint "\nSelect point to place table: "))
    (setq rowno (getint "\nNumber of rows for table: "))
    (setq colno (getint "\nNumber of columns for table: "))
    (setq colno 4)
    (setq rowno (/ list-len 4))
    (entmake (list(cons 0 "ACAD_TABLE")))
    (entmake (list(cons 10 ins-point)))
    (entmake (list(cons 91 rowno)))
    (entmake (list(cons 92 colno)))
    (setq list-counter 0)
    (setq table-text (nth list-counter xcel-list))
    (while (< list-counter list-len)
    (entmake (list(cons 1 table-text)))
    (entmake (list(cons 7 table-text-style)))
    (setq list-counter (1+ list-counter))
    );end while
    (entmake (list(cons 0 "seqend")))
    (setq ent (entlast))
    (entupd ent)
    )
    *************************************************
    This one looks like like it would work and when I make the first couple of entmake calls, they look like they go thru OK. But it does not create the table.

    Next snippet, using an existing table:
    ************************************************
    (while (< itemno ent-count)
    ; get the first item in the list to put in the table
    (setq table-text (nth list-counter xcel-list))
    (setq ent-list-line (nth itemno ent-list))
    (setq ent-list (subst (cons 1 table-text)(cons 1 ent-list-line) ent-list))
    (setq itemno (1+ itemno))
    (setq ent-list-line (nth itemno ent-list))
    (setq ent-list (subst (cons 7 table-text-style)(cons 7 ent-list) ent-list))
    (setq itemno (+ itemno 9))
    (setq list-counter (1+ list-counter))
    (setq ent (entnext ent))

    ) ;end while
    *********************************************************

    This one will actually place the data into the first cell, but none of the other cells, it just keeps overwriting the data in the first cell. So, it obviously not advancing to the next cell. When I try using an entnext call, it looks like a table is not a nested entity, even though it looks like a polyline when you inspect the dxf data.

    Suggestions are most welcome...prefer not to do this in VBA.

    Thanks,

    Elise Moss
    www.mossdesigns.com
     
    elise_moss, Mar 29, 2005
    #1
  2. Elisa,

    Here is a little sample I have for this particular object, hope it helps.

    (vl-load-com)

    ;; headers list
    (setq table_headers (list "Header1" "Header2" "Header3" "Header4"))

    ;; rows list
    (setq table_rows
    (list
    (list "item1" "item2" "item3" "item4")
    (list "item1" "item2" "item3" "item4")
    (list "item1" "item2" "item3" "item4")
    (list "item1" "item2" "item3" "item4")))

    ;; object Table
    (setq vla_table (vla-addtable
    ;; for test place the object on model space
    (vla-get-modelspace
    (vla-get-activedocument (vlax-get-acad-object)))
    ;; base = 0,0,0
    (vlax-3d-point (list 0 0 0))
    ;; rows number - including title & headers
    (+ (length table_rows) 2)
    ;; columns number
    (length table_headers)
    ;; row height
    10.0
    ;; column width
    10.0))

    ;; set title name
    (vla-settext vla_table 0 0 "MY TITLE GOES HERE")
    ;; cell alignment
    (vla-setcellalignment vla_table 0 0 acmiddlecenter)
    ;; cell text height
    (vla-setcelltextheight vla_table 0 0 1.65)

    ;; first column
    (setq column 0)

    ;; generates all headers
    (foreach item table_headers
    ;; header
    (vla-settext vla_table 1 column item)
    ;; alignment
    (vla-setcellalignment vla_table 1 column acmiddlecenter)
    ;; text height
    (vla-setcelltextheight vla_table 1 column 1.65)
    ;; next column
    (setq column (1+ column)))

    ;; start with row 2
    (setq row 2)
    ;; first column
    (setq column 0)

    ;; generate all rows
    (foreach row table_rows
    ;; for each row fill all the data
    (foreach item row
    ;; cell text
    (vla-settext vla_table row column item)
    ;; alignment
    (vla-setcellalignment vla_table row column acmiddlecenter)
    ;; text height
    (vla-setcelltextheight vla_table row column 1.65)
    ;; next column
    (setq column (1+ column)))
    ;; next row
    (setq row (1+ row))
    ;; first column
    (setq column 0))

    (princ)
     
    Luis Esquivel, Mar 29, 2005
    #2
  3. elise_moss

    elise_moss Guest

    Luis-

    That is awesome code! Thank you so much. I haven't tried it yet, but it looks wonderful

    You rock!

    Elise
     
    elise_moss, Mar 29, 2005
    #3
  4. Thanks..


    There is a little mistake I just made when typing.... please use this part:

    ;; generate all rows
    (foreach rows table_rows
    ;; for each row fill all the data
    (foreach item rows
    ;; cell text
    (vla-settext vla_table row column item)
    ;; alignment
    (vla-setcellalignment vla_table row column acmiddlecenter)
    ;; text height
    (vla-setcelltextheight vla_table row column 1.65)
    ;; next column
    (setq column (1+ column)))
    ;; next row
    (setq row (1+ row))
    ;; first column
    (setq column 0))
     
    Luis Esquivel, Mar 29, 2005
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.