本帖最后由 vectra 于 2017-9-27 16:24 编辑
- ;;;(get-att-textstrings (vlax-ename->vla-object (car (entsel))) '("图号" "图名文字1"))
- (defun get-att-textstrings (obj names / rt tag)
- (foreach att (vlax-safearray->list
- (vlax-variant-value (vla-getattributes obj))
- )
- (setq tag (vla-get-tagstring att))
- (if (member tag names)
- (setq rt (cons (cons tag (vla-get-textstring att)) rt))
- )
- )
- (reverse rt)
- )
- ;;;(put-att-textstrings (vlax-ename->vla-object (car (entsel))) '(("图号" . "ABC")))
- (defun put-att-textstrings (obj values / text)
- (foreach att (vlax-safearray->list
- (vlax-variant-value (vla-getattributes obj))
- )
- (if (setq text (cdr (assoc (vla-get-tagstring att) values)))
- (vla-put-textstring att text)
- )
- )
- )
- ;; 以图框中标记为“图号”的属性值修改当前布局名称
- (defun c:th (/ name obj ss)
- (if (= "Model" (getvar "CTAB"))
- (princ "无法在模型空间中使用该命令。")
- (if (setq ss (ssget "X"
- (list '(0 . "INSERT")
- '(2 . "A*_Tileblock")
- (cons 410 (getvar "CTAB"))
- )
- )
- )
- (progn
- (setq obj (vlax-ename->vla-object (ssname ss 0))
- name (cdr (assoc "图号" (get-att-textstrings obj '("图号"))))
- )
- (command "_.LAYOUT" "R" "" name)
- )
- )
- )
- (princ)
- )
- ;; 当前布局名称替换图框中标记为“图号”的属性值
- (defun c:bj (/ obj ss)
- (if (= "Model" (getvar "CTAB"))
- (princ "无法在模型空间中使用该命令。")
- (if (setq ss (ssget "X"
- (list '(0 . "INSERT")
- '(2 . "A*_Tileblock")
- (cons 410 (getvar "CTAB"))
- )
- )
- )
- (progn
- (setq obj (vlax-ename->vla-object (ssname ss 0)))
- (put-att-textstrings obj (list (cons "图号" (getvar "CTAB"))))
- )
- )
- )
- (princ)
- )
每个布局里必须要放且只能有一个图框。欢迎测试反馈BUG。
|