Swap the visibility state in a block using lisp.

Swap the visibility state in a block using lisp.

ByronU78KM
Enthusiast Enthusiast
282 Views
2 Replies
Message 1 of 3

Swap the visibility state in a block using lisp.

ByronU78KM
Enthusiast
Enthusiast

I have a problem I have written 4 lisp that I have attached. What they do is swap the visibility state of the dynamic block I created. There is really on two lisp each one is auto run and the other is a command to run. I have attached two of the lisp and the block. It runs perfect on some machine and the on others I get no function definition: LM:BLOCKNAME" on the command line. I cannot figure out what is missing on these machines. 

 Thank you - Byron

0 Likes
283 Views
2 Replies
Replies (2)
Message 2 of 3

paullimapa
Mentor
Mentor

I see that you're missing this Lee Mac function found on this link

LM:blockname :

 

;; Block Name  -  Lee Mac
;; Returns the true (effective) name of a supplied block reference
                        
(defun LM:blockname ( obj )
    (if (vlax-property-available-p obj 'effectivename)
        (defun LM:blockname ( obj ) (vla-get-effectivename obj))
        (defun LM:blockname ( obj ) (vla-get-name obj))
    )
    (LM:blockname obj)
)

 

Hopefully you have the other LM: functions involving visiblity state

 

;; Set Dynamic Block Visibility State  -  Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; blk - [vla] VLA Dynamic Block Reference object
;; val - [str] Visibility State Parameter value
;; Returns: [str] New value of Visibility Parameter, else nil

(defun LM:SetVisibilityState ( blk val / vis )
    (if
        (and
            (setq vis (LM:getvisibilityparametername blk))
            (member (strcase val) (mapcar 'strcase (LM:getdynpropallowedvalues blk vis)))
        )
        (LM:setdynpropvalue blk vis val)
    )
)

;; Set Dynamic Block Property Value  -  Lee Mac
;; Modifies the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; val - [any] New value for property
;; Returns: [any] New value if successful, else nil

(defun LM:setdynpropvalue ( blk prp val )
    (setq prp (strcase prp))
    (vl-some
       '(lambda ( x )
            (if (= prp (strcase (vla-get-propertyname x)))
                (progn
                    (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))
                    (cond (val) (t))
                )
            )
        )
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions

(defun LM:getdynpropallowedvalues ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)

;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil

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

 

All of the above need to be loaded in order for your lisp to work

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 3

komondormrex
Mentor
Mentor

a function to get the dyn property by name

 

(defun get_dyn_property_by_name (dyn_property_name insert_object / dyn_property_found)
	(if (vl-some '(lambda (dyn_property) (= dyn_property_name (vla-get-propertyname (setq dyn_property_found dyn_property))))
				  (vlax-invoke insert_object 'getdynamicblockproperties)
		)
		dyn_property_found
		nil
	)
)

 

and a function to set a value to the dyn property

 

(defun set_dyn_property (dyn_property_name value \ stamp_property)
	(if (setq stamp_property (get_dyn_property_by_name dyn_property_name (vlax-ename->vla-object (car (entsel "\nPick stamp block: "))))) 
		(vla-put-value stamp_property value)
		(princ "\nThat block doesn't have \"STAMP\" property")
	)
	(princ)
)

 

usage:

 

set the value of the existing dyn property "STAMP" of the selected block to "Prelim"

(set_dyn_property "STAMP" "Prelim")

 

set the value of the existing dyn property "STAMP" of the selected block to "Stamp"

(set_dyn_property "STAMP" "Stamp")

 

0 Likes