用下面的函数修改块的属性:
;;;***************************************************************************;;;
;;; MODULE: vlex-ChangeAttributes (lst) ;;;
;;; DESCRIPTION: ;;;
;;; ARGS: ;;;
;;; EXAMPLE: (vlex-ChangeAttributes (list blk (cons "tag" "new-value"))) ;;;
;;;***************************************************************************;;;
;;; Arguments:
;;; A list containing one atom and one or more dotted pairs.
;;; The atom is the entity name of the block to change.
;;; The dotted pairs consist of the attribute tag and the new value for that attribute.
;;;
;;; Notes:
;;; Modifies the specified attribute in the specified block reference
;;;***************************************************************************;;;
(vl-load-com)
(defun vlex-ChangeAttributes (lst / blk itm atts)
(setq blk (vlax-Ename->vla-Object (car lst))
lst (cdr lst)
)
(if (= (vla-Get-HasAttributes blk) :vlax-true)
(progn
(setq atts (vlax-SafeArray->list
(vlax-Variant-Value (vla-GetAttributes blk))
)
); setq
(foreach item lst
(mapcar
'(lambda (x)
(if (= (strcase (car item)) (strcase (vla-Get-TagString x)))
(vla-Put-TextString x (cdr item))
); endif
)
atts
); mapcar
); foreach
(vla-Update blk)
)
); endif
)
参数为一个表: (块实体名 (属性标记 . 新的属性值))