Hello.
I'm trying to figure out how to create a list of all locked layers in a drawing. Then unlock those layers. Then lock them again.
Thank you.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Solved by dlanorh. Go to Solution.
Here are my VL routines. You pass in the list created by (rh:lock_lyr_lst)
;; unlock all layers : requires list of locked layer objects (defun rh:unlock_lyrs (lst) (mapcar '(lambda (x) (vlax-put-property x 'lock :vlax-false)) lst) );end_defun ;; relock all previously locked layers : requires list of locked layer objects (defun rh:relock_lyrs (lst) (mapcar '(lambda (x) (vlax-put-property x 'lock :vlax-true)) lst) );end_defun ;return list of locked layer objects : requires layer collection (defun rh:lock_lyr_list (lyrs / lst) (if (= "AcDbLayerTable" (vlax-get-property lyrs 'objectname)) (vlax-map-collection lyrs '(lambda (x) (if (= :vlax-true (vlax-get-property x 'lock)) (setq lst (cons x lst))))) );end_if lst );end_defun
(vl-load-com)
(defun c:test (/ c_doc lyrs lock_lst)
(setq c_doc (vla-get-activedocument (vlax-get-acad-object))
c_lyrs (vla-get-layers c_doc)
lock_lst (rh:lock_lyr_list c_lyrs);;THIS IS THE LIST OF LOCKED LAYER TO PASS INTO UNLOCK/LOCK
)
(rh:unlock_lyrs lock_lst)
;.....REST OF CODE
(rh:relock_lyrs lock_lst)
);end_defun
I am not one of the robots you're looking for
Christ... yea ok i definitely couldn't have figured that out myself 😕
That seems to work great though, thanks!
One thing I did change was I removed the Unlock parts and replaced it with (command "-layer" "u" "*" "").
I figured it would do the same job right? A few less lines to deal with.
It does the same think but 10x slower for a single layer, not that you'd notice. 😁
I am not one of the robots you're looking for
@Anonymous wrote:
Hello.
I'm trying to figure out how to create a list of all locked layers in a drawing. Then unlock those layers. Then lock them again.
Thank you.
(defun _Unlocked (layers / _LockedlayerState) (vlax-for itm layers (if (minusp (vlax-get itm 'Lock)) (progn (setq _LockedlayerState (cons itm _LockedlayerState)) (vlax-put itm 'Lock 0) ) ) ) _LockedlayerState ) (defun demo (/ c_doc lyrs lock_lst) (setq aDoc (vla-get-activedocument (vlax-get-acad-object)) clayrs (vla-get-layers aDoc) L_locked (_Unlocked clayrs) ) ;<<< Do you thing here >>> (foreach itm L_locked ;<-- if not nil (vlax-put itm 'Lock -1)) )
Unlocked the layer while in the process of creating the locked layer list.
Ok dlanorh, thanks for clearing that up. And yes that's right 3wood, that's what I was suggesting to dlanorh 👍
pbejse - I popped in the rest of my code into your routine & tried it out as well. It seems to work perfectly!
Thank you all for you're help, I really appreciate it.
If you don't really need them as a list specifically, but a comma-delimited string will do, the re-locking becomes simpler:
(defun C:GLL (/ lay); = Get Locked Layers (while (setq lay (tblnext "layer" (not lay))) (if (= (logand (cdr (assoc 70 lay)) 4) 4); locked (setq LockedLayers (strcat (cond (LockedLayers) ("")) (cdr (assoc 2 lay)) ",")) ); if ); while ); defun (defun C:UAL (); = Unlock All Layers (command "_.layer" "_unlock" "*" "") ); defun (defun C:RLL () ; = Relock [formerly] Locked Layers (command "_.layer" "_lock" LockedLayers "") ); defun
This is very great code. It resolved what I'm looking for everywhere while other solution provided longer routine to somehow achieve it.
@Kent1Cooper Further to this routine, if i want to not only save the lock state of layers but all states (on/off, frozen/thawed, lock/unlock), how to go about to achieve this? I don't have any idea on how to modified the lisp around the dxf code.
@azri_kun wrote:
.... if i want to not only save the lock state of layers but all states (on/off, frozen/thawed, lock/unlock), how to go about to achieve this? ....
You've got the right word in there -- with a Layer STATE. This is just what they're for. -LAYER command, stAte option, Save -- give it a name, check that it's showing "Yes" on all the properties you want it to know about, and Enter a few times to back out. Then when you've done whatever you needed to change Layer conditions for, and you want it all back the way it was, use the -LAYER / stAte / Restore option.
Many thanks. Really appreciate you taking time to reply especially with the formatings.
I tried to use command as you mentioned, however during selection of states that I want to pick, the yes no option is globally save where it option will switch between yes and no and I have no way to know if user current setting is yes or no. Which mean I could flip the no to yes and yes to no.
Is there any way to achieve this concretely to set yes or no for each states?
@Kent1Cooper wrote "...but a comma-delimited string will do,..."
Not if the string exceeds 256 characters.
John F. Uhden
@john.uhden wrote:
@Kent1Cooper wrote "...but a comma-delimited string will do,..."
Not if the string exceeds 256 characters.
Not true. An individual Layer's name cannot exceed 255 characters according to Help, but a comma-delimited string of Layer names can. I just verified that using 6 Layer names, each 50 characters long, for a total string length of 305 characters including the commas. A -LAYER command happily made them all in the New option, and LOcked them all, using that string.
Maybe the rules have changed over the years. I was basing my claim on conditions in ACAD2002.
Is the same as you say true for Freeze and Thaw options?
John F. Uhden
@john.uhden wrote:
....
Is the same as you say true for Freeze and Thaw options?
Yes, and Color, and Unlock. I didn't try all the other options, but I assume they'll all accept that kind of string.
Thanks for that verification, Kent. It will undoubtedly change any future code I write having to deal with lots of layers. Of course if the old ones still work, then why bother fixing them?
John F. Uhden
Can't find what you're looking for? Ask the community or share your knowledge.