Layer lock/unlock toggle

Layer lock/unlock toggle

msarqui
Collaborator Collaborator
2,406 Views
4 Replies
Message 1 of 5

Layer lock/unlock toggle

msarqui
Collaborator
Collaborator

Hi,

 

I was wondering if it is possible to have a routine that will toggle between LOCK and UNLOCK the selected layers. So, the trick is, it must work with SSGET to let the OP select as many objects as he wants, and then lock the layers of those that are unlocked, or unlock the layers of those that are locked.

 

Thanks for your help.

 

Marcelo

0 Likes
Accepted solutions (1)
2,407 Views
4 Replies
Replies (4)
Message 2 of 5

msarqui
Collaborator
Collaborator

I my research, I found something that could help, but I have no idea how to put this together:

 

;;;  Returns T if Locked
;;;        nil if Unlocked or not found
;;;        nil if lname is not a string
(defun islayerlocked (lname / entlst)
  (and (= 'str (type lname))
       (setq entlst (tblsearch "LAYER" lname))
       (= 4 (logand 4 (cdr (assoc 70 entlst))))
  )
)

And here, another one very interesting from Lee Mac. This will lock the selected layers:

 

(defun c:lck ( / b e i l s x )

  (if (setq s (ssget))
    (repeat (setq i (sslength s))
      (if (not (member (setq l (cdr (assoc 8 (entget (ssname s (setq i (1- i))))))) x))
        (progn
          (setq e (entget (tblobjname "LAYER" l))
                x (cons l x)
                b (cdr (assoc 70 e))
          )
          (entmod (subst (cons 70 (logior 4 b)) (assoc 70 e) e))
        )
      )
    )
  )
  (princ)
)

 

Thanks again!

Marcelo

 

 

0 Likes
Message 3 of 5

hmsilva
Mentor
Mentor
Accepted solution

Hi Marcelo!

 

Quick and dirty...

(Untested)

 

(defun c:demo (/ i lay layer layers lay_lst ss)
  (setq layers (vla-get-layers (vla-get-activedocument (vlax-get-Acad-Object))))
  (princ "\nSelect objects to toggle LOCK/UNLOCK object layers: ")
  (if (setq ss (ssget))
    (repeat (setq i (sslength ss))
      (setq lay (vla-get-layer (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
      (if (or (null lay_lst)
              (not (vl-position lay lay_lst))
          )
        (progn
          (setq layer (vla-item layers lay))
          (vlax-put layer 'lock (~ (vlax-get layer 'lock)))
          (setq lay_lst (cons lay lay_lst))
        )
      )
    )
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

Message 4 of 5

msarqui
Collaborator
Collaborator

Perfect as always Henrique.

It is really nice to have your help.

Thank You

Marcelo

Message 5 of 5

hmsilva
Mentor
Mentor

You're welcome, Marcelo!
Glad I could help

Henrique

EESignature

0 Likes