本帖最后由 菜卷鱼 于 2014-4-15 12:59 编辑
http://lee-mac.com/applytoblockobjects.html
 - ;; Apply to Block Objects - Lee Mac
- ;; Evaluates a supplied function on all objects in a block definition.
- ;; Arguments:
- ;; blks - VLA Block Collection in which block resides
- ;; name - Block name
- ;; func - function to apply to all objects in block
- ;; Returns a list of results of evaluating the function, else nil.
- (defun LM:ApplytoBlockObjects ( blks name func / def result )
- (setq func (eval func))
- (if (not (vl-catch-all-error-p (setq def (vl-catch-all-apply 'vla-item (list blks name)))))
- (vlax-for obj def (setq result (cons (func obj) result)))
- )
- (reverse result)
- )
The following example program will move all objects in a block to Layer "0".
 - (defun c:test ( / s )
- (princ "\nSelect Block: ")
- (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
- (LM:ApplytoBlockObjects
- (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
- (vla-get-effectivename (vlax-ename->vla-object (ssname s 0)))
- '(lambda ( obj ) (vla-put-layer obj "0"))
- )
- )
- (princ)
- )
- (vl-load-com) (princ)
|