Setting multiple visibility states to a group of items?

Setting multiple visibility states to a group of items?

matthew_neesley
Collaborator Collaborator
1,007 Views
5 Replies
Message 1 of 6

Setting multiple visibility states to a group of items?

matthew_neesley
Collaborator
Collaborator

Has anyone come up with a way to pick a group of objects and assign them as "Visible" in several visibility states at once?  I am doing a lot of very-involved dynamic block authoring.  All of my blocks have at least eight visibility states, and it would be great to (for example) select a rectangle inside a block, then say "I need this 'VISIBLE' in these 6 states only" in one fell swoop.  Thanks for any advice!

0 Likes
Accepted solutions (1)
1,008 Views
5 Replies
Replies (5)
Message 2 of 6

CodeDing
Advisor
Advisor

@matthew_neesley ,

 

Sounds like layering will be your best friend here. Have you tried that?

 

Best,

~DD

0 Likes
Message 3 of 6

ВeekeeCZ
Consultant
Consultant

Here is something simple... quickly done.

Two limitations...

- since I don't know how to retrieve the name of the block currently being edited in the Block Editor (unless is typed  manually) - you need to use BEditSaveName to enter the block editor

- secondly, don't know how to get the current visible state. So the routine always sets the top one of the list when finished.

 

(vl-load-com)

(defun c:BEditSaveName ( / s blk vis nam)
  
  (princ "\nSelect a block, ")
  
  (if (and (setq s (ssget "_+.:E:S" '((0 . "INSERT"))))
	   (setq blk (vlax-ename->vla-object (ssname s 0)))
	   (setq vis (LM:getvisibilityparametername blk))
	   (setq *ebn-lst* (LM:getdynpropallowedvalues blk vis))
	   (setq nam (LM:blockname blk))
	   )
    (command "_.bedit" nam))
  (princ)
  )


(defun c:VisibleStates ( / *error* cmd s)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if cmd (setvar 'cmdecho cmd))
    (princ))
  
  (setq cmd (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  
  (if (and (setq s (ssget))
	   *ebn-lst*)
    (progn
      (foreach e *ebn-lst*
	(initget "No")
	(or (getkword (strcat "\nAdd object to '" e "' state [No] <yes>: "))
	    (command "_.bvstate" "_set" e
		     "_.bvshow" s "" "_current")))
      (command "_.bvstate" "_set" (car *ebn-lst*))))
  (setvar 'cmdecho 1)
  (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)
  )


;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

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


;; Get Dynamic Block Properties  -  Lee Mac
;; Returns an association list of Dynamic Block properties & values.
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [lst] Association list of (( . ) ... )

(defun LM:getdynprops ( blk )
  (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
	  (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)))
    )
  )


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

(defun LM:getvisibilitystate ( blk / vis )
  (if (setq vis (LM:getvisibilityparametername blk))
    (LM:getdynpropvalue blk vis)
    )
  )

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

 

0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant

The site removed me the <yes>

 

(or (getkword (strcat "\nAdd object to '" e "' state [No] <yes>: "))

 

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

This may  be useful to you, the param is the name of the visibility state eg "Visibity1" it will the display in  a dcl all the options and you can pick which one. For multiple on can use Multi toggles instead.

 

(setq dynlst (LM:getdynpropallowedvalues  obj param))
(ah:butts but "v"  (append (list "Please choose") dynlst))

This is displayed another dynamic block has 8 visibilty states the only issue is the name of the visibility parameter.

 

 screenshot305.png

0 Likes
Message 6 of 6

matthew_neesley
Collaborator
Collaborator
Accepted solution

I have not yet had time to dig deeply into all the responses yet, but thanks very much to all that contributed!

0 Likes