欢迎来到CADTutor。
我已经编写了这个例程,希望它能够满足您的需要,并被告知Excel文件必须具有扩展名。csv以允许代码选择它。
试试看,让我知道。
- (defun c:Test (/ Deconstruct_Strings f o st bks ss l)
- ;; Author : Tharwat Al Shoufi ;;
- ;; Date : 15. April. 2014 ;;
- (defun Deconstruct_Strings (string delimiter / pos lst)
- (while (setq pos (vl-string-search delimiter string 0))
- (progn (setq lst (cons (substr string 1 pos) lst))
- (setq string (substr string (+ pos 2) (strlen string)))
- )
- )
- (if string
- (setq lst (cons string lst))
- )
- (setq lst (reverse lst))
- )
- (if (and (setq f (getfiled "Select Excel file to Update Attributes ..."
- (getvar 'DWGPREFIX)
- "csv"
- 16
- )
- )
- (setq o (open f "r"))
- )
- (progn (while (setq st (read-line o))
- (setq l (cons (Deconstruct_Strings st ";") l))
- )
- (setq bks
- (apply 'strcat
- (mapcar '(lambda (u) (strcat u ",")) (mapcar 'cadr l))
- )
- )
- (close o)
- )
- )
- (if (and bks
- (setq
- ss (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 bks)))
- )
- )
- ((lambda (i / sn h get e n)
- (while (setq sn (ssname ss (setq i (1+ i))))
- (setq h (cdr (assoc 5 (entget sn))))
- (if (and l
- (vl-some '(lambda (x)
- (if (vl-some '(lambda (u) (eq u h)) x)
- (setq get x)
- )
- )
- l
- )
- )
- (progn
- (setq n 1
- l (vl-remove get l)
- )
- (while
- (/=
- (cdr (assoc 0 (setq e (entget (setq sn (entnext sn)))))
- )
- "SEQEND"
- )
- (if (eq (cdr (assoc 0 e)) "ATTRIB")
- (entmod (subst (cons 1 (nth (setq n (1+ n)) get))
- (assoc 1 e)
- e
- )
- )
- )
- )
- )
- )
- )
- )
- -1
- )
- )
- (princ)
- )(vl-load-com)
|