layer states function

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

  1. Jamie Duncan

    Jamie Duncan Guest

    Trying to save and restore layer states within lisp routines. Came up with
    these - seems to store 'em just fine, but doesn't seem to be able to restore
    them...any help is appreciated:

    (defun c:savealllayers (/ end1 temp )
    (setq Savethelayers nil temp T)
    (while (setq end1 (tblnext "LAYER" temp))(princ end1)
    (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)
    (foreach temp Savethelayers
    (setq laynam1 (car temp) layval1 (cadr temp) layval2 (caddr temp))
    (if (tblsearch "LAYER" laynam1)
    (progn
    (if (< 0 layval2)(command "-layer" "off" laynam1 "")(command
    "-layer" "on" laynam1 ""))
    (if (logand layval1 1)(command "-layer" "f" laynam1 "")(command
    "-layer" "t" laynam1 ""))
    (if (logand layval1 4)(command "-layer" "lo" laynam1 "")(command
    "-layer" "u" laynam1 ""))
    )
    )
    )
    )



    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
     
    Jamie Duncan, Jul 30, 2003
    #1
  2. Jamie Duncan

    Bob Basques Guest

    try this:

    (defun c:Restorealllayers (/ temp layval1 laynam1 layval2)
    (foreach temp Savethelayers
    (setq laynam1 (car temp)
    layval1 (cadr temp)
    layval2 (caddr temp))
    (if (tblsearch "LAYER" laynam1)
    (progn
    (if (< 0 layval2)
    (command "_-layer" "on" laynam1 "")
    (command "_-layer" "off" laynam1 ""))
    (if (logand layval1 1)
    (command "_-layer" "t" laynam1 "")
    (command "_-layer" "f" laynam1 ""))
    (if (logand layval1 4)
    (command "_-layer" "u" laynam1 "")
    (command "_-layer" "lo" laynam1 ""))
    )
    )
    )
    )

    I think you had the condition backwards, the above wored for me.

    bobb
     
    Bob Basques, Jul 30, 2003
    #2
  3. Jamie Duncan

    Bob Basques Guest

    Whoops, I sent it too soon. Doesn't owrk in some instances. . . . .

    bobb
     
    Bob Basques, Jul 30, 2003
    #3
  4. Jamie Duncan

    Jamie Duncan Guest

    Hey Luis! Mon amour Espagnol!

    I truly don't understand vlisp! (it's a birth defect)
    I'm not sure why my function doesn't work. Can you 'splain why?
    (still angry that entmod doesn't work on "layers" or ignores code 70)

    Jamie
     
    Jamie Duncan, Jul 31, 2003
    #4
  5. Jamie Duncan

    Jamie Duncan Guest

    k' like i'm confused. Why doesn't this work?

    I thinks it's a variable thing!

    Like for some reason it doesn't recognize caddr temp as an integer?

    Why oh why?

    I could solve it another way, but this started out so elegant!

    GRRRRRRRR! Lisp!


    Jamie
     
    Jamie Duncan, Jul 31, 2003
    #5
  6. Jamie Duncan

    James Buzbee Guest

    Jamie,
    The functions Luis posted are the way to go. Take a look at a thread titled
    "Layer States w\ F keys". I posted a similar set of functions as Luis with
    an example at the end. Here are some way's to use Luis' functions:

    To save the current Layer State
    (set-layerstate "MyLayerState" acLsAll) ;where acLsAll will save all the
    Layers properties; On Freeze Color etc.

    To restore a saved Layer State
    (if (member "MyLayerState"(get-statenames))(restore-layerstate
    "MyLayerState"))

    HTH

    jb
     
    James Buzbee, Jul 31, 2003
    #6
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.