Author Topic: Osmode question  (Read 3603 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Osmode question
« on: March 31, 2005, 04:56:45 AM »
In the following lisp no matter what I do when I escape the routine I can't get the osmode to revert to what it was originally.

anyone have any Ideas where I'm going wrong?
Code: [Select]

;;;Degrees to Radians function
(defun dtr (a)
   (* pi (/ a 180.0))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;main circuit routine;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:circ ()
  (setq osm (getvar "osmode")
cmd (getvar "cmdecho"))
  (setvar "osmode" 18)
  (setvar "cmdecho" 0)
  (setq pt1 (getpoint "\nSelect First Symbol: ")
pt2 (getpoint "\nSelect next Symbol: ")
ANG (ANGLE PT1 PT2)
PT3 (POLAR PT1 (+ ANG (DTR 45)) 275)
PT4 (POLAR PT2 (+ ANG (DTR 135)) 275)
)
  ;;;DRAW CIRCUIT LINE
  (setvar "osmode" 0)
  (COMMAND "PLINE" PT1 PT3 PT4 PT2 "")
  ;;;move onto next circuit line
  (while
  (setq pt1 pt2)
  (setq pt2 nil)
  (setq pt3 nil)
  (setq pt4 nil)
  (setq ang nil)
  (setvar "osmode" 18)
  (setq pt2 (getpoint "\nSelect Next symbol: ")
ANG (ANGLE PT1 PT2)
PT3 (POLAR PT1 (+ ANG (DTR 45)) 275)
PT4 (POLAR PT2 (+ ANG (DTR 135)) 275)
)
  (setvar "osmode" 0)
  (COMMAND "PLINE" PT1 PT3 PT4 PT2 "")
(SETVAR "OSMODE" OSM)
(SETVAR "CMDECHO" CMD)
  )
  (princ)
  )
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

daron

  • Guest
Osmode question
« Reply #1 on: March 31, 2005, 07:26:46 AM »
Code: [Select]
(defun c:circ ()
     (setq osm (getvar "osmode")
  cmd (getvar "cmdecho")
     )
     (setvar "osmode" 18)
     (setvar "cmdecho" 0)
     (setq pt1 (getpoint "\nSelect First Symbol: ")
  pt2 (getpoint "\nSelect next Symbol: ")
  ANG (ANGLE PT1 PT2)
  PT3 (POLAR PT1 (+ ANG (DTR 45)) 275)
  PT4 (POLAR PT2 (+ ANG (DTR 135)) 275)
     )
;;;DRAW CIRCUIT LINE
     (setvar "osmode" 0)
     (COMMAND "PLINE" PT1 PT3 PT4 PT2 "")
;;;move onto next circuit line
     (while
 (setq pt1 pt2)
     (setq pt2 nil
   pt3 nil
   pt4 nil
   ang nil)
     (setvar "osmode" 18)
     (setq pt2 (getpoint "\nSelect Next symbol: ")
   ANG (ANGLE PT1 PT2)
   PT3 (POLAR PT1 (+ ANG (DTR 45)) 275)
   PT4 (POLAR PT2 (+ ANG (DTR 135)) 275)
     )
     (setvar "osmode" 0)
     (COMMAND "PLINE" PT1 PT3 PT4 PT2 "")
     )
     (SETVAR "OSMODE" OSM)
     (SETVAR "CMDECHO" CMD)
     (princ)
)


See if that'll work.

hudster

  • Gator
  • Posts: 2848
Osmode question
« Reply #2 on: March 31, 2005, 08:12:24 AM »
nope, when I hit escape during the routine the osmode stays at 18.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Osmode question
« Reply #3 on: March 31, 2005, 08:20:06 AM »
I just woke up but ...

Code: [Select]
(defun c:circ ( / *error* osm cmd )
   
    (defun *error* ( msg )
        (setvar "osmode" osm)
        (setvar "cmdecho" osm)
        (princ)
    )
   
    (setq
        osm (getvar "osmode")
        cmd (getvar "cmdecho")
    )
   
    ...
   
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hudster

  • Gator
  • Posts: 2848
Osmode question
« Reply #4 on: March 31, 2005, 08:24:07 AM »
:oops: OK got it, I had tried the error checking/console break routine from afralisp but I fogot to add the lines
Code: [Select]
(initerr) ;intit error
and
Code: [Select]
(reset)                  ;reset variables




Code: [Select]
;;;
;;error checker from www.afralisp.com
;;;
(defun error () ;load function
  (prompt "\nGlobal Error Trap Loaded") ;inform user
  (princ)
) ;defun
;;;*==========================================================
(defun initerr () ;init error
  (setq oldlayer (getvar "clayer")) ;save settings
  (setq oldsnap (getvar "osmode"))
  (setq oldpick (getvar "pickbox"))
  (setq blip (getvar "blipmode"))
  (setq temperr *error*) ;save *error*
  (setq *error* trap) ;reassign *error*
  (princ)
) ;defun
;;;*===========================================================
(defun trap (errmsg) ;define trap
  (command nil nil nil)
  (if (not (member errmsg '("console break" "Function Cancelled"))
      )
    (princ (strcat "\nError: " errmsg)) ;print message
  )
  (command "undo" "b") ;undo back
  (setvar "clayer" oldlayer) ;reset settings
  (setvar "blipmode" blip)
  (setvar "menuecho" 0)
  (setvar "highlight" 1)
  (setvar "osmode" osm)
  (setvar "pickbox" oldpick)
  (princ "\nError Resetting Enviroment ") ;inform user
  (terpri)
  (setq *error* temperr) ;restore *error*
  (princ)
) ;defun
;;;*===========================================================
(defun reset () ;define reset
  (setq *error* temperr) ;restore *error*
  (setvar "clayer" oldlayer) ;reset settings
  (setvar "blipmode" blip)
  (setvar "menuecho" 0)
  (setvar "highlight" 1)
  (setvar "osmode" osm)
  (setvar "pickbox" oldpick)
  (princ)
) ;defun
;;;*======================================================
(princ)
;;;
;;;Degrees to Radians function
(defun dtr (a)
   (* pi (/ a 180.0))
)
;;;
(defun c:circ ()
     (setq osm (getvar "osmode")
      cmd (getvar "cmdecho")
     )
(initerr) ;intit error
(command "undo" "m") ;set undo mark
     (setvar "osmode" 18)
     (setvar "cmdecho" 0)
     (setq pt1 (getpoint "\nSelect First Symbol: ")
      pt2 (getpoint "\nSelect next Symbol: ")
      ANG (ANGLE PT1 PT2)
      PT3 (POLAR PT1 (+ ANG (DTR 45)) 275)
      PT4 (POLAR PT2 (+ ANG (DTR 135)) 275)
     )
;;;DRAW CIRCUIT LINE
     (setvar "osmode" 0)
     (COMMAND "PLINE" PT1 PT3 PT4 PT2 "")
;;;move onto next circuit line
     (while
     (setq pt1 pt2)
         (setq pt2 nil
          pt3 nil
          pt4 nil
          ang nil)
         (setvar "osmode" 18)
         (setq pt2   (getpoint "\nSelect Next symbol: ")
          ANG   (ANGLE PT1 PT2)
          PT3   (POLAR PT1 (+ ANG (DTR 45)) 275)
          PT4   (POLAR PT2 (+ ANG (DTR 135)) 275)
         )
         (setvar "osmode" 0)
         (COMMAND "PLINE" PT1 PT3 PT4 PT2 "")
     )
(reset) ;reset variables
     (princ)
)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

daron

  • Guest
Osmode question
« Reply #5 on: March 31, 2005, 08:44:12 AM »
Of course, you never said anything about "USER ERROR" in your initial post. I found that as I ran your routine, it didn't reset my snaps from exiting the while loop properly. That is why I moved it out.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Osmode question
« Reply #6 on: March 31, 2005, 09:10:26 AM »
FYI, if you ever hit the escape key while in a lisp program, AutoCAD WILL generate an error, to handle that error you should define an error handler for your lisp program. It can be simple or complex ... but you must have one if you are going to ever hit the escape key while in a lisp program.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
Osmode question
« Reply #7 on: March 31, 2005, 09:18:29 AM »
I assume you're telling the Hudster that. I do know what you speak of. It's just that "user error" wasn't the impression I got from the initial post