OSNAP problem

Discussion in 'AutoCAD' started by ghiggins457, Apr 16, 2004.

  1. ghiggins457

    ghiggins457 Guest

    I have written some lisp routines that require the OSNAP to be set to certain things during the middle of the program. The problem is, that after the program is done running, I don't know how to set the OSNAP back to the users original settings before the program. Does anybody know how to do this? Thanks.

    Greg
     
    ghiggins457, Apr 16, 2004
    #1
  2. ghiggins457

    R.K. McSwain Guest

    At the beginning of the routine, retreive and save the value of the system variable OSMODE.
    At the end, set it back.
     
    R.K. McSwain, Apr 16, 2004
    #2
  3. The OSMODE system variable stores the settings. Put this in at the
    beginning:

    (setq osnapsettings (getvar "OSMODE"))

    then do whatever you want with the settings in the routine, then put this in
    at the end:

    (setvar "OSMODE" osnapsettings)

    Kent Cooper, AIA

    certain things during the middle of the program. The problem is, that after
    the program is done running, I don't know how to set the OSNAP back to the
    users original settings before the program. Does anybody know how to do
    this? Thanks.
     
    Kent Cooper, AIA, Apr 16, 2004
    #3
  4. ghiggins457

    OLD-CADaver Guest

    load these in your acad.lsp or acad2000doc.lsp

    (defun osmget () (setq osget nil)(setq osget (getvar "osmode"))(setvar "osmode" 0))

    (defun osmret () (setvar "osmode" osget))

    Then add (osmget) at the start of your routine and (osmret) at the end
     
    OLD-CADaver, Apr 16, 2004
    #4
  5. ghiggins457

    Jamie Duncan Guest

    here is one you might like:
    works for all sysvars that aren't point based.

    (maybe someone can give me an idea?)

    Like OLD-C said, add these to the files he mentioneed and:


    (defun arctsetvar ( arctvar1 arctval1 /) ;;; reset a var in a routine
    (if (not (assoc arctvar1 ARCTACADVAR))
    (setq ARCTACADVAR (cons (cons arctvar1 arctval1) ARCTACADVAR))
    (setq ARCTACADVAR (subst (cons arctvar1 arctval1)(assoc arctvar1
    ARCTACADVAR) ARCTACADVAR))
    )
    )
    (defun arctgetvar ( arctvar1 /);;; get one var
    (if (not (assoc arctvar1 ARCTACADVAR))
    (getvar arctvar1)
    (cdr (assoc arctvar1 ARCTACADVAR))
    )
    )
    (defun arctvsav (/ ev1);;; save sysvars - lisp starting function
    (if (not ARCTACADVAR)
    (setq ARCTACADVAR (list (cons "aperture" (getvar "aperture"))(cons
    "blipmode" (getvar "blipmode"))
    (cons "cmdecho" (getvar "cmdecho"))(cons "cecolor" (getvar
    "cecolor"))(cons "highlight" (getvar "highlight"))
    (cons "clayer" (getvar "clayer"))(cons "orthomode" (getvar
    "orthomode"))(cons "osmode" (getvar "osmode"))
    (cons "pickbox" (getvar "pickbox"))(cons "snapang" (getvar
    "snapang"))(cons "plinewid" (getvar "plinewid"))
    (cons "expert" (getvar "expert"))(cons "ctab" (getvar
    "ctab"))(cons "cvport" (getvar "cvport"))(cons "attmode" (getvar "attmode"))
    (cons "attreq" (getvar "attreq"))(cons "attdia" (getvar
    "attdia"))(cons "filedia" (getvar "filedia"))(cons "texteval" (getvar
    "texteval"))
    (cons "snapmode" (getvar "snapmode))(cons "textstyle" (getvar
    "textstyle"))
    (cons "dimtxt" (getvar "dimtxt"))(cons "angbase" (getvar
    "angbase"))(cons "cmddia" (getvar "cmddia"))(cons "hpname" (getvar
    "hpname"))
    (cons "hpang" (getvar "hpang"))(cons "hpscale" (getvar
    "hpscale"))
    ))
    (foreach ev1 ARCTACADVAR (setq ARCTACADVAR (subst (cons (car ev1)
    (getvar (car ev1)))(assoc (car ev1) ARCTACADVAR) ARCTACADVAR)))
    )
    (setvar "cmdecho" 0)(if (< (getvar "osmode") 16384)(setvar "osmode" (+
    (getvar "osmode") 16384)))(setvar "blipmode" 0);;;this sets it to 0
    (command ".undo" "Begin")(graphscr);;;this sets up your undo
    )
    (defun arctvrst (/ ev1) ;;;restore sysvars - lisp ending function
    (command ".undo" "end");;;end undo bit
    (foreach ev1 ARCTACADVAR (setvar (car ev1) (cdr ev1))
    )
    (princ)
    )



    so at the start of any routine (arctvsav) which will save a whole slew of
    settings, set up the undo, and set osmode to off.
    at the end (arctvrst) will restore everything.


    there.


    --
    Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)












    certain things during the middle of the program. The problem is, that after
    the program is done running, I don't know how to set the OSNAP back to the
    users original settings before the program. Does anybody know how to do
    this? Thanks.
     
    Jamie Duncan, Apr 16, 2004
    #5
  6. I played with this a little. Wouldn't this be a little more readable?

    (defun arctvsav ()
    ;;; save sysvars - lisp starting function
    (setq ARCTACADVAR
    (mapcar (function (lambda (key) (cons key (getvar key))))
    '("aperture" "blipmode" "cmdecho" "cecolor"
    "highlight" "clayer" "orthomode" "osmode"
    "pickbox" "snapang" "snapang" "plinewid"
    "expert" "ctab" "cvport" "attmode" "attreq"
    "attdia" "filedia" "texteval" "snapmode"
    "textstyle" "dimtxt" "angbase" "cmddia"
    "hpname" "hpang" "hpscale" )))
    (setvar "cmdecho" 0)
    (if (< (getvar "osmode") 16384)
    (setvar "osmode"
    (+ (getvar "osmode") 16384)))
    (setvar "blipmode" 0);;;this sets it to 0
    (command ".undo" "Begin")(graphscr);;;this sets up your undo
    )

    --
     
    Martti Halminen, Apr 22, 2004
    #6
  7. ghiggins457

    Jamie Duncan Guest

    Beautiful.

    Thanks


    Another needed lesson in mapcar & lambda



    --
    Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)
     
    Jamie Duncan, Apr 24, 2004
    #7
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.