Save and restore VAR

Discussion in 'AutoCAD' started by KirkONE, Feb 1, 2005.

  1. KirkONE

    KirkONE Guest

    Hi everybody,
    sorry for my poor english, i can write this better in italian!

    So, i wold like to change the current color ad layer, draw a mline trugh
    drawing adn when finishing restore the previous state of layer and colour.
    I write this code, but i don't know how is it possible to invoke restore
    routine after mline command.

    Thanks to all, very fine NG

    Diego.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;SOC

    (defun restore()
    (setvar "cecolor" oldcol)
    (setvar "clayer" oldlay)
    )
    (defun save()
    (setq oldcol (getvar "cecolor")) ;; save current color
    (setq oldlay (getvar "clayer")) ;; save current layer
    )
    (defun C:mpele (/)
    (save)
    (setvar "cecolor" "bylayer")
    (setvar "clayer" "PASSERELLE ELE")
    (command "mline" "j" "zero")
    (restore)
    )
    ;;;EOC
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
    KirkONE, Feb 1, 2005
    #1
  2. KirkONE

    Adesu Guest

    Hi KirkONE,try this
    (defun restore()
    (setvar "cecolor" oldcol)
    (setvar "clayer" oldlay)
    )
    (defun save()
    (setq oldcol (getvar "cecolor")) ;; save current color
    (setq oldlay (getvar "clayer")) ;; save current layer
    )
    (defun C:mpele (/ nlayer pt1 pt2)
    (save)
    (setvar "cecolor" "bylayer")
    ;(setvar "clayer" "PASSERELLE ELE")
    (setq nlayer "PASSERELLE ELE")
    (if (not (tblsearch "layer" nlayer))
    (command "layer" "n" nlayer "")
    (princ "That layer already exists.")
    )
    (setq pt1 (getpoint "\nCLICK LOCATION FOR FIRST OBJECT: "))
    (setq pt2 (getpoint "\nCLICK LOCATION FOR SECOND OBJECT: "))
    (command "mline" pt1 pt2 "")
    (restore)
    )
     
    Adesu, Feb 1, 2005
    #2
  3. KirkONE

    KirkONE Guest

    OK, i think this work fine but i must draw a Mline with very lot of
    point, and not ever the same number of it.
     
    KirkONE, Feb 1, 2005
    #3
  4. KirkONE

    ECCAD Guest

    Try this model..

    (defun restore()
    (setvar "cecolor" oldcol)
    (setvar "clayer" oldlay)
    )
    (defun save_lay ()
    (setq oldcol (getvar "cecolor")) ;; save current color
    (setq oldlay (getvar "clayer")) ;; save current layer
    )
    (defun C:mpele (/)
    (save_lay)
    (setvar "cecolor" "bylayer")
    (setq nlayer "PASSERELLE ELE")
    (if (not (tblsearch "layer" nlayer))
    (command "_layer" "m" nlayer "")
    )
    (command "mline" "j" "zero")
    (while (= (logand (getvar "cmdactive") 1) 1)
    (command pause)
    ); while
    (restore)
    )

    Bob
     
    ECCAD, Feb 1, 2005
    #4
  5. KirkONE

    KirkONE Guest

    SIMPLY PERFECT!!!!
    tnx

    diego
     
    KirkONE, Feb 2, 2005
    #5
  6. KirkONE

    ECCAD Guest

    ECCAD, Feb 3, 2005
    #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.