TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: wjbzone on February 16, 2004, 03:50:38 PM

Title: Check the Lock/UnLock layer status
Post by: wjbzone 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
Title: Check the Lock/UnLock layer status
Post by: JohnK 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?
Title: Check the Lock/UnLock layer status
Post by: daron on February 16, 2004, 05:24:48 PM
Is that an accurate email address John? hehe
Title: Check the Lock/UnLock layer status
Post by: JohnK on February 16, 2004, 06:15:21 PM
Hey he's the one that put it there. (I cant touch it! :? :lol:)
Title: Check the Lock/UnLock layer status
Post by: CAB 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)
)
Title: Check the Lock/UnLock layer status
Post by: SMadsen 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))))
  )
)
Title: Check the Lock/UnLock layer status
Post by: CAB 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
Title: Check the Lock/UnLock layer status
Post by: wjbzone 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
Title: Check the Lock/UnLock layer status
Post by: CAB 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
Title: Check the Lock/UnLock layer status
Post by: SMadsen 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.