- (vl-load-com)
- (defun strsplit (string delimited / pos lst)
- (while (setq pos (vl-string-search delimited string))
- (setq lst (cons (substr string 1 pos) lst)
- string (substr string (+ pos 1 (strlen delimited)))
- )
- )
- (reverse (cons string lst))
- )
- (defun parse-filename ()
- (strsplit (vl-string-trim " \r\t\n" (vl-filename-base (getvar "DWGNAME"))) " ")
- )
- ;; ("MM-01" "平面图" "5")
- (defun c:tt (/ block i kx ss tag)
- (setq kx (parse-filename))
- (if (setq ss (ssget "X" '((0 . "INSERT") (66 . 1) (2 . "KX-目录属性块"))))
- (progn
- (setq i -1)
- (repeat (sslength ss)
- (setq block (vlax-ename->vla-object (ssname ss (setq i (1+ i)))))
- (foreach att (vlax-safearray->list
- (vlax-variant-value (vla-getattributes block))
- )
- (setq tag (vla-get-tagstring att))
- (cond
- ((= "总页码" tag)
- (vla-put-textstring att (nth 2 kx))
- )
- ((= "图号" tag)
- (vla-put-textstring att (nth 0 kx))
- )
- ((= "图名" tag)
- (vla-put-textstring att (nth 1 kx))
- )
- )
- )
- )
- )
- )
- (princ)
- )
|