George V. Fournier Jr., CTS
Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
2006 AUGI DAWG (7th) - NJ AUGI Camp
Volunteer Firefighter since 1985 & Bagpiper Wanna-be
With the freedom of expression comes great responsibility
If I try this as a LISP I get completely lost:
(vl-load-com)
;TTBL - Export Tables to CSV file
(DEFUN C:TTBL ()
(TableExport nil "C:\Users\gfournier\Documents\AutoCAD Files/Tables.CSV" "MyPrefix")
(defun ReadList (lst /)
(cond
((= (type lst) 'Str) (ReadList (read (strcat "(" (vl-string-translate ",;" " " lst) ")"))))
((= (type lst) 'Sym) (eval lst))
((= (type lst) 'List) (mapcar (function ReadList) lst))
(t lst)
)
)
(defun SelectObjects (pt filter / ss n lst)
(if pt
(progn
(setq pt (ReadList pt))
(if (= (type pt) 'List)
(cond
((and (>= (length pt) 2) (vl-every (function (lambda (i) (member (type i) '(Int Real)))) pt))
(setq n (list (/ (getvar 'ViewSize) (* (getvar 'PickBox) 80.0)) 0.0)
n (cons (car n) n)
ss (ssget "C" (mapcar '- pt n) (mapcar '+ pt n) filter)
)
)
((vl-every (function
(lambda (i)
(and (= (type i) 'List) (vl-every (function (lambda (j) (member (type j) '(Int Real)))) i))
)
)
pt
)
(cond
((= (length pt) 1) (setq lst (SelectObjects (car pt) filter)))
((= (length pt) 2) (setq ss (ssget "C" (car pt) (cadr pt) filter)))
(t (setq ss (ssget "CP" pt filter)))
)
)
)
)
)
(setq ss (ssget "X" filter))
)
(if ss
(progn (setq n (sslength ss)) (while (>= (setq n (1- n)) 0) (setq lst (cons (ssname ss n) lst))))
)
lst
)
(defun TableExport (pt fname prefix / lst eo f row col str)
(if (and (setq lst (SelectObjects pt '((0 . "ACAD_TABLE"))))
(setq f (open fname "a"))
)
(progn
(foreach en lst
(setq eo (vlax-ename->vla-object en)
row -1
)
(while (< (setq row (1+ row)) (vla-get-Rows eo))
(setq col -1
str ""
)
(while (< (setq col (1+ col)) (vla-get-Columns eo))
(setq str (strcat str ",\"" (vla-GetText eo row col) "\""))
)
(setq str (strcat ",\"" (vla-get-Handle eo) "\"" str "\n"))
(if prefix
(setq str (strcat ",\"" prefix "\"" str))
)
(princ (substr str 2) f)
)
)
(close f)
)
)
)
George V. Fournier Jr., CTS
Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
2006 AUGI DAWG (7th) - NJ AUGI Camp
Volunteer Firefighter since 1985 & Bagpiper Wanna-be
With the freedom of expression comes great responsibility
Make sure that if you use backslashes in your path they get doubled. That's why I prefer using forward slashes instead.
So your path should read as either one of these:Code:"C:/Users/gfournier/Documents/AutoCAD Files/Tables.CSV" "C:\\Users\\gfournier\\Documents\\AutoCAD Files\\Tables.CSV"
Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!
George V. Fournier Jr., CTS
Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
2006 AUGI DAWG (7th) - NJ AUGI Camp
Volunteer Firefighter since 1985 & Bagpiper Wanna-be
With the freedom of expression comes great responsibility
George V. Fournier Jr., CTS
Sr. Sales Engineer - Autodesk Product Design Suite Premium 2014
2006 AUGI DAWG (7th) - NJ AUGI Camp
Volunteer Firefighter since 1985 & Bagpiper Wanna-be
With the freedom of expression comes great responsibility
Sorry, I must've missed this post. Try using the getfiled function. That shoul open a dialog so you can pic a filename. It returns the full path string or nil if the user cancels.
Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!