TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mystogan on October 08, 2021, 03:57:18 AM
-
Hi sir/mam
Hoping you could help me out, does any here have a copy of LSP.
That will routinely write all the details(in each cell, only the written) in the excel in AutoCad that will create a table.
Im using copy paste from excel then into cad, but this method will requires me to add it my .xlsx in the process
of submission. I prefer not to include it.
Thank you in advance
-
I typically create a datalink to an Excel file and then insert a table created from the datalink.
-
Here is an example of read csv to a table. You will have to edit to suit number of columns.
; Read a csv and make a table
; BY Alanh info@alanh.com.au
; defun by Lee-mac
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
(list str)
)
)
(defun AH:addlinet ( / rowcnt rowhgt)
(setq rowcnt (vla-get-rows objtable))
(setq rowhgt (vla-getRowHeight objtable 2))
(vla-InsertRows objTable rowcnt rowhgt 1)
(vla-settext objtable (- rowcnt 1) 0 (nth 0 lst))
(vla-settext objtable (- rowcnt 1) 1 (nth 1 lst))
(vla-settext objtable (- rowcnt 1) 2 (nth 2 lst))
(vla-settext objtable (- rowcnt 1) 3 (nth 3 lst))
(vla-settext objtable (- rowcnt 1) 4 (nth 4 lst))
(princ)
)
(setq sp (vlax-3d-point (getpoint "pick a point for table")))
(Setq vgms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq numrows 3)
(setq numcolumns 5)
(setq rowheight 3.04)
(setq colwidth 60)
(setq objtable (vla-addtable vgms sp numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "SETOUT")
(vla-settext objtable 1 0 "NUMBER")
(vla-settext objtable 1 1 "EASTING")
(vla-settext objtable 1 2 "NORTHING")
(vla-settext objtable 1 3 "RL")
(vla-settext objtable 1 4 "DESCRIPTION")
(command "_zoom" "e")
(princ)
(setq objtable (vlax-ename->vla-object (entlast)))
(setq fo (open "d:\\Acadtemp\\setout.csv" "R"))
(while (setq nline (read-line fo))
(setq lst (_csv->lst nline))
(AH:addlinet)
)
(close fo)
; (setq objtable (vlax-ename->vla-object (entlast)))
(SETQ Y 0 )
(repeat 5
(setq x 0)
(repeat (- (vla-get-rows objtable) 2)
(vla-setcelltextheight objtable (setq x (+ x 1)) y 1.25)
)
(setq y (+ y 1))
)
(SETQ X 0)
(repeat (- (vla-get-rows objtable) 2)
(VLA-SETROWHEIGHT OBJTABLE (setq x (+ x 1)) 3.04)
)
(setq x 0)
(repeat 5
(VLA-SetColumnWidth OBJTABLE x 25)
(setq x (+ x 1))
)