shokoufeh Posted yesterday at 07:36 AM Posted yesterday at 07:36 AM Hi every one I need a lisp that adds the texts I select, to a pre defined table in Autocad. In the attached file, I need to select texts in the "DRAWING TITLE" part, and add them to the first column of the table. It would be great if the lisp, itself, can automatically select all of the mentioned texts and add them to the table. But if not, I can manually select the texts, and the lisp adds them to the table. Add Text to Table.dwg Quote
Emmanuel Delay Posted 3 hours ago Posted 3 hours ago (edited) I think based on something Bigal wrote, link in the code. Command TEST (feel free to rename) - User selects the table - User picks the start row. Fill in 1 for the row of 000, Fill in 2 for the row of 001, ... (you can hardcode this (setq row 1) if you will always start with 1 - User selects the title objects, the green text objects "GENERAL NOTES 0" ... one by one ;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/user-text-to-existing-table-cells/td-p/12238012 ;;You can get tables using ssget. ;; ;;I just posted this, the 0 0 is the title, 1 1 is 1st cell in header (vl-load-com) (defun c:test ( / obj rows cols row col value_ cellvalue) (setq obj (vlax-ename->vla-object (car (entsel "\nPick table: ")))) (setq rows (vlax-get-property obj 'rows)) (setq cols (vlax-get-property obj 'columns)) ;; get value of a cell ;;(setq col (getint "\nColumn: ")) ;;(setq row (getint "\nRow: ")) ;;(setq cellvalue (vlax-variant-value (vla-GETCELLVALUE OBJ row col))) ;;(princ "\n") ;;(princ cellvalue) ;;;;;;;;;;;; (setq col 0) (setq row (getint "\nStart Row (row 1 = the row of 000): ")) (princ "\nNow select texts: ") (while (setq title_obj (entsel "\ntitle object: ")) (setq title (cdr (assoc 1 (entget (car title_obj))))) ;;So if you know where "REVISION" is row & column can check easy then use next to put values. (vla-settext obj row col title) (setq row (+ row 1)) ) ) Happy with this? We can quite easily let you select all the all the frames, and read all the Text objects on layer "TEXT-0.3", sort from left to right, ... then auto fill in the table If you want Edited 3 hours ago by Emmanuel Delay Quote
BIGAL Posted 1 hour ago Posted 1 hour ago If you just want to add to end of a table it is easy as there is a function of Vla-insertrow so just do that for the extra text you want I would look at a selection set. So can do in random order or some sorted list of the selection set. Could then read the entire table and resort it if required. Quote
Emmanuel Delay Posted 1 hour ago Posted 1 hour ago I think this is what you want. Command ATTT (vl-load-com) ;; ATTT for Add Text To Table (defun c:ATTT ( / rowstart obj texts i x x_vals x_vals_sorted) (setq rowstart (getint "\nStart Row (row 1 = the row of 000): ")) (setq obj (vlax-ename->vla-object (car (entsel "\nPick table: ")))) (princ "\nSelects the green title objects: ") (setq texts (ssget (list (cons 0 "TEXT") (cons 8 "TEXT-0.3")))) (setq x_vals (list)) (setq i 0) (repeat (sslength texts) (setq x (nth 0 (cdr (assoc 10 (entget (ssname texts i)))))) (setq x_vals (append x_vals (list x))) (setq i (+ i 1)) ) ;; sort the x-values (setq x_vals_sorted (vl-sort-i x_vals '<)) (setq i 0) (setq col 0) (repeat (sslength texts) (setq text (ssname texts (nth i x_vals_sorted))) (setq title (cdr (assoc 1 (entget text)))) (setq row (+ i rowstart)) (vla-settext obj row col title) (setq i (+ i 1)) ) (princ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.