; Created by Lee Mak http://www.cadtutor.net/forum/showthread.php?92854-insert-block-from-.txt&p=635332&viewfull=1#post635332
; Modified by Igal Averbuh 2015
(defun c:csb ( / *error* blk cmd cnt csv des dwg ins str )

(defun *error* ( msg )
(if (= 'file (type des)) (close des))
(if (= 'int (type cmd)) (setvar 'cmdecho cmd))
(if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
(princ (strcat "\nError: " msg))
)
(princ)
)

(setq blk "ppoint" ;; Block to insert
cmd (getvar 'cmdecho)
)
(setvar 'cmdecho 0)
(cond
( (not
(or (tblsearch "block" (setq dwg blk))
(and (setq dwg (findfile (strcat blk ".dwg")))
(progn
(command "_.-insert" dwg nil)
(tblsearch "block" (setq dwg blk))
)
)
)
)
(alert "\nFirst of All Create Block ppoint.dwg and Put it to Autocad Support directory!\n")
(princ (strcat "\n\"" blk ".dwg\" not found."))
)
( (not (setq csv (getfiled "Select CSV" "" "csv" 16))))
( (not (setq des (open csv "r")))
(princ (strcat "\nUnable to open \"" csv "\" for reading."))
)
( (setq cnt 0)
(while (setq str (read-line des))
(if (and (setq ins (read (strcat "(" (vl-string-translate "," " " str) ")")))
(< 1 (length ins) 4)
(vl-every 'numberp ins)
(setq cnt (1+ cnt))
)
(command "_.-insert" dwg "_s" 1.0 "_r" 0.0 "_non" ins)
(princ (strcat "\n\"" str "\" is not a valid point."))
)
)
(setq des (close des))
(if (< 0 cnt)
(alert (strcat "\n" (itoa cnt) " block" (if (= 1 cnt) "" "s") " inserted."))
(princ "\nSelected CSV file does not contain valid point data.")
)
)
)
(*error* nil)
(princ)
)

(c:csb)

Advertisements