Dynamic Block Functions

Introduction

Here are various subfunctions which may be used to manipulate dynamic block properties using Visual LISP; information about the purpose, arguments and returns of each function is detailed in the code header.

Get Dynamic Property Value

Select all
;;------------=={ Get Dynamic Property Value }==--------------;;
;;                                                            ;;
;;  Returns the value of a Dynamic Block Property, if present ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - VLA Dynamic Block Reference Object                ;;
;;  prop  - Dynamic Block Property Name                       ;;
;;------------------------------------------------------------;;
;;  Returns: Value of property, else nil                      ;;
;;------------------------------------------------------------;;

(defun LM:GetDynamicPropValue ( block prop )
    (setq prop (strcase prop))
    (vl-some
        (function
            (lambda ( _prop )
                (if (eq prop (strcase (vla-get-propertyname _prop)))
                    (vlax-get _prop 'Value)
                )
            )
        )
        (vlax-invoke block 'GetDynamicBlockProperties)
    )
)

Set Dynamic Property Value

Select all
;;------------=={ Set Dynamic Property Value }==--------------;;
;;                                                            ;;
;;  Modifies the value of a Dynamic Block Property            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - VLA Dynamic Block Reference Object                ;;
;;  prop  - Dynamic Block Property Name                       ;;
;;  value - New value for Property                            ;;
;;------------------------------------------------------------;;
;;  Returns: Value property was set to, else nil              ;;
;;------------------------------------------------------------;;

(defun LM:SetDynamicPropValue ( block prop value )
    (setq prop (strcase prop))
    (vl-some
        (function
            (lambda ( _prop )
                (if (eq prop (strcase (vla-get-propertyname _prop)))
                    (progn
                        (vla-put-value _prop
                            (vlax-make-variant value
                                (vlax-variant-type (vla-get-value _prop))
                            )
                        )
                        value
                    )
                )
            )
        )
        (vlax-invoke block 'GetDynamicBlockProperties)
    )
)

Get Dynamic Properties

Select all
;;---------------=={ Get Dynamic Properties }==---------------;;
;;                                                            ;;
;;  Returns a list of Dynamic Block Properties & Values.      ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - VLA Dynamic Block Reference Object                ;;
;;------------------------------------------------------------;;
;;  Returns: Association list of ((<prop> . <value>) ... )    ;;
;;------------------------------------------------------------;;

(defun LM:GetDynamicProps ( block )
    (mapcar
        (function
            (lambda ( _prop )
                (cons (vla-get-propertyname _prop) (vlax-get _prop 'Value))
            )
        )
        (vlax-invoke block 'GetDynamicBlockProperties)
    )
)

Get Property Allowed Values

Select all
;;------------=={ Get Property Allowed Values }==-------------;;
;;                                                            ;;
;;  Returns the allowed values for a specific property.       ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - VLA Dynamic Block Reference Object                ;;
;;  prop  - Dynamic Block Property Name                       ;;
;;------------------------------------------------------------;;
;;  Returns: Allowed values for prop, nil if no restriction   ;;
;;------------------------------------------------------------;;

(defun LM:GetPropAllowedValues ( block prop )
    (setq prop (strcase prop))
    (vl-some
        (function
            (lambda ( _prop )
                (if (eq prop (strcase (vla-get-propertyname _prop)))
                    (vlax-get _prop 'AllowedValues)
                )
            )
        )
        (vlax-invoke block 'GetDynamicBlockProperties)
    )
)

Get Visibility Parameter Name

Select all
;;-----------=={ Get Visibility Parameter Name }==------------;;
;;                                                            ;;
;;  Returns the name of the Visibility Parameter of a         ;;
;;  Dynamic Block (if present).                               ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block  -  VLA (Dynamic) Block Reference Object            ;;
;;------------------------------------------------------------;;
;;  Returns:  Name of Visibility Parameter, else nil          ;;
;;------------------------------------------------------------;;

(defun LM:GetVisibilityParameterName ( block / visib )  
    (if
        (and
            (vlax-property-available-p block 'effectivename)
            (setq block
                (vla-item
                    (vla-get-blocks (vla-get-document block))
                    (vla-get-effectivename block)
                )
            )
            (eq :vlax-true (vla-get-isdynamicblock block))
            (eq :vlax-true (vla-get-hasextensiondictionary block))
            (setq visib
                (vl-some
                    (function
                        (lambda ( pair )
                            (if
                                (and
                                    (= 360 (car pair))
                                    (eq "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
                                )
                                (cdr pair)
                            )
                        )
                    )
                    (dictsearch
                        (vlax-vla-object->ename (vla-getextensiondictionary block))
                        "ACAD_ENHANCEDBLOCK"
                    )
                )
            )
        )
        (cdr (assoc 301 (entget visib)))
    )
)

Get Visibility State

Select all
;;----------------=={ Get Visibility State }==----------------;;
;;                                                            ;;
;;  Returns the value of the Visibility Parameter of a        ;;
;;  Dynamic Block (if present)                                ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block  -  VLA (Dynamic) Block Reference Object            ;;
;;------------------------------------------------------------;;
;;  Returns:  Value of Visibility Parameter, else nil         ;;
;;------------------------------------------------------------;;

(defun LM:GetVisibilityState ( block )
    (
        (lambda ( name )
            (vl-some
                (function
                    (lambda ( prop )
                        (if (eq name (vla-get-propertyname prop))
                            (vlax-get prop 'value)
                        )
                    )
                )
                (vlax-invoke block 'getdynamicblockproperties)
            )
        )
        (LM:GetVisibilityParameterName block)
    )
)

Set Visibility State

Select all
;;----------------=={ Set Visibility State }==----------------;;
;;                                                            ;;
;;  Sets the Visibility Parameter of a Dynamic Block          ;;
;;  (if present) to a specific value (if allowed).            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block  -  VLA (Dynamic) Block Reference Object            ;;
;;  value  -  Visibility Parameter value                      ;;
;;------------------------------------------------------------;;
;;  Returns:  Value of Visibility Parameter, else nil         ;;
;;------------------------------------------------------------;;

(defun LM:SetVisibilityState ( block value )
    (
        (lambda ( name value )
            (vl-some
                (function
                    (lambda ( prop )
                        (if
                            (and
                                (eq name (vla-get-propertyname prop))
                                (member value (mapcar 'strcase (vlax-get prop 'allowedvalues)))
                            )
                            (progn
                                (vla-put-value prop
                                    (vlax-make-variant value (vlax-variant-type (vla-get-value prop)))
                                )
                                value
                            )
                        )
                    )
                )
                (vlax-invoke block 'getdynamicblockproperties)
            )
        )
        (LM:GetVisibilityParameterName block) (strcase value)
    )
)

textsize

increase · reset · decrease