Apply to Block Objects

Function Syntax (LM:ApplytoBlockObjects <blks> <name> <func>)
Current Version 1.1
Symbol Type Description
blks VLA-Object Block Collection Object in which block to be processed resides
name String Name of block to which function will be applied
func Function Function taking a single VLA-Object argument
Type Description
List List of the results of evaluating the function on every object in the block definition

Function Description

This subfunction will evaluate a supplied function on all objects in a block definition and return a list of the result of each function evaluation.

The function argument should be a function requiring a single VLA-Object argument which will be evaluated on each object in the specified block definition.

If the supplied block name is not present in the supplied block collection, the function will return nil.

Select all
;; 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)

Example Function Call

The following example program will move all objects in a block to Layer "0".

Note: a regen is required to view the result.

Select all
(defun c:test ( / s )
    (princ "\nSelect Block: ")
    (if (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
            (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"))
(vl-load-com) (princ)


increase · reset · decrease

Designed & Created by Lee Mac © 2010