User Text to Existing Table Cells

User Text to Existing Table Cells

DGCSCAD
Collaborator Collaborator
523 Views
7 Replies
Message 1 of 8

User Text to Existing Table Cells

DGCSCAD
Collaborator
Collaborator

Hello all!

 

I'm searching for a way to insert text from user input from a dialog box into existing table cells in a drawing.  The tables are all in model space and there are multiple copies of the same tables in each drawing, all containing the same information. I'm dealing with legacy data and old processes, so I'm trying to find a way to automate the process of having to enter the same information multiple times.


What I'm looking to accomplish:

  • Open Dialog Box for user input of: REV | Date | Description | User
  • Find all tables with REVISION in the Header
  • Populate user input text into cells in each table instance, first available cell in each column, respectively


It's been quite some time since I've done anything LISP related, but I'm familiar with it as well as DCL. I would be eternally grateful if someone could point me the right direction to get this started.

AutoCad 2018 (full)
Win 11 Pro
0 Likes
524 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

Any reason for not deleting the old table in each dwg and just doing it once and xref the new table in?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

DGCSCAD
Collaborator
Collaborator

I know, right? Unfortunately, that's the process at the moment so I'm trying to eliminate some of the repetitiveness of manually changing each revision table (these should all be blocks, oy vey). LISP to the rescue.

 

I have made a bit of progress, but it's been too long since I've done any coding so I'm real rusty. I'll keep poking at it until I get something working well enough to post up here.

 

I appreciate the reply. 🙂

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 4 of 8

Sea-Haven
Mentor
Mentor

Use this for your dcl. Examples in code.

 

You can get tables using ssget.

I just posted this, the 0 0 is the title, 1 1 is 1st cell in header

(setq obj (vlax-ename->vla-object (car  (entsel "Pick table"))))

(setq rows (vlax-get-property obj 'rows))
(setq cols (vlax-get-property obj 'columns))

(setq cellvalue (vlax-variant-value (vla-GETCELLVALUE OBJ row col)))


So if you know where "REVISION" is row & column can check easy then use next to put values.

(vla-settext obj row col value)

 

Message 5 of 8

komondormrex
Mentor
Mentor

hey,

post some example of table before/after.

0 Likes
Message 6 of 8

DGCSCAD
Collaborator
Collaborator

I managed to put this together but it loops continually if there's no "-" in the table. Not sure why.

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;T-REV

(defun c:t-rev () ;(/ tblss row rows vals txtval e i n s x ans rev1 descr1 column)
(tr3-5)
(up-dater)
(tr3-1)
(tr3-2)
)

(defun tr3-1 ()
(setq tblss (ssget  "x" (list(cons -4 "<AND")
			  (cons 0 "ACAD_TABLE")			  
			  (cons -4 "<AND")
			  (cons 1  "REVISION"); <-- case sensitive column header
			  (cons -4 "AND>")
			  (cons 410  (getvar "CTAB")); <-- current layout name
			  (cons -4 "AND>")
			  )))
)

(defun tr3-2 ()
    (if (/= tblss nil)
        (progn
            (setq i 0
                  n (sslength tblss)
            )
            (while (< i n)
                (setq e (ssname tblss i)
                      x (cdr (assoc 0 (entget e)))
                      i (1+ i)
                )
                (tr3-3)
                (tr3-4)
            )
        )
    )
    (princ)
)

(defun tr3-3 ()
(setq table (vlax-ename->vla-object e))
(setq columns (vlax-get-property table 'Columns))
(setq rows (vlax-get-property table 'rows))
)


(defun tr3-4 ()
(setq row 1)   ; 0 is header
(while (/= rows nil)
    (setq column 0)
    (setq txtval (vlax-invoke-method table 'GetText row column )); now we have value from first cell in row.
    (if (= txtval "-")
	(progn          
	    (vla-settext table row column rev1)
            (setq column (1+ column))
            (vla-settext table row column datetext)
            (setq column (1+ column))
            (vla-settext table row column descr1)
            (setq column (1+ column))
            (vla-settext table row column "PD")
            (setq column (1+ column))
            (vla-settext table row column "-")
	    (setq txtval nil)
	    (setq rows nil)
    	)
	(setq row (1+ row ))
    )
)
)


(defun tr3-5 ()
(setq ans (AH:getvalsm (list "Add Revision " "REV " 6 5 "" "DESCRIPTION " 40 40 "")))
(setq rev1 (car ans))
(setq descr1 (cadr ans))
)

(defun UP-DATER ()
(setq d (rtos (getvar "CDATE") 2 6)
     ;get the date and time and convert to text
          yr (substr d 3 2)
	  ;extract the year
          mo (substr d 5 2)
	  ;extract the month
         day (substr d 7 2)
	 ;extract the day
     );setq
(setq datetext (strcat mo "/" day "/" yr))
)


(defun AH:getvalsm (dcllst / x y num fo fname keynum key_lst v_lst)
  (setq num (/ (- (length dcllst) 1) 4))
  (setq x 0)
  (setq y 0)
  (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
  (write-line "ddgetvalAH : dialog {" fo)
  (write-line (strcat "	label =" (chr 34) (nth 0 dcllst) (chr 34) " ;") fo)
  (write-line " : column {" fo)
  (write-line " width =25;" fo)
  (repeat num
    (write-line "spacer_1 ;" fo)
    (write-line ": edit_box {" fo)
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (write-line (strcat "    key = " (chr 34) keynum (chr 34) ";") fo)
    (write-line (strcat " label = " (chr 34) (nth (+ x 1) dcllst) (chr 34) ";") fo)
    (write-line (strcat "     edit_width = " (rtos (nth (+ x 2) dcllst) 2 0) ";") fo)
    (write-line (strcat "     edit_limit = " (rtos (nth (+ x 3) dcllst) 2 0) ";") fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "   allow_accept=true ;" fo)
    (write-line "    }" fo)
    (setq x (+ x 4))
  )
  (write-line "    }" fo)
  (write-line "spacer_1 ;" fo)
  (write-line "ok_cancel;}" fo)
  (close fo)

  (setq dcl_id (load_dialog fname))
  (if (not (new_dialog "ddgetvalAH" dcl_id))
    (exit)
  )
  (setq x 0)
  (setq y 0)
  (setq v_lst '())
  (repeat num
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (setq key_lst (cons keynum key_lst))
    (set_tile keynum (nth (setq x (+ x 4)) dcllst))
   ; (mode_tile keynum 3)
  )
    (mode_tile "key1" 2)
  (action_tile "accept" "(mapcar '(lambda (x) (setq v_lst (cons (get_tile x) v_lst))) key_lst)(done_dialog)")
  (action_tile "cancel" "(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete fname)

  (princ v_lst)
)
AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 7 of 8

hosneyalaa
Advisor
Advisor

Can y 

Attached example drawing 

 

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

You dont need the multi getvals code in your code, just use 

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

or like this with correct path to file, easier is save multi getvals.lsp in a support path then line above will work.

(if (not AH:getvalsm)(load "C:\\mydirectory1\\yourlisps\\Multi Getvals.lsp"))