谢谢Brandon
效率方面的一个次要问题:由于所有属性定义都被添加到同一块定义中,我建议将块定义对象分配给局部变量,以避免需要从块集合中为每个添加的属性定义检索应用程序对象、文档对象、块集合和块定义,例如:
- (defun c:addattribs ( / blk [color=red]def[/color] )
- (while
- (not
- (or (= "" (setq blk (getstring t "\nName of block to update: ")))
- (tblsearch "BLOCK" blk)
- )
- )
- (princ (strcat "\nBlock "" blk "" not found."))
- )
- (if (/= "" blk)
- (progn
- [color=red](setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk))[/color]
- (vla-addattribute [color=red]def[/color]
- (getvar 'textsize)
- acattributemodelockposition
- "New Attribute 1"
- (vlax-3D-point 0 0)
- "NEW_TAG1"
- "New Value 1"
- )
- (vla-addattribute [color=red]def[/color]
- (getvar 'textsize)
- acattributemodelockposition
- "New Attribute 2"
- (vlax-3D-point 0 (- (* 1.5 (getvar 'textsize))))
- "NEW_TAG2"
- "New Value 2"
- )
- (command "_.attsync" "_N" blk)
- )
- )
- (princ)
- )
- (vl-load-com) (princ)
|