Match block visibility from source to destination.

Match block visibility from source to destination.

smallƑish
Advocate Advocate
378 Views
4 Replies
Message 1 of 5

Match block visibility from source to destination.

smallƑish
Advocate
Advocate

Is that possible to write a lisp to match Visibility of a Dynamic block to another one. Same like match properties in default autocad.

0 Likes
Accepted solutions (1)
379 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution
(vl-load-com)

(defun c:MatchVisibility ( / LM:getvisibilityparametername e p v s i)

  ;; http://www.lee-mac.com/dynamicblockfunctions.html#getvisibilityparametername
  ;; 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))))
    )
  
  ; ==========================================================================================================================
  
  (if (and (setq e (car (entsel "\nSelect source block: ")))
	   (or (= "INSERT" (cdr (assoc 0 (entget e))))
	       (prompt "\nError: Selected object is not a block!"))
	   (or (setq p (LM:getvisibilityparametername (vlax-ename->vla-object e)))
	       (prompt "\nError: Selected block has no visibility parameter!"))
	   (setq v (getpropertyvalue e (strcat "AcDbDynBlockProperty" p)))
	   (princ "\nSelect destination blocks...")
	   )
    (while (setq s (ssget "_:S" '((0 . "INSERT"))))
      (repeat (setq i (sslength s))
	(if (setq p (LM:getvisibilityparametername (vlax-ename->vla-object (setq e (ssname s (setq i (1- i)))))))
	  (vl-catch-all-apply 'setpropertyvalue (list e (strcat "AcDbDynBlockProperty" p) v))))))
  (princ)
  )
Message 3 of 5

smallƑish
Advocate
Advocate

Thank you So much it's perfect.

0 Likes
Message 4 of 5

bfalconr
Contributor
Contributor

Hi, sorry to bother, shoult I type MatchVisibility in autocad to get it work?

Please let me know,

Thank you

Bruno Falcon

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

You can add (c:MatchVisibility) as last line, then when you load it the first time it wil run, if you want to run again yes type "MatchVisibility" you could make the function name shorter or add a new defun with an abbreviation. NOTE can not use "MV" that is already used by CAD.

 

You could add this at end of code .

 

(defun c:Mvis ( / )
(command "MatchVisibility")
)

 

You should add this at the start of code, as recognition of who provided code.

 

; Match visibilty between dynamic blocks
; By BeekeeCZ March 2025

 

 

0 Likes