Saving & restoring Layer States

Discussion in 'AutoCAD' started by Jamie Duncan, Jul 31, 2003.

  1. Jamie Duncan

    Jamie Duncan Guest

    If someone needs to do this in a lisp routine:


    (defun c:savealllayers (/ end1 temp )
    (setq Savethelayers nil temp T)
    (while (setq end1 (tblnext "LAYER" temp))
    (setq temp nil
    Savethelayers (cons (list (cdr (assoc 2 end1))(cdr (assoc 70
    end1))(cdr (assoc 62 end1))) Savethelayers)
    )
    )
    )
    (defun c:Restorealllayers (/ temp layval1 laynam1 layval2 lay_on lay_off
    lay_f Lay_t lay_lo lay_un)
    (setq lay_on "" lay_off "" lay_lo "" lay_un "" lay_f "" lay_t "")
    (defun sr_strg ( sr1 /)
    (strcat sr1 (if (> (strlen sr1) 0) "," "") laynam1)
    )
    (foreach temp Savethelayers
    (setq laynam1 (car temp) layval1 (cadr temp))
    (princ laynam1)
    (if (tblsearch "LAYER" laynam1)
    (progn
    (if (> 0 (caddr temp)) (setq lay_off (sr_strg lay_off))(setq
    lay_on (sr_strg lay_on)))
    (if (= (logand layval1 1) 1)(setq lay_f (sr_strg lay_f))(setq
    lay_t (sr_strg lay_t)))
    (if (= (logand layval1 4) 1)(setq lay_lo (sr_strg lay_lo))(setq
    lay_un (sr_strg lay_on)))
    )
    )
    )
    (if (> (strlen lay_on) 0) (command "-layer" "on" lay_on ""))
    (if (> (strlen lay_off) 0)(command "-layer" "off" lay_off ""))
    (if (> (strlen lay_t) 0)(command "-layer" "t" lay_t ""))
    (if (> (strlen lay_lo) 0) (command "-layer" "lo" lay_lo ""))
    (if (> (strlen lay_f) 0) (command "-layer" "f" lay_f ""))
    (if (> (strlen lay_un) 0) (command "-layer" "un" lay_un ""))
    )
     
    Jamie Duncan, Jul 31, 2003
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.