Code Red > AutoLISP (Vanilla / Visual)

Keep osmode settings on the fly while setting them for specific routine?

<< < (2/3) > >>

KewlToyZ:
If I hit escape during during these commands in 2008 I lose my snap settings still.
But I can't seem to find the right time to fire the return in the error condition.
Any advice?

My Command prompt just follows through the function cancelled error.
Command: (smartinsert 0 129 "clayer" "plumbing/kta_ppi003")
Pick insertion point...

Pick Insertion Point on Line or Arc:
Pick Insertion Point on Line or Arc:*Cancel*
; error: Function cancelled



--- Code: ---;;  Error condition for exit to restore osnaps -------------------------------------------------------------------------------
  (DEFUN *error* (errormessage /)
      (COND ((NOT errormessage))                              ; no error, do nothing       
            ((VL-POSITION (STRCASE errormessage T)            ; cancel
                          '("console break"
                            "function cancelled"
                            "quit / exit abort"
                           )                           
             )
            )
            (setvar "osmode" usersnaps)
            (princ "\n Osnaps returned.") ; return osnaps
            ((PRINC (STRCAT "\nApplication Error: "
                            (GETVAR "errno")
                            " :- "
                            errormessage
                    )                 
             )
            )
      )
      (setvar "osmode" usersnaps)
      (princ "\n Osnaps returned.")
  )
;  Error condition for exit to restore osnaps -------------------------------------------------------------------------------




(defun insertandbreakline (/ line lineName p1 brkPt1 brkPt2 insAngle ls le *error*)
 
  (setq usersnaps (getvar "osmode"));-------------------Get user osmode settings
  (setvar "osmode" 512)
  (setq p1 (getpoint "\nPick insertion point:"))
  (setvar "osmode" 0)
  (setq line (nentselp p1))
  (setq linName (car line))
  (setq ls (cdr (assoc 10 (entget linName))))
  (setq le (cdr (assoc 11 (entget linName))))
  (setq insAngle (angle ls le))
  (setq brkPt1 (polar p1 insAngle breakDist))
  (setq brkPt2 (polar p1 (+ insAngle pi) breakDist))
  (if (and (> insAngle (/ pi 2)) (<= insAngle (/ (* pi 3) 2)))
    (setq insAngle (- insAngle pi))
  )
  (setq insAngle (/ (* insAngle 180) pi))
  (setq sc (getvar "dimscale"))
  (command "insert" blk p1 sc "" insAngle)
  (command "break" linName brkPt1 brkPt2)
)

(defun insertatend (/ pt1 ent pt2 pt3 *error*)
 
 (setq usersnaps (getvar "osmode"));-------------------Get user osmode settings
  (setvar "osmode" 0)

  (while (null
   ;(setvar "osmode" usersnaps)
   ;(princ "\n Osnaps returned.")
;  Error condition for exit to restore osnaps -------------------------------------------------------------------------------
   (setq ent (entsel "\nPick Insertion Point on Line or Arc:"))
   ;(setvar "osmode" usersnaps)
;(princ "\n Osnaps returned.")
)
(setvar "osmode" usersnaps)
(princ "\n Osnaps returned.")
    (princ "\nSelect (Line, Polyline, Arc, Circle) or Press ESC to EXIT:")
  )
  (setq pt1 (cadr ent))
  (setq pt2 (osnap pt1 "end"))
  (setq pt3 (osnap pt1 "nea"))
  (setq sc (getvar "dimscale"))
  (command "insert" blk pt2 sc sc pt3)

  (insertatend)
)

(defun insertonline (/ line lineName p1 insAngle ls le *error*)

  (setq usersnaps (getvar "osmode"));-------------------Get user osmode settings
  (setvar "osmode" 512)
  (setq p1 (getpoint "\nPick insertion point:"))
  (setvar "osmode" 0)
  (setq line (nentselp p1))
  (setq linName (car line))
  (setq ls (cdr (assoc 10 (entget linName))))
  (setq le (cdr (assoc 11 (entget linName))))
  (setq insAngle (angle ls le))
  (if (and (> insAngle (/ pi 2)) (<= insAngle (/ (* pi 3) 2)))
    (setq insAngle (- insAngle pi))
  )
  (setq insAngle (/ (* insAngle 180) pi))
  (setq sc (getvar "dimscale"))
  (command "insert" blk p1 sc "" insAngle)
)

--- End code ---

ronjonp:
You could use lisp reactors to reset predefined variables in a list when the lisp is cancelled:


--- Code: ---(if (not *rjp-lispReactors*)
  (setq *rjp-lispReactors*
(vlr-lisp-reactor
   nil
   '((:vlr-lispWillStart . strtlsp)
     (:vlr-lispCancelled . cncllsp)
    )
)
  )
  (princ)
)
(defun strtlsp (calling-reactor strtlspInfo / stlisp)
  (setq stlisp     (strcase (nth 0 strtlspInfo) T)
rjp-varlist nil
rjp-varlist (mapcar '(lambda (x) (cons x (getvar x)))
    '("apbox"      "aperture"
      "attdia"      "attmode"
      "aunits"      "autosnap"
      "blipmode"     "cecolor"
      "celtscale"    "clayer"
      "cmddia"      "cmdecho"
      "dimassoc"     "dragmode"
      "edgemode"     "elevation"
      "expert"      "fillmode"
      "gridmode"     "gripsize"
      "highlight"    "ltscale"
      "orthomode"    "osmode"
      "osnapcoord"   "plinewid"
      "snapang"      "snapmode"
      "textsize"
     )
    )
  )
  (princ)
)
(defun cncllsp (calling-reactor cncllspInfo /)
  (mapcar '(lambda (x)
     (vl-catch-all-apply
       'setvar
       (list (car x) (cdr x))
     )
   )
  rjp-varlist
  )
  (princ "\n <<Lisp cancelled...>>")
)
--- End code ---

Sdoman:
Hey, that's an interesting approach Ronjonp. I am thinking maybe it could be improved slightly by adding a check in the callback function to see if the lisp that just ended completed without error. The lisp that ended could set a global variable like *LispEnded* or whatever.

ronjonp:

--- Quote from: 'steved on June 28, 2007, 03:32:21 PM ---Hey, that's an interesting approach Ronjonp. I am thinking maybe it could be improved slightly by adding a check in the callback function to see if the lisp that just ended completed without error. The lisp that ended could set a global variable like *LispEnded* or whatever.

--- End quote ---

Steve,

I'm not quite sure how to do this.... I have and endlisp reactor running as well (on my full version)....what differentiates (defines) a lisp that ended without errors and one that errors out?

Thanks,

Ron

CAB:
You can have the lisp set the osmode global var to nil upon normal completion.
Else it will have a value to restore the osmode to.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version