Get Layer Status

Function Syntax (LM:GetLayerStatus)
Current Version 1.0

Program Description

This subfunction is a primarily academic venture, using a variety programming techniques to return the status of all layers in a drawing.

I hope that programmers of all levels may benefit in some way from it.

Select all
;;-------------------=={ Get Layer Status }==-----------------;;
;;                                                            ;;
;;  Returns a list of dotted pairs detailing the status of    ;;
;;  each layer in a drawing.                                  ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright  2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun LM:GetLayerStatus ( / FindBits List->String cAssoc IterateLayers )

  (defun FindBits ( n / b )
    (if (< 0 n)
      (cons
        (setq b
          (expt 2
            (fix (/ (log n) (log 2)))
          )
        )
        (FindBits (- n b))
      )
    )
  )

  (defun List->String ( lst del )
    (if (cdr lst)
      (strcat (car lst) del (List->String (cdr lst) del))
      (car lst)
    )
  )

  (defun cAssoc ( key lst ) (cdr (assoc key lst)))

  (defun IterateLayers ( def )
    (
      (lambda ( status )
        (if def
          (cons
            (cons (cAssoc 2 def)
              (List->String
                (apply 'append
                  (cons (list (if (minusp (cAssoc 62 def)) "Off" "On"))
                    (mapcar
                      (function
                        (lambda ( c ) (list (cAssoc c status)))
                      )
                      (FindBits (logand (cAssoc 70 def) (~ 112)))
                    )
                  )
                )
                ","
              )
            )
            (IterateLayers (tblnext "LAYER"))
          )
        )
      )
     '((1 . "Frozen")
       (2 . "Frozen in VP")
       (4 . "Locked")
      )
    )
  )

  (foreach x (IterateLayers (tblnext "LAYER" T))
    (if (cdr x) (print x))
  )
  (princ)
)

Example of Output

("0" . "On")
("DEFPOINTS" . "On,Frozen")
("Layer1" . "Off,Locked")
("Layer2" . "Off,Frozen")
("Layer3" . "On,Locked")
("Layer4" . "On")
("Layer5" . "On,Frozen in VP")

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010