Dialog box to turn on/off certain layer

Dialog box to turn on/off certain layer

Thomasbatson
Collaborator Collaborator
529 Views
6 Replies
Message 1 of 7

Dialog box to turn on/off certain layer

Thomasbatson
Collaborator
Collaborator

I am very limited in my lsp and dcl coding and have only done very basic things so far.  I have tried to put together a way for our users to turn on/off (and freeze/thaw) certain layers by selecting a checkbox instead of going through the layers dropdown all the time.  I have attached what I have, it pulls up the dialog box and I can check the 1 I am trying to test (0-Seal, just trying to test 1 to start) but it doesn't thaw/turn on that layer.  

 

Does anyone have any advice?  I saw a few posts about something along the lines but they looked different but will continue to search as well.  

 

Thank you

0 Likes
530 Views
6 Replies
Replies (6)
Message 2 of 7

pendean
Community Legend
Community Legend
Q: why not implement and use LAYERSTATEs? One easy pulldown for users to use is right there on the Ribbon, you can even move it around if needed
https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-5312A8BD-DD94-47D6-B1BA-5E0AF5E0CED8#:~:text=...
0 Likes
Message 3 of 7

Thomasbatson
Collaborator
Collaborator

Editing reply, I will have to look at the layer states.

0 Likes
Message 4 of 7

Sea-Haven
Mentor
Mentor

If the layers are known can do a lisp  defun for each group of layers, say use command L1, L2 or ground, floor etc. There is code that turns off a layer if on and if ran again the layer is off will turn on. Can be modifed to look at a list of layers. That code has been posted many times but I don't have it.

 

 

0 Likes
Message 5 of 7

komondormrex
Mentor
Mentor

just for starter

(defun c:SealLayers ()
	(setq lay_state_nam_num_list '(
								  	("0" "0-SEAL" 1) ("0" "0-SEAL_AREAWRK" 2) ("0" "0-SEAL_BIDPRUPOSE" 3) 
									("0" "0-SEAL_DOCUTXT" 4) ("0" "0-SEAL_E-COPY" 5) ("0" "0-SEAL_CLIENT USE" 6) 
									("0" "0-SEAL_PRELIMTXT" 7) ("0" "0-SEAL_E-PROF INFO" 😎 
									("0" "0-SEAL_REFTXT" 9) ("0" "0-SEAL_REVIEW" 10)
								  )
		  dialog (load_dialog "SealLayers.dcl")
	)
	(if (not (new_dialog "SealLayers" dialog))
		(exit)
		(progn
			(action_tile "OK" "(progn (change_state (get_state lay_state_nam_num_list)) (done_dialog))") 
  			(start_dialog)
  			(unload_dialog dialog)
		)
	)
)

(defun Get_State (lay_state_nam_num_list)
	(setq index 0)
	(repeat (length lay_state_nam_num_list)
		(setq lay_state_nam_num_list (subst (append (list (get_tile (strcat "checkbox" (itoa (last (nth index lay_state_nam_num_list))))))
													(cdr (nth index lay_state_nam_num_list))
											)
											(nth index lay_state_nam_num_list)
											lay_state_nam_num_list
									 )
			  index (1+ index)
		)
	)
	lay_state_nam_num_list
)
(defun change_state (lay_state_nam_num_list)
	(mapcar '(lambda (layer) (progn (set-layer-visibility (cadr layer) (atoi (car layer)))
;									(thaw-turn-on-thaw-all-viewports...)
							 )
			 )
			 lay_state_nam_num_list
	)
)

(defun set-layer-visibility (layer-name status)
  	(if (tblsearch "layer" layer-name) (vlax-put layer-name 'LayerOn status))
)

;(defun thaw-turn-on-thaw-all-viewports (layer-name status)
;  (vlax-for layout (vla-get-layouts (vla-get-activeDocument (vlax-get-acad-object)))
;  	(vlax-for object (vla-get-block layout)
;    	(if (= "AcDbViewport" (vla-get-objectname object))
;    	  (progn
;		  		should define here what you are going to do with vp's layers or else
;    	  )
;    	)
;  )
;)
0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant

Another way to consider this is to use a layer filter. It creates SEAL filter if needed, then launches the layer dialog with this filter current. 

 

(vl-load-com)

(defun c:SealLayers (/ :LayerFilterList n)
  
  (defun :LayerFilterList (/ :SubFilterList)
    (defun :SubFilterList (dict / ent lst)
      (foreach ent (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 350)) dict))
	(setq lst (append lst (cons ent (if (assoc 360 (entget ent)) (:SubFilterList (entget (cdr (assoc 360 (entget (cdr (assoc 360 (entget ent))))))))))))) lst)
    (mapcar '(lambda (x) (cdr (assoc 300 (entget x))))
	    (:SubFilterList (dictsearch (vlax-vla-object->ename (vla-getextensiondictionary (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))) "ACLYDICTIONARY"))))
  
  (setq n "SEAL")
  (setvar 'cmdecho 0)
  (if (not (member n (:LayerFilterList)))
    (command "_.-LAYER" "_Filter" "_New" "_P" "All" "NAME==\"0-SEAL*\" OR NAME==\"Layer*\"" n ""))
  (command "_.-LAYER" "_Filter" "_Set" n "")
  (command "_.-LAYER" "_Filter" "_Set" n "") ; for some reason
  (initdia) (command "_.LAYER")
  (setvar 'cmdecho 1)
  (princ)
  )

 

0 Likes
Message 7 of 7

Thomasbatson
Collaborator
Collaborator

Thank you I will look for it.

0 Likes