Effective Block Name

Function Syntax (LM:effectivename <obj>) / (LM:al-effectivename <ent>)
Current Version 1.0
Donate
Arguments
Symbol Type Description
obj / ent VLA-Object / Entity Block Reference for which to return the effective name
Returns
Type Description
String True block name as held by the referenced block definition

Function Description

The following functions demonstrate both Visual LISP & Vanilla AutoLISP methods to obtain the true name of a standard or dynamic block reference as held by the associated block definition within the block collection of the drawing in which it resides.

The motivation for such functionality arises when programming with dynamic block references, since a dynamic block reference may reference a temporary anonymous block definition when the dynamic properties are altered.

The Visual LISP method illustrated below is the categorical method of choice for most; however, I have also included a Vanilla LISP route to allow for block names containing Unicode characters (since these are omitted when using the Visual LISP method) and also for academic purposes.

Visual LISP

Select all
;; Effective Block Name  -  Lee Mac
;; obj - [vla] VLA Block Reference object

(defun LM:effectivename ( obj )
    (vlax-get-property obj
        (if (vlax-property-available-p obj 'effectivename)
            'effectivename
            'name
        )
    )
)

Vanilla LISP

Select all
;; Effective Block Name  -  Lee Mac
;; ent - [ent] Block Reference entity

(defun LM:al-effectivename ( ent / blk rep )
    (if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**")
        (if
            (and
                (setq rep
                    (cdadr
                        (assoc -3
                            (entget
                                (cdr
                                    (assoc 330
                                        (entget
                                            (tblobjname "block" blk)
                                        )
                                    )
                                )
                               '("AcDbBlockRepBTag")
                            )
                        )
                    )
                )
                (setq rep (handent (cdr (assoc 1005 rep))))
            )
            (setq blk (cdr (assoc 2 (entget rep))))
        )
    )
    blk
)

Block Name to Effective Block Name

Function Syntax (LM:name->effectivename <blk>)
Current Version 1.0
Donate
Arguments
Symbol Type Description
blk String Block name for which to return the effective name
Returns
Type Description
String True block name as held by the referenced block definition

Function Description

Given that the Vanilla version of the above function uses the anonymous block name in order to return the effective block name, the following function removes the step of retrieving the block name and instead allows this data to be supplied as an argument to the function.

This approach allows for improved efficiency in programs in which the block name is retrieved & used elsewhere in the code (hence avoiding the need to repeatedly query the block name), and also accounts for cases in which the calling program may not have ready access to the original block reference entity.

Select all
;; Block Name -> Effective Block Name  -  Lee Mac
;; blk - [str] Block name

(defun LM:name->effectivename ( blk / rep )
    (if
        (and (wcmatch blk "`**")
            (setq rep
                (cdadr
                    (assoc -3
                        (entget
                            (cdr (assoc 330 (entget (tblobjname "block" blk))))
                           '("AcDbBlockRepBTag")
                        )
                    )
                )
            )
            (setq rep (handent (cdr (assoc 1005 rep))))
        )
        (cdr (assoc 2 (entget rep)))
        blk
    )
)

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010