I know this post is years old, but that LISP routine was EXACTLY what I needed to complete a project I am working on. I have a bunch of drawings that have exploded tables (only single text entities and lines) representing a table, but I need to export them to a .csv file and manipulate there...this worked perfectly.
The error comes from the function populate-table.
Only if the 1st string content is "DESCRIPTION" can u have the definition of colleft.
so if the colleft is not defined, you will stop while running (vla-SetCellAlignment tobj (setq j (1+ j)) colleft acMiddleLeft)
[code]
(defun populate-table (tobj tlist rowlines collines)
(setq i (- 1)
data (car tlist)
) ;_ end of setq
(repeat (/ (length data) 4)
(setq txtstr (car data)
inspt (vlax-safearray->list (cadr data))
textstyle (caddr data)
txtht (cadddr data)
rowcol (get-rowcol inspt rowlines collines)
row (car rowcol)
col (cadr rowcol)
rowheight (caddr rowcol)
colwidth (cadddr rowcol)
) ;_ end of setq
(if (= txtstr "DESCRIPTION")
(setq colleft col)
) ;_ end of if
(if (= row 0)
(progn
(if (< col 5)
(progn
(vla-SetText tobj 0 0 txtstr)
(vla-SetCellTextStyle tobj 0 0 textstyle)
(vla-SetCellTextHeight tobj 0 0 txtht)
) ;_ end of progn
(progn
(if (> (length collines) 7)
(progn
(vla-SetText tobj 0 6 "CALCULATED CABLE DISTANCE")
(vla-SetCellTextStyle tobj 0 6 textstyle)
(vla-SetCellTextHeight tobj 0 6 txtht)
) ;_ end of progn
) ;_ end of if
) ;_ end of progn
) ;_ end of if
) ;_ end of progn
(progn
(vla-SetText tobj row col txtstr)
) ;_ end of progn
) ;_ end of if
(vla-SetCellTextHeight tobj row col txtht)
(vla-SetColumnWidth tobj col colwidth)
(vla-SetRowHeight tobj row rowheight)
(vla-SetCellTextStyle tobj row col textstyle)
(repeat 4
(setq data (cdr data))
) ;_ end of repeat
) ;_ end of repeat
(setq j 1)
(repeat (- (length rowlines) 3)
(vla-SetCellAlignment tobj (setq j (1+ j)) colleft acMiddleLeft)
) ;_ end of repeat
) ;_ end of populate-table
[/code]
So what would be the solution? I am getting the same error. I am not a LISP expert, but looking through the code, it would seem that "DESCRIPTION" and "CALCULATED CABLE DISTANCE" are both required in order for the routine to work.
Try this one for plain text table (wwould not working with mtext though)
;; Import the multi column plain text ;; ;; into newly created Excel file ;; ;; written by Fatty (c) 2007 * all rights released ;; ;; edited 8/20/08 (defun rem-dups (mylist / newlst) ;; remove duplicates ;; published by hutch (foreach item mylist (and (null (member item newlst)) (setq newlst (cons item newlst)) ) ) newlst ) (defun get-contents (/ data en i ip output p1 p2 rowlist ss tmp txt ylist) (setq data nil);debug only (alert "Select text by window selection\n\twithout title") (setq p1 (getpoint "\nSpecify the first corner point around the text ") p2 (getcorner p1 "\nSpecify the opposite corner point of window ") ) (setq ss (ssget "W" p1 p2 (list (cons 0 "TEXT"))) i -1 ) (repeat (sslength ss) (setq en (ssname ss (setq i (1+ i))) ip (cdr (assoc 10 (entget en))) txt (cdr (assoc 1 (entget en))) tmp (cons txt ip) data (cons tmp data) ) ) (setq ylist (mapcar 'caddr data) ylist (rem-dups ylist) ylist (vl-sort ylist (function (lambda (a b) (> a b)))) ) (repeat (length ylist) (setq rowlist (vl-remove-if-not (function (lambda (x) (equal (caddr x) (car ylist) 0.01) ) ) data ) rowlist (vl-sort rowlist (function (lambda (a b) (< (cadr a) (cadr b)))) ) ) (setq output (append output (list rowlist))) (setq ylist (cdr ylist)) ) (setq output (mapcar (function (lambda (x) (mapcar 'car x) ) ) output ) ) output ) ;; *** main part *** ;; (defun C:ETT (/ adoc aexc awb axss cll col colm csht rowdata excel_list nwb osm rang row sht ) (vl-load-com) (setq excel_list (get-contents)) (setq fname (getstring T "\nEnter an Excel file name without XLS extension: ")) (setq aexc (vlax-get-or-create-object "Excel.Application") awb (vlax-get-property aexc "Workbooks") nwb (vlax-invoke-method awb "Add") sht (vlax-get-property nwb "Sheets") csht (vlax-get-property sht "Item" 1) cll (vlax-get-property csht "Cells") ) (vlax-put-property csht 'Name "Table") (vla-put-visible aexc :vlax-false) (setq n 1 num (length (car excel_list)) ) (repeat num (setq row 1 colm n ) (setq rowdata (mapcar 'car excel_list)) (repeat (length rowdata) (vlax-put-property cll "Item" row colm (vl-princ-to-string (car rowdata)) ) (setq row (1+ row)) (setq rowdata (cdr rowdata)) ) (setq excel_list (mapcar 'cdr excel_list)) (setq row (1+ row) n (1+ n) ) ) (setq rang (vlax-get-property csht "UsedRange")) ;; Horizontal alignment Left(Indent) : (vlax-put-property rang "Horizontalalignment" (vlax-make-variant -4131 3) ) ;; Vertical alignment Center : (vlax-put-property rang "VerticalAlignment" (vlax-make-variant -4108 3) ) ;; Set text format : (vlax-put-property rang "NumberFormat" (vlax-make-variant "@" 8); <-- text format (use "0,000" for number format) ) (vlax-invoke-method (vlax-get-property csht "Columns") "AutoFit") (vlax-invoke-method nwb 'SaveAs (strcat (getvar "dwgprefix") fname ) -4143 nil nil :vlax-false :vlax-false 1 2 ) (vlax-invoke-method aexc "Quit") (mapcar (function (lambda (x) (vl-catch-all-apply (function (lambda () (progn (vlax-release-object x) (setq x nil) ) ) ) ) ) ) (list cll csht rang sht nwb awb aexc) ) (gc) (princ) ) ;; TesT : ;;(C:ETT) (princ "\n\t*** Type ETT to execute...") (princ)
Command APPLOAD
Load the *.lsp file you needs,
Start with the new Command COT
follow further instructions
Thanks I had found a similar lisp from bunch of lisp files on freecadtipsandtricks.com but I forgot which one was that. It worked. Thanks again.