Table editing

Automohan
Advocate
Advocate

Table editing

Automohan
Advocate
Advocate

Need a solution for this!

AutoCAD Table.png

"Save Energy"
Did you find this reply helpful? If so please use the Accept as Solution
0 Likes
Reply
2,469 Views
6 Replies
Replies (6)

pbejse
Mentor
Mentor

@Automohan wrote:

Need a solution for this!


 

And I need funds for Murciélago 🙂

 

Murciélago.jpeg

 

How were you able to create the table?  Better to build a list before inserting the table.

You can inset an excel sheet [OLE], Sheet set perhaps.

 

Begin with the end in mind. What do you have so far?

 

0 Likes

marko_ribar
Advisor
Advisor

What I see : you duplicated all rows... And you marked some from all rows in 2 different columns...

To get forward to what @pbejse stated, here is one from my library that creates table based on input list - at the end is example how is to be used - firstly its header then its columns titles and then are data - each sublist is row of table...

HTH., M.R.

 

(defun lst2table ( lst / pt as cols rh cw ttl data rows tbl r k )
  (vl-load-com)
  (setq rh
    (vla-gettextheight
      (vla-item
        (vla-item (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))) "acad_tablestyle")
        (getvar 'ctablestyle)
      )
      acdatarow
    )
  )
  (setq pt (vlax-3d-point '(0.0 0.0 0.0))
        as (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
        cols (length (caadr lst))
        ttl (car lst)
        data (cadr lst)
        rows (1+ (length data))
  );setq
  (setq cw (apply 'max (mapcar '(lambda ( x ) (apply 'max (mapcar 'strlen x))) (apply 'mapcar (cons 'list data)))));setq
  (setq tbl (vla-addtable as pt rows cols (* 2.5 rh) (* 0.8 cw)));active space/ins point/# rows/# cols/row ht/col wid
  (if (vlax-property-available-p tbl 'regeneratetablesuppressed t)
    (vla-put-regeneratetablesuppressed tbl :vlax-true)
  )
  (vla-put-stylename tbl (getvar 'ctablestyle))
  (vla-settext tbl 0 0 ttl)
  (setq r 1)
  (foreach i data
    (setq k -1)
    (foreach ii i
      (vla-settext tbl r (setq k (1+ k)) ii);table/row/col/text
      (if (> r 1)
        (vla-setcellalignment tbl r k acmiddleleft)
      )
    );foreach
    (setq r (1+ r))
  );foreach
  (setq cw (mapcar '(lambda ( x ) (apply 'max (mapcar 'strlen x))) (apply 'mapcar (cons 'list data))))
  (setq k -1)
  (foreach c cw
    (vla-setcolumnwidth tbl (setq k (1+ k)) (* c rh 1.25))
  );foreach
  (if (vlax-property-available-p tbl 'regeneratetablesuppressed t)
    (vla-put-regeneratetablesuppressed tbl :vlax-false)
  )
  (vla-update tbl)
  (princ)
);defun
;|
(lst2table '("LEGEND OF SYMBOLS" (("Symbol" "Description") ("DD-SYM" "Full full-wood or gypsum-filled doors or non-transparent material without metal elements without taking into account the locksmith") ("WW-SYM" "Window with glass - fully transparent solid wood hatch - PVC material or frames made of non-transparent material without metal elements without taking into account locksmith") ("DW-SYM" "Balcony doors or glass doors - fully transparent hollow solid wood hatch - PVC material or frames made of non-transparent material without metal elements without taking into account the locksmith") ("DM-SYM" "Balcony doors or glass doors - a fully transparent hole or hole filled with semi-transparent material (laminated glass or lexan) of solid wood - PVC material or frames made of non-transparent material with metallic elements of the enclosure at the height of the parapet or along the entire height of the door with a clearly defined split subconstruction") ("WM-SYM" "Glass window - fully transparent hole or hole filled with semi-transparent material (glass-lined glass or lexan) made of solid wood - PVC material or frames made of non-transparent material with metal fencing elements along the entire height of the window with a clearly defined subdivision") ("OM-SYM" "Metal fence with free intermediate between metal parts or interstitials filled with semi-transparent material (screened-reinforced glass or lexan)") ("MM-SYM" "Full metal fence or door or window without free interstice between metal parts") ("OZ-SYM" "Perforated parapet wall or wall with elements of full material with free intermediate or interstitials filled with semi-transparent material (screened-reinforced glass or lexan) between full elements of a staircase or a full masonry frame") ("ZZ-SYM" "A full wall or a full parapet wall"))))
|;
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes

marko_ribar
Advisor
Advisor

Actually, I've retested my code and found lacks... This is now better - there are 2 types - one with Titles and other without - the other list is list of lists with strings - rows (first row is Header)... Here are 2 lisps for testing - if you already have TABLE, you can try something like (lst2table (table2lst (car (entsel "\nPick TABLE...")))) ... It should create almost identical table just without correct scale and in insertion point 0,0,0...

 

(defun lst2table ( lst / pt as cols rh cw ttl data rows sty tbl r k )
  (vl-load-com)
  (setq rh
    (vla-gettextheight
      (setq sty
        (vla-item
          (vla-item (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object))) "acad_tablestyle")
          (getvar 'ctablestyle)
        )
      )
      acdatarow
    )
  )
  (setq pt (vlax-3d-point '(0.0 0.0 0.0))
        as (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
        cols (if (listp (caadr lst)) (length (caadr lst)) (length (car lst)))
        ttl (if (not (listp (car lst))) (car lst))
        data (if (not (listp (car lst))) (cadr lst) lst)
        data (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (if (null y) "" y)) x)) data)
        rows (if (not (listp (car lst))) (1+ (length data)) (length data))
  );setq
  (if ttl
    (vla-enablemergeall sty "Title" :vlax-true)
    (vla-enablemergeall sty "Title" :vlax-false)
  )
  (setq cw (apply 'max (mapcar '(lambda ( x ) (apply 'max (mapcar 'strlen x))) (apply 'mapcar (cons 'list data)))));setq
  (setq tbl (vla-addtable as pt rows cols (* 2.5 rh) (* 0.8 cw)));active space/ins point/# rows/# cols/row ht/col wid
  (if (vlax-property-available-p tbl 'regeneratetablesuppressed t)
    (vla-put-regeneratetablesuppressed tbl :vlax-true)
  )
  (vla-put-stylename tbl (getvar 'ctablestyle))
  (if ttl
    (progn
      (vla-settext tbl 0 0 ttl)
      (setq r 1)
    )
    (setq r 0)
  )
  (foreach i data
    (setq k -1)
    (foreach ii i
      (vla-settext tbl r (setq k (1+ k)) ii);table/row/col/text
      (cond
        ( (and ttl (> r 1))
          (vla-setcellalignment tbl r k acmiddleleft)
        )
        ( (and (not ttl) (= r 0))
          nil
        )
        ( t
          (vla-setcellalignment tbl r k acmiddleleft)
        )
      )
    );foreach
    (setq r (1+ r))
  );foreach
  (setq cw (mapcar '(lambda ( x ) (apply 'max (mapcar 'strlen x))) (apply 'mapcar (cons 'list data))))
  (setq k -1)
  (foreach c cw
    (vla-setcolumnwidth tbl (setq k (1+ k)) (* c rh 1.25))
  );foreach
  (if (vlax-property-available-p tbl 'regeneratetablesuppressed t)
    (vla-put-regeneratetablesuppressed tbl :vlax-false)
  )
  (vla-update tbl)
  (princ)
);defun
;|
(lst2table '("LEGEND OF SYMBOLS" (("Symbol" "Description") ("DD-SYM" "Full full-wood or gypsum-filled doors or non-transparent material without metal elements without taking into account the locksmith") ("WW-SYM" "Window with glass - fully transparent solid wood hatch - PVC material or frames made of non-transparent material without metal elements without taking into account locksmith") ("DW-SYM" "Balcony doors or glass doors - fully transparent hollow solid wood hatch - PVC material or frames made of non-transparent material without metal elements without taking into account the locksmith") ("DM-SYM" "Balcony doors or glass doors - a fully transparent hole or hole filled with semi-transparent material (laminated glass or lexan) of solid wood - PVC material or frames made of non-transparent material with metallic elements of the enclosure at the height of the parapet or along the entire height of the door with a clearly defined split subconstruction") ("WM-SYM" "Glass window - fully transparent hole or hole filled with semi-transparent material (glass-lined glass or lexan) made of solid wood - PVC material or frames made of non-transparent material with metal fencing elements along the entire height of the window with a clearly defined subdivision") ("OM-SYM" "Metal fence with free intermediate between metal parts or interstitials filled with semi-transparent material (screened-reinforced glass or lexan)") ("MM-SYM" "Full metal fence or door or window without free interstice between metal parts") ("OZ-SYM" "Perforated parapet wall or wall with elements of full material with free intermediate or interstitials filled with semi-transparent material (screened-reinforced glass or lexan) between full elements of a staircase or a full masonry frame") ("ZZ-SYM" "A full wall or a full parapet wall"))))
|;
(defun table2lst ( tab / rr cc row lst ) ; tab - ACAD TABLE ( ename or vla-object )
  (vl-load-com)
  (if (= (type tab) 'ename)
    (setq tab (vlax-ename->vla-object tab))
  )
  (if (= (cdr (assoc 0 (entget (vlax-vla-object->ename tab)))) "ACAD_TABLE")
    (progn
      (setq rr -1)
      (repeat (vla-get-rows tab)
        (setq rr (1+ rr) cc -1)
        (repeat (vla-get-columns tab)
          (setq cc (1+ cc))
          (setq row (append row (list (vlax-variant-value (vla-getcellvalue tab rr cc)))))
        )
        (setq lst (cons row lst) row nil)
      )
      (setq lst (reverse lst))
      (if (vl-every 'null (cdr (car lst)))
        (setq lst (append (vl-remove nil (car lst)) (list (cdr lst))))
        lst
      )
    )
  )
)

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes

Sea-Haven
Mentor
Mentor

Sorry Marco for Automohan, forums all work different when posting keep forgetting here, pick poster and add.

 

My $0.05 this is dwg index table, note it is hard coded for a particular title block and attributes so will need a couple of changes.

; dwg index to a table
; by Alan H NOV 2013
(defun AH:dwgindex (/ doc objtable ss1 lay ans ans2 plotabs ss1 tag2 tag3 list1 list2 curlayout colwidth numcolumns numrows INC rowheight )

(vl-load-com)
(setq curlayout (getvar "ctab"))
(if (= curlayout "Model")
(progn
(Alert "You need to be in a layout for this option")
(exit)
) ; end progn
) ; end if model
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq curspace (vla-get-paperspace doc))
(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table:  "))) 

; read values from title blocks

(setq bname "DA1DRTXT") ; title block name

(setq tag2 "DRG_NO") ;attribute tag name
(setq tag3 "WORKS_DESCRIPTION") ;attribute tag name

(setq ss1 (ssget "x"  (list (cons 0 "INSERT") (cons 2 bname))))

(setq INC (sslength ss1))  
(repeat INC
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (SETQ INC (- INC 1)) )) 'getattributes) 
        (if (= tag2 (strcase (vla-get-tagstring att)))
            (progn
            (setq ans (vla-get-textstring att))
            (if (/= ans NIL)
            (setq list1 (cons ans list1))
            ) ; if 
            ); end progn
          ) ; end if
        (if (= tag3 (strcase (vla-get-tagstring att)))
          (progn
          (setq ans2 (vla-get-textstring att))
          (if (/= ans2 NIL)
              (setq list2 (cons ans2 list2)) 
           ) ; end if
           ) ; end progn
	 ) ; end if tag3 
    
) ; end foreach

) ; end repeat
(setvar 'ctab curlayout)
(command "Zoom" "E")
(command "regen")


(reverse list1)
;(reverse list2)

; now do table 
(setq numrows (+ 2 (sslength ss1)))
(setq numcolumns 2)
(setq rowheight 0.2)
(setq colwidth 150)
(setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "DRAWING REGISTER")
(vla-settext objtable 1 0 "DRAWING NUMBER") 
(vla-settext objtable 1 1 "DRAWING TITLE") 

(SETQ X 0)
(SETQ Y 2)

(REPEAT (sslength ss1)
  (vla-settext objtable Y 0 (NTH X LIST1))
  (vla-settext objtable Y 1 (NTH X LIST2))
  (vla-setrowheight objtable y 7)

  (SETQ X (+ X 1))
  (SETQ Y (+ Y 1))
)

(vla-setcolumnwidth objtable 0 55)
(vla-setcolumnwidth objtable 1 170)

(command "_zoom" "e")
(princ)
); end AH defun

(AH:dwgindex)


 

 

0 Likes

pbejse
Mentor
Mentor

We now have a couple of constributions here, too bad we have not heard anything for Automohan.

 

What is the source of the drawing title(s) anyway? Multple titleblock on a single drawing? Multiple sheets on separate folders? give us something to work on Automohan.

 

BTW: This is too easy to accomplish with Sheet Set Manager.

 

 

0 Likes

marko_ribar
Advisor
Advisor

I am still under impression that @Automohan wants to alter content of his ACAD TABLE object... Not sure, but if that's his intent, I've coded for this case another sub function... I know that there is a way to save variables and their values into *.txt, so if TABLE is enormous big, he may look into solution from here :

http://www.theswamp.org/index.php?topic=50628.msg557923#msg557923

Otherwise he may copy+paste to notepad++ explained at the end of the code...

 

(defun table2lst ( tab / rr cc row lst ) ; tab - ACAD TABLE ( ename or vla-object )
  (vl-load-com)
  (if (= (type tab) 'ename)
    (setq tab (vlax-ename->vla-object tab))
  )
  (if (= (cdr (assoc 0 (entget (vlax-vla-object->ename tab)))) "ACAD_TABLE")
    (progn
      (setq rr -1)
      (repeat (vla-get-rows tab)
        (setq rr (1+ rr) cc -1)
        (repeat (vla-get-columns tab)
          (setq cc (1+ cc))
          (setq row (append row (list (vlax-variant-value (vla-getcellvalue tab rr cc)))))
        )
        (setq lst (cons row lst) row nil)
      )
      (setq lst (reverse lst))
      (if (vl-every 'null (cdr (car lst)))
        (setq lst (append (vl-remove nil (car lst)) (list (cdr lst))))
        lst
      )
    )
  )
)

(defun lst2table-update ( lst tab / ttl data rr cc s ) ; lst - changed text of table ; tab - ACAD TABLE ( ename or vla-object )
  (vl-load-com)
  (if (= (type tab) 'ename)
    (setq tab (vlax-ename->vla-object tab))
  )
  (setq ttl (if (not (listp (car lst))) (car lst))
        data (if (not (listp (car lst))) (cadr lst) lst)
        data (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) (if (null y) "" y)) x)) data)
  )
  (setq rr -1)
  (repeat (vla-get-rows tab)
    (setq rr (1+ rr) cc -1)
    (repeat (vla-get-columns tab)
      (setq cc (1+ cc))
      (cond
        ( (and ttl (= rr 0))
          (vla-settext tab 0 0 ttl)
        )
        ( ttl
          (if (and (= (type (setq s (nth cc (nth (1- rr) data)))) 'STR) (snvalid s))
            (vla-settext tab rr cc s)
          )
        )
        ( t
          (if (and (= (type (setq s (nth cc (nth rr data)))) 'STR) (snvalid s))
            (vla-settext tab rr cc s)
          )
        )
      )
    )
  )
  (princ)
)
;|
(table2lst (car (entsel "\nPick TABLE..."))) ;;; remember what TABLE you picked
;;; copy+paste ACAD textscreen output to notepad... change list in notepad++ using ctrl+H (find&replace) and after change add "(setq lst (quote " before and "))" after change... copy+paste from notepad to ACAD textscreen 
(lst2table-update lst (car (entsel "\nPick TABLE..."))) ;;; pick the same TABLE
|;

Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes