1
116
115
初来乍到
使用道具 举报
7
6
(defun C:ImpDes ( / ;;All Functions declared locally ImpDes:err ImpDes:sav ImpDes:res parsestring layouts layers ;;Saved variables for restore ocmd olderr ;;Local Variables data file fileline objad lay ) (vl-load-com) (setq objad (vla-get-activedocument (vlax-get-acad-object))) ;******************************************************************* ; Error Handling, Save and Restore ;******************************************************************* (defun ImpDes:err (s / ) (if (/= s "Function cancelled") (if (= s "quit / exit abort") (princ) (princ (strcat "\nError < " s " >")) );if );if (ImpDes:res);restore environment (princ) ) ;--------------------------------------------------------- (defun ImpDes:sav ( / ) (vla-StartUndoMark objad) (setq ocmd (getvar "cmdecho") olderr *error* *error* ImpDes:err ) (setvar "cmdecho" 0) ) ;--------------------------------------------------------- (defun ImpDes:res ( / ) (setvar "cmdecho" ocmd) (setq *error* olderr); restore old *error* handler (gc);garbage collection (vla-EndUndoMark objad) (princ) ) ;;****************************************************************** ;; Local Functions ;;****************************************************************** (defun parsestring ( str / res found previous) (setq str (vl-string-right-trim "," str) found (vl-string-position 44 str 0) previous -1 ) (while (and found (< found (strlen str))) (setq res (cons (substr str (+ 2 previous) (- found previous 1)) res) previous found found (vl-string-position 44 str (1+ previous)) ) ) (setq res (cons (substr str (+ 2 previous)) res)) (reverse res) ) ;;****************************************************************** (defun layouts ( layout ) (if (and (not (member layout (layoutlist))) (/= layout "Model") ) (vla-add (vla-get-layouts objad) layout) ) ) ;;****************************************************************** (defun layers ( lay / objlay actlyr ) (if (null (tblsearch "LAYER" lay)) (vla-add (vla-get-layers objad) lay) (progn (setq objlay (vla-item (vla-get-layers objad) lay) actlyr (vla-get-name (vla-get-activelayer objad)) ) (vla-put-layeron objlay :vlax-true) (vla-put-lock objlay :vlax-false) (if (/= lay actlyr) (vla-put-freeze objlay :vlax-false) ) ) );if ) ;;****************************************************************** ;; Main Program Code ;;****************************************************************** (ImpDes:sav);Save variables for error handling (if (and (setq file (getfiled "Design File To Import" "" "csv" 4)) (setq file (open file "r")) ) (progn (read-line file) ;ignore header info (while (setq fileline (read-line file)) ;read whole file (if (/= fileline "") (setq data (append data (list (parsestring fileline)))) ;store data ) ) (close file) (foreach line data (if (and (>= (length line) 6) (apply 'and (mapcar (function (lambda ( x ) (> (strlen x) 0) ) ) line ) ) );and (progn (layouts (car line)) (layers (cadr line))