Author Topic: Check the Lock/UnLock layer status  (Read 4247 times)

0 Members and 1 Guest are viewing this topic.

wjbzone

  • Guest
Check the Lock/UnLock layer status
« on: February 16, 2004, 03:50:38 PM »
I have a lisp program that copies a polyline out of one layer and into a newly created layer. It works fine unless the existing layer is locked.

I can unlock the layer, but I want to check the lock/unlock status so I can restore the original setting. How can I check the status?

Thanks,
Bill

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9282
Check the Lock/UnLock layer status
« Reply #1 on: February 16, 2004, 05:10:30 PM »
With this fancy dancy lil procedure.
Code: [Select]
;;; FUNCTION
;;; determines if a layer is locked, returns either :vlax-true
;;; or :vlax-false
;;;
;;; ARGUMENTS
;;; layer name = string
;;;
;;; USAGE
;;; (if (= (MST-IslockedLayer "Layername") :vlax-true)
;;; (prompt "layer is locked"))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2003 Mark S. Thomas
;;; mark.thomas@bigswamp.org
;;;
;;; VERSION
;;; 1.0 Wed Thu Apr 03, 2003
(defun MST-IslockedLayer (lname)
  (if
    (not
      (vl-catch-all-error-p
        (vl-catch-all-apply
          'vla-item
          (list
            (vla-get-Layers
              (vla-get-ActiveDocument
                (vlax-get-acad-object)
                )
              )
            lname
            ); list
          )
        )
      ); not
    (vlax-get-property
      (vla-item
        (vla-get-Layers
          (vla-get-ActiveDocument
            (vlax-get-acad-object)
            )
          )
        lname); layer name
      'Lock)
    )
  ); defun


does that help ya?
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

daron

  • Guest
Check the Lock/UnLock layer status
« Reply #2 on: February 16, 2004, 05:24:48 PM »
Is that an accurate email address John? hehe

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9282
Check the Lock/UnLock layer status
« Reply #3 on: February 16, 2004, 06:15:21 PM »
Hey he's the one that put it there. (I cant touch it! :? :lol:)
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

CAB

  • Global Moderator
  • Seagull
  • Posts: 10369
Check the Lock/UnLock layer status
« Reply #4 on: February 16, 2004, 10:39:16 PM »
Here is the Plain Lisp version.
If your are interested.

Code: [Select]
;;;  Returns T if Locked
;;;        nil if Unlocked or not found
;;;        nil if lname is not a string
(defun IsLayerLocked (lname / ent )
  (if (and (=(type lname) 'STR)(setq ent (tblobjname "layer" lname)))
      (= 4 (logand 4 (cdr (assoc 70 (entget ent)))))
  )
) ; end defun


;;;  Returns T if On
(defun IsLayerOn (lname / ent )
  (if (and (=(type lname) 'STR)(setq ent (tblobjname "layer" lname)))
      (null (minusp (cdr (assoc 62 (entget ent)))))
  )
) ; end defun


;;;  Returns T if Frozen
(defun IsLayerFrozen (lname / ent )
  (if (and (=(type lname) 'STR)(setq ent (tblobjname "layer" lname)))
      (= 1 (logand 1 (cdr (assoc 70 (entget ent)))))
  )
) ; end defun


;;;  Returns T if Plot is Off
(defun IsLayerPlotOff (lname / ent )
  (if (and (=(type lname) 'STR)(setq ent (tblobjname "layer" lname)))
      (zerop (cdr (assoc 290 (entget ent))))
  )
) ; end defun


;;;  Returns T if Layer is Frozen In New View Port
(defun IsLayerFrozenInNewVP (lname / ent )
  (if (and (=(type lname) 'STR)(setq ent (tblobjname "layer" lname)))
      (= 2 (logand 2 (cdr(assoc 70 (entget ent)))))
  )
) ; end defun


(defun c:ltest()
  (if (setq lname (getstring "Enter a layer name. "))
    (progn
    (prompt "\nLayer locked ")
    (princ (IsLayerLocked lname))
   
    (prompt "\nLayer is On ")
    (princ (IsLayerOn lname))
   
    (prompt "\nLayer is Frozen ")
    (princ (IsLayerFrozen lname))
   
    (prompt "\nLayer Plot is Off ")
    (princ (IsLayerPlotOff lname))
   
    (prompt "\nLayer is Frozen In a new VP ")
    (princ (IsLayerFrozenInNewVP lname))
   
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Check the Lock/UnLock layer status
« Reply #5 on: February 17, 2004, 07:47:35 AM »
CAB, just tell me to shut up and mind my own business - but why the overhead of TBLOBJNAME and ENTGET when code 70 (and 62) is returned by the much quicker TBLSEARCH?

Code: [Select]
(defun IsLayerLocked (lname / tblst)
  (and (= 'STR (type lname))
       (setq tblst (tblsearch "LAYER" lname))
       (= 4 (logand 4 (cdr (assoc 70 tblst))))
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10369
Check the Lock/UnLock layer status
« Reply #6 on: February 17, 2004, 08:51:59 AM »
Wow-That is soooo simple,  But not obvious, to me anyway.

Thank you for showing me the way.

I swear i'm going to get there someday. :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

wjbzone

  • Guest
Check the Lock/UnLock layer status
« Reply #7 on: February 17, 2004, 09:06:03 AM »
Thanks for the help.

I am using the SMadsen method. It gets the job done!!

I had already tried out the Se7ens and it was working. I need to study that one a little more to understand whats going on with the vla statements.

All great responses!
Bill

CAB

  • Global Moderator
  • Seagull
  • Posts: 10369
Check the Lock/UnLock layer status
« Reply #8 on: February 17, 2004, 09:37:51 AM »
Ok, here they are all fixed up. :)
Thanks again Stig.

I could not find a list of exactly what the tblsearch returned
except for the examples given in the online help.
So guess I need to do a test to see what each table returns before using it.

CAB

Code: [Select]
;;;  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))))
  )
)


;;;  Returns T if On
(defun islayeron (lname / entlst)
  (and (= (type lname) 'str)
       (setq entlst (tblsearch "layer" lname))
       (null (minusp (cdr (assoc 62 entlst))))
  )
) ; end defun


;;;  Returns T if Frozen
(defun islayerfrozen (lname / entlst)
  (and (= (type lname) 'str)
       (setq entlst (tblsearch "layer" lname))
       (= 1 (logand 1 (cdr (assoc 70 entlst))))
  )
) ; end defun


;;;  Returns T if Plot is Off
(defun islayerplotoff (lname / ent)
  (and (= (type lname) 'str)
       (setq ent (tblobjname "layer" lname))
       (zerop (cdr (assoc 290 (entget ent))))
  )
) ; end defun


;;;  Returns T if Layer is Frozen In New View Port
(defun islayerfrozeninnewvp (lname / entlst)
  (and (= (type lname) 'str)
       (setq entlst (tblsearch "layer" lname))
       (= 2 (logand 2 (cdr (assoc 70 entlst))))
  )
) ; end defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Check the Lock/UnLock layer status
« Reply #9 on: February 17, 2004, 10:19:18 AM »
Quote from: CAB
I could not find a list of exactly what the tblsearch returned
except for the examples given in the online help.
I don't think there is a complete listing. It depends on the symbol table and the entry itself. For example, code 1 is not returned for ordinary blocks - even though they hold such a property - but it's returned for xref's.