; VSetP selects Dynamic Block to change Visibility States name for all found (defun c:VSetP (/ aec_getdynpropvalue blkname ent idx item LM:getdynpropallowedvalues LM:getvisibilityparametername obj sel ss vis_select visname vispar ) (if(not(car (atoms-family 1 '("vl-load-com"))))(vl-load-com)) ;******************************************************************************************** ; Sub routines ;******************************************************************************************** ;; aec_getdynpropvalue Get Dynamic Block Property Value ;; Modified from Lee Mac's LM:setdynpropvalue ;; Gets the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; Returns: value if successful, else nil (defun aec_getdynpropvalue ( blk prp / val ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (progn ; (vla-get-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (setq val(vlax-get x 'value)) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;; LM:getdynpropallowedvalues 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) ) ) ;; LM: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))) ) ) ;; 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) ) ) ;; vis_select chooses from list of Visibility States Name ;; Returns the string of the Visibility States name. ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; msg - [str] Prompt message string ;; Returns: [str] Selected Visibility States name (defun vis_select (blk prp msg / i dynmode stropt vislst visopt visstr) (setq vislst (mapcar 'strcase (LM:getdynpropallowedvalues blk prp))) ; get list of visibility states defined in dynamic block (setq visopt (itoa (1+ (vl-position (strcase (aec_getdynpropvalue blk prp)) vislst)))) ; get current visibility states name (setq i 0) (repeat (length vislst) (if(zerop i) (setq visstr "" stropt "") ; on first loop initialize strings (setq visstr (strcat visstr ", ") ; thereafter following visbility states item string add a comma separator stropt (strcat stropt (itoa i) " ") ; & add space to # selection option ) ) ; if (setq visstr (strcat visstr "(" (itoa (1+ i)) ")" (nth i vislst))) ; include count index followed by item from visbility states list (setq i (1+ i)) ) ; repeat ; modified from get keyword on screen input by Ronjonp Jan 2018 ; https://www.cadtutor.net/forum/topic/64736-getstring-a-default-value-without-print/?do=findComment&comment=533439 ; dynmode needs to be 1 or 3 to display cursor popup (if(<= (rem (getvar"dynmode") 2) 0) ; if even # chks negative value as well (progn (setq dynmode (getvar"dynmode")) ; save current setting (setvar "dynmode" 1) ; enable dynmode ) ) ; if (initget (setq stropt (strcat stropt (itoa i)))) ; include last count index in # selection option (setq visopt ; set new default (cond ; display in popup # selection option as cursor hovers over graphics area & highlite # selection options at command line ((getkword (strcat msg visstr " [" (vl-string-translate " " "/" stropt) "] <" visopt ">: "))) (visopt) ) ; cond ) ; setq (if dynmode (setvar "dynmode" dynmode)) ; restore original dynmode setting ; returns selected visibility states name (nth (1- (atoi visopt)) vislst) ) ;******************************************************************************************** ; Main function ;******************************************************************************************** (if(and (setq ss (ssget "_+.:E:S" '((0 . "INSERT")))) (setq obj (vlax-ename->vla-object (ssname ss 0))) (= (VLAX-GET-PROPERTY obj 'IsDynamicBlock) :VLAX-TRUE) ; chk if dynamic block (setq blkname (vlax-get-property obj 'EffectiveName)) (setq vispar (LM:getvisibilityparametername obj)) ; get visibility states parameter ie Visibility1 ) (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blkname))))) ; select all dynamic blocks and actual block name (progn (setq visname (vis_select obj vispar "\nSelect a Visibility States ")) ; select visibility states name (repeat (setq idx (sslength sel)) (setq obj (vlax-ename->vla-object (setq ent(ssname sel (setq idx (1- idx)))))) ; get & convert entity in selection set to obj (if (wcmatch (strcase (vla-get-effectivename obj)) (strcase blkname)) ; chk dynamic block name matches actual block name (LM:setdynpropvalue obj vispar visname) ; change visibility states ) ; if ) ; repeat (princ(strcat"\nMatching Dynamic Blocks [" blkname "] Visibility States Changed to [" visname "].")) ) ; progn ) ; if ) ; if (princ) ) ; defun