Change visibility state of dynamic block contained in another block

Change visibility state of dynamic block contained in another block

C.Utzinger
Collaborator Collaborator
812 Views
3 Replies
Message 1 of 4

Change visibility state of dynamic block contained in another block

C.Utzinger
Collaborator
Collaborator

HI

 

I get this code from a old post from Lee Mac.

I can change the visibility state from two different blocks and perfectly.

 

But one of them is contained in another block "el_1" and then it does not work. 

Is it possible to change this visibility state? 

 

(defun c:<Test6 ( / blk bkl2 idx obj sel vis )
(setq blk "SPI-Adressen" ;; Block Name
      blk2 "SPI-EL-Adressen"
      vis "Büro Basel" ;; New Visibility State
)
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)))))
(repeat (setq idx (sslength sel))
(if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
(LM:SetVisibilityState obj vis)
)
)
)
(if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk2)))))
(repeat (setq idx (sslength sel))
(if (= (strcase blk2) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
(LM:SetVisibilityState obj vis)
)
)
)
(princ)
)
;; 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)
)
;; 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)))
)
)
(vl-load-com) (princ)
0 Likes
Accepted solutions (1)
813 Views
3 Replies
Replies (3)
Message 2 of 4

pbejse
Mentor
Mentor
Accepted solution

 


@C.Utzinger wrote:

HI

 

 

 

...But one of them is contained in another block "el_1" and then it does not work. 

Is it possible to change this visibility state? 

 


 

(defun c:<Test6	(/ blk  idx obj sel vis)
  
  (setq	blks '( "SPI-Adressen" 	 "SPI-EL-Adressen")
	vis  "Büro Basel" 	;; New Visibility State
  )
	
(vlax-for blk (vla-get-blocks (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
	(if
  		(eq :vlax-false (vla-get-isXref blk))
                 (vlax-for h blk
                       (and
                                (vlax-write-enabled-p h)
                                (eq	(vla-get-ObjectName h) "AcDbBlockReference")
				(eq 	(vla-get-IsDynamicBlock h)  :vlax-true)
				(member (vla-get-EffectiveName h) blks)    
				(LM:SetVisibilityState h vis) 
                                )
                              )
                           )
                       )
  
	(vla-regen aDoc acActiveViewport)
  )

HTH

Message 3 of 4

C.Utzinger
Collaborator
Collaborator

HI

 

Thank you very much!!!

 

Best regards

0 Likes
Message 4 of 4

pbejse
Mentor
Mentor

@C.Utzinger wrote:

 

....Thank you very much!!!

 


Good for you Cree-G, Glad it helps.

 

Cheers