chelsea1307 Posted May 29, 2009 Posted May 29, 2009 i posted my code below. Is there a way to make it go back to the original snap settings with the function is finished. (defun c:FU-CW () (setvar "cmdecho" 0) (command "layer" "M" "FU-CW" "C" "7" "" "") (setvar "osmode" 512) (setq pnt1 (getpoint "\nPick point 1")) (setq a (getangle "\nAngle?:" PNT1))(terpri) (setq ang ( * a 57.3)) (SETQ num1 (GETREAL "\ N ENTER first number")) (SETQ num2 (GETREAL "\ N ENTER second number")) (setq val (+ num1 num2)) (setq CW (rtos VAL 2 0)) (command "text" "JUSTIFY" "MIDDLE" pnt1 ANG CW) (command "units" "4" "64" "1" "" "" "") ) Quote
ronjonp Posted May 29, 2009 Posted May 29, 2009 Give this a try: (defun c:fu-cw (/ a ang cw num1 num2 pnt1 val os);;localized variables (setq os(getvar 'osmode));;Get the current OSMODE (setvar "cmdecho" 0) (command "layer" "M" "FU-CW" "C" "7" "" "") (setvar "osmode" 512) (setq pnt1 (getpoint "\nPick point 1")) (setq a (getangle "\nAngle?:" pnt1)) (terpri) (setq ang (* a 57.3)) (setq num1 (getreal "\ N ENTER first number")) (setq num2 (getreal "\ N ENTER second number")) (setq val (+ num1 num2)) (setq cw (rtos val 2 0)) (command "text" "JUSTIFY" "MIDDLE" pnt1 ang cw) (command "units" "4" "64" "1" "" "" "") (setvar 'osmode os);;Reset the osmode *will not get reset if routine crashes or user presses ESC ) Quote
Lee Mac Posted May 29, 2009 Posted May 29, 2009 The easiest way: (defun c:FU-CW (/ oldcmd oldos pnt1 a ang num1 num2 val cw) (setq oldcmd (getvar "CMDECHO") oldos (getvar "OSMODE")) (setvar "cmdecho" 0) (command "layer" "M" "FU-CW" "C" "7" "" "") (setvar "osmode" 512) (setq pnt1 (getpoint "\nPick point 1")) (setq a (getangle "\nAngle?:" PNT1)) (terpri) (setq ang (* a 57.3)) (SETQ num1 (GETREAL "\ N ENTER first number")) (SETQ num2 (GETREAL "\ N ENTER second number")) (setq val (+ num1 num2)) (setq CW (rtos VAL 2 0)) (command "text" "JUSTIFY" "MIDDLE" pnt1 ANG CW) (command "units" "4" "64" "1" "" "" "") (setvar "CMDECHO" oldcmd) (setvar "OSMODE" oldos) (princ)) Pretty much what Ron did though Quote
Lee Mac Posted May 29, 2009 Posted May 29, 2009 For added security, you could also add an Error Handler, so that the OSNAPS and CMDECHO will be reset if the user hits Esc through the routine: (defun c:FU-CW (/ [color=Red][b]*error vlst ovar pnt1 a ang num1 num2 val cw[/b][/color]) [b][color=Red] (defun *error* (msg) (if ovar (mapcar 'setvar vlst ovar)) (princ))[/color][/b] [b][color=Red](setq vlst '("CMDECHO" "OSMODE") ovar (mapcar 'getvar vlst)) (mapcar 'setvar vlst '(0 512))[/color][/b] (setvar "cmdecho" 0) (command "layer" "M" "FU-CW" "C" "7" "" "") (setvar "osmode" 512) (setq pnt1 (getpoint "\nPick point 1")) (setq a (getangle "\nAngle?:" PNT1)) (terpri) (setq ang (* a 57.3)) (SETQ num1 (GETREAL "\ N ENTER first number")) (SETQ num2 (GETREAL "\ N ENTER second number")) (setq val (+ num1 num2)) (setq CW (rtos VAL 2 0)) (command "text" "JUSTIFY" "MIDDLE" pnt1 ANG CW) (command "units" "4" "64" "1" "" "" "") [color=Red][b] (mapcar 'setvar vlst ovar)[/b][/color] (princ)) Also, remember to localise your variables! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.