@charles_neelyFG4LK
check this mod to your code
;Contains lisp routines to change the visibility state of the WSB-SCALE-DYN block
;This is for the Renewables Group
;If there are any issues with its use please contact Charlie Neely, charles.neely@wsbeng.com
(defun c:ChgScaleBlock ()
(setq blk "WSB-SCALE-DYN" ;; Block Name
;; vis "1 = 10" ;; New Visibility State
;; komondormrex
_list '("1 = 10" "1 = 20" "1 = 30" "1 = 40" "1 = 50" "1 = 60" "1 = 100" "1 = 200" "1 = 300" "1 = 400"
"1 = 500" "1 = 600" "1 = 700" "1 = 800" "1 = 1000" "1 = 1500" "1 = 2000" "H 1 = 20 V 1 = 4" "H 1 = 20 V 1 = 5"
"H 1 = 20 V 1 = 10" "H 1 = 30 V 1 = 4" "H 1 = 30 V 1 = 5" "H 1 = 30 V 1 = 10" "H 1 = 40 V 1 = 4"
"H 1 = 40 V 1 = 5" "H 1 = 40 V 1 = 10" "H 1 = 50 V 1 = 4" "H 1 = 50 V 1 = 5" "H 1 = 50 V 1 = 10"
"H 1 = 100 V 1 = 5" "H 1 = 100 V 1 = 10" "H 1 = 20 V 1 = 4 BAR" "H 1 = 20 V 1 = 5 BAR" "H 1 = 20 V 1 = 10 BAR"
)
vis (get_listed_choice vis "Pick Visibility State" _list nil)
;; komondormrex
)
(if (and vis (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)) '(410 . "~Model")))))
(repeat (setq idx (sslength sel))
(if (= (strcase blk) (strcase (blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))))))
(SetVisibilityState obj vis)
)
)
)
(princ)
)
;; Block Name
;; Returns the true (effective) name of a supplied block reference
(defun blockname ( obj )
(if (vlax-property-available-p obj 'effectivename)
(defun blockname ( obj ) (vla-get-effectivename obj))
(defun blockname ( obj ) (vla-get-name obj))
)
(blockname obj)
)
;; Set Dynamic Block Visibility State
;; 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 SetVisibilityState ( blk val / vis )
(if
(and
(setq vis (getvisibilityparametername blk))
(member (strcase val) (mapcar 'strcase (getdynpropallowedvalues blk vis)))
)
(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 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
;; 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 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
;; 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 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)))
)
)
;**********************************************************************************************************************
; komondormrex, apr 2025
;**********************************************************************************************************************
(defun get_listed_choice (set_choice list_prompt _list multiple / dcl_lines dcl_filename_full glc_dcl_id _list
dialog_result selected_choices default_choice
)
;******************************************************************************************************************
(defun write_dialog_file (dcl_lines / temp_file_path dcl_filename_full dcl_file_id)
(setq temp_file_path (vla-get-TempFilePath (vla-get-Files (vla-get-preferences (vlax-get-acad-object))))
dcl_filename_full (vl-filename-mktemp "Dialog" temp_file_path ".dcl"])
dcl_file_id (open dcl_filename_full "w")
)
(mapcar '(lambda (dcl_str) (write-line dcl_str dcl_file_id))
dcl_lines
)
(close dcl_file_id)
dcl_filename_full
)
;******************************************************************************************************************
(defun populate_list ( list_key list_to_process )
(start_list list_key 3)
(mapcar 'add_list
(mapcar '(lambda (list_element)
(strcat "\n" list_element)
)
list_to_process
)
)
(end_list)
)
;******************************************************************************************************************
(setq dcl_lines (list "List_Box : dialog {"
"initial_focus = \"List_Box\";"
(strcat "label = \"" list_prompt "\";")
": list_box {"
"key = \"List_Box\";"
"width = 50;"
"height = 20;"
"allow_accept = true;"
(if multiple "multiple_select = true;" "")
"}"
"ok_cancel;"
"}"
)
dcl_filename_full (write_dialog_file dcl_lines)
glc_dcl_id (load_dialog dcl_filename_full)
)
(if glc_dcl_id
(if (new_dialog "List_Box" glc_dcl_id)
(progn
(populate_list "List_Box" _list)
(if (setq default_choice (vl-position set_choice _list))
(set_tile "List_Box" (itoa default_choice))
; (set_tile "List_Box" "0")
)
(action_tile "List_Box" "(cond
((= 4 $reason) (setq selected_choices $value))
(t (setq selected_choices $value))
)
"
)
(setq dialog_result (start_dialog))
(unload_dialog glc_dcl_id)
(vl-file-delete dcl_filename_full)
(cond
((= dialog_result 1)
(if selected_choices
(if multiple
(setq selected_choices (mapcar '(lambda (index) (nth index _list))
(read (strcat "(" selected_choices ")"))
)
)
(setq selected_choices (nth (atoi selected_choices) _list))
)
)
)
(t (setq selected_choices nil))
)
)
)
)
)
;**********************************************************************************************************************