Change vis state with dialog box

Change vis state with dialog box

charles_neelyFG4LK
Contributor Contributor
1,107 Views
17 Replies
Message 1 of 18

Change vis state with dialog box

charles_neelyFG4LK
Contributor
Contributor

I have a lisp that will change the visibility state of a dynamic block in all layouts (h/t Lee Mac). I would like to use a dialog box with either a list or a pull-down menu to set the variable for the visibility state. Can anyone help with that?

0 Likes
Accepted solutions (1)
1,108 Views
17 Replies
  • Lisp
Replies (17)
Message 2 of 18

paullimapa
Mentor
Mentor

Could you share that lisp and the dynamic block that you want this to work on?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 18

charles_neelyFG4LK
Contributor
Contributor

Here are the files

0 Likes
Message 4 of 18

paullimapa
Mentor
Mentor

so when you click on the down triangle, you don't like to select the visibility states options from that list?

paullimapa_0-1743613667248.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 18

charles_neelyFG4LK
Contributor
Contributor

The lisp will change the vis state in all layouts which is desirable. Typically there are multiple layouts. 

0 Likes
Message 6 of 18

paullimapa
Mentor
Mentor

try VSetP.lsp...no dialog box but select a # list from cursor menu.

Load & run VSetP then select the dynamic block in this case WSB-SCALE-DYN on the drawing screen and you'll get this # list to select from:

paullimapa_0-1743615079654.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 18

ВeekeeCZ
Consultant
Consultant

Found a routine that I've posted already before.... to match the visibility state. Just fix one, then run the routine to match the rest. 

 

(vl-load-com)

(defun c:MatchVisibility ( / LM:getvisibilityparametername e p v s i)
  
  ;; http://www.lee-mac.com/dynamicblockfunctions.html#getvisibilityparametername
  (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)))
	   (setq s (ssget "_A" '((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)
  )

 

0 Likes
Message 8 of 18

charles_neelyFG4LK
Contributor
Contributor

Got this error when running that lisp
; error: bad argument type: stringp nil

0 Likes
Message 9 of 18

paullimapa
Mentor
Mentor

Here's a new code VSetPW.lsp that lets you select from a window list box.

PS: Double clicking will also dismiss the list box with the current item selected

paullimapa_0-1743629114219.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 18

ВeekeeCZ
Consultant
Consultant

@charles_neelyFG4LK wrote:

Got this error when running that lisp
; error: bad argument type: stringp nil


 

Sorry, difficult to fix since I'm not able to replicate the issue.

0 Likes
Message 11 of 18

komondormrex
Mentor
Mentor
Accepted solution

@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))
				)
			)
		  )
	 )
)
;**********************************************************************************************************************
0 Likes
Message 12 of 18

Sea-Haven
Mentor
Mentor

@komondormrex if you have a block and can select it then this should produce _list.

 

(setq obj (vlax-ename->vla-object (car (entselect '\nPick a block "))))
(setq visval (LM:getvisibilityparametername obj))
(setq _lst (LM:getdynpropallowedvalues obj visval))
0 Likes
Message 13 of 18

paullimapa
Mentor
Mentor

which is exactly how I did that in my code I posted previously:

paullimapa_0-1743809818446.png

paullimapa_1-1743809870934.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 18

Sea-Haven
Mentor
Mentor

Sorry @paullimapa missed that, because there is more than 20 visibility states yes have to use a list box, rather than say a radio button solution, which I cut the code from. Just me would have had 2 blocks one for 1:x and the other for V x & H y, bit easier to choose.

 

If the 1:x is used with a layout viewport to indicate scale you can get the viewport scale so would auto set to correct 1:x without need for selecting scale.

0 Likes
Message 15 of 18

paullimapa
Mentor
Mentor

tricky thing is the 2nd portion of the lists contains selections that would give you multiple scales or multiple scale bars:

paullimapa_0-1743812638684.png

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 18

komondormrex
Mentor
Mentor

@Sea-Haven

and if you have only the block name, like in the op's code? i mean you start the code getting the block name to do dialog, nothing's been selected so far. and btw i'd prefer it lm free))) i mean there is nothing that complex to write such a code from scratch, for me to be correct))) 

0 Likes
Message 17 of 18

ВeekeeCZ
Consultant
Consultant

@charles_neelyFG4LK wrote:

Got this error when running that lisp
; error: bad argument type: stringp nil


 

Try the updated code. It should overcome the error.

0 Likes
Message 18 of 18

charles_neelyFG4LK
Contributor
Contributor

Been away from this for a few days. Thanks for the help with this, got me all set up!

 

0 Likes