Author Topic: Civil 3D 2014 Canceling a routine undoes.......Everything!  (Read 1801 times)

0 Members and 1 Guest are viewing this topic.

jmcshane

  • Newt
  • Posts: 83
Civil 3D 2014 Canceling a routine undoes.......Everything!
« on: October 16, 2014, 07:22:48 AM »
Hi,
Would anybody know why, when I cancel a routine, it undoes the whole drawing back to its original state?
I think this started happening after loading Civil 3D 2014, and I think I got around it, but after loading the last service pack the problem seems to have reared its head again.
I have been using these routines for years without any problems but this has got me very concerned as I have lost hours of work lately because of it, and its happening other users on the network as well.

Any help would be appreciated.

John
John.

Civil 3D 2021. Windows 10

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Civil 3D 2014 Canceling a routine undoes.......Everything!
« Reply #1 on: October 16, 2014, 07:59:15 AM »
I had this problem in LDD 2008. I ended up finding an issue with an errror handler in a routine I'd been using since the early 2000s.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ChrisCarlson

  • Guest
Re: Civil 3D 2014 Canceling a routine undoes.......Everything!
« Reply #2 on: October 16, 2014, 08:45:57 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun *error* (msg)
  2.   (and msg
  3.        (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*"))
  4.        (princ (strcat "\nError: " msg))
  5.   )
  6. )      


Try this snippet. I had a similar issue

jmcshane

  • Newt
  • Posts: 83
Re: Civil 3D 2014 Canceling a routine undoes.......Everything!
« Reply #3 on: October 21, 2014, 07:57:02 AM »
Thanks guys, snowed under here at the minute so please forgive my late replies.

I have to admit that error trapping is my Achilles heal, and what i have been using for years is what I have taken from AfraLisp.

This is what we use:
Code: [Select]
;;;Error Trap
(defun error ()
  (prompt "\Global Error Trap Loaded.")
  (princ)
  ) ;_ end of defun

;;********************************************************************************************

(defun NODiniterr ()
  (setq OldLayer (getvar "clayer")
OldLineType (getvar "celtype")
OldLineWeight (getvar "celweight")
OldColor (getvar "cecolor")
OldSnap (getvar "osmode")
OldEcho (getvar "cmdecho")
OldAtt (getvar "attreq")
OldText  (getvar "Textstyle")
OldDim  (getvar "Dimstyle")
temperr *error*
*error* NODtrap
) ;_ end of setq
  (princ)
  ) ;_ end of defun

;;********************************************************************************************

(defun NODtrap (errmsg)
  (command nil nil nil)
  (if (not (member errmsg '("console break" "Function Canclled"))
   ) ;_ end of not
    (princ (strcat "\nError : " errmsg))
    ) ;_ end of if
  (command "undo" "b")
  (setvar "clayer" OldLayer)
  (setvar "celtype" OldLineType)
  (setvar "celweight" OldLineWeight)
  (setvar "cecolor" OldColor)
  (setvar "osmode" OldSnap)
  (setvar "attreq" OldAtt)
  (setvar "Textstyle" OldText)
  (vl-cmdf "-Dimstyle" "Restore" OldDim)
  (setvar "cmdecho" OldEcho)
  (princ "\nError - Now Resetting System Environment. ")
  (terpri)
  (setq *error* temperr)
  (princ)
  ) ;_ end of defun

;;***************************************************************************************

(defun NODreset ()
  (setvar "clayer" OldLayer)
  (setvar "celtype" OldLineType)
  (setvar "celweight" OldLineWeight)
  (setvar "cecolor" OldColor)
  (setvar "osmode" OldSnap)
  (setvar "attreq" OldAtt)
  (setvar "Textstyle" OldText)
  (vl-cmdf "-Dimstyle" "Restore" OldDim)
  (setvar "cmdecho" OldEcho)
  (princ)
  ) ;_ end of defun
(princ)

;;************** Set Default Scale ****************************

(defun DefaultScale ()
  (IF (= DEFSCALE NIL)
    (SETQ DEFSCALE " ")
    ) ;_ end of if
  (prompt "\nEnter Scale Factor  : <")
  (PRINC DEFSCALE)
  (PRINC ">")
  (SETQ SCALE (GETSTRING))
  (IF (= SCALE "")
    (SETQ SCALE DEFSCALE)
    ) ;_ end of if
  (SETQ DEFSCALE SCALE)
  ) ;_ end of defun

This is how we typically use it:
Code: [Select]
(defun c:REVISION (/ InsertPoint)
  (NODiniterr)
  (setvar "CMDECHO" 0)
  (vl-cmdf "_UNDO" "M")
  (vl-cmdf "-layer" "M" "CE-GRPH-MISC" "")
  (DefaultScale)
  (setq InsertPoint (getpoint "\nSelect insertion point : "))
  (vl-cmdf "-insert"
   "V:\\Menu Drawing File\\Revision"
   InsertPoint
   SCALE
   SCALE
   "0"
   ) ;_ end of command
  (NODreset)
  (princ)
  ) ;_ end of defun

And this is typically the command that, when I cancel it causes the undo back to the start of the drawing!
Code: [Select]
(DEFUN C:D ()
(SETVAR "CMDECHO" 0)
(SETQ OS (GETVAR "OSMODE"))
(SETVAR "OSMODE" 37)
(PRINC "\n        **** Direct Distance **** ")
(SETQ 1ST (GETPOINT "\n        First point: "))
(SETQ 2ND (GETPOINT 1ST " ...second point: "))
(SETQ DIST (DISTANCE 1ST 2ND))
(PRINC (STRCAT "--> " (RTOS DIST)))
(SETVAR "OSMODE" OS)
(SETVAR "CMDECHO" 1)
(PRINC)
)

Can anybody (if they have a minute) possibly have a look and see what I am doing wrong?
As I have said, its only really happening in Civil 3D 2014.

ChrisCarlson,
Thanks for the snippet of code, but where and when would I use it?

Thanks for the help.

John
John.

Civil 3D 2021. Windows 10

BlackBox

  • King Gator
  • Posts: 3770
Re: Civil 3D 2014 Canceling a routine undoes.......Everything!
« Reply #4 on: October 21, 2014, 09:27:09 AM »
Forgive me as I've not taken the time to look over your code, but thought to offer my $0.02 on *error* handling.

AutoCAD provides its own *error* function, which we often temporarily overwrite with our own customized *error* handler... It is imperative that the OOTB function be restored when done so as to allow the application to continue to perform normally, otherwise your custom *error* handler is used instead, which at some point will likely cause an issue with application performance.

That said, there are multiple ways of going about a custom *error* handler... You can use multiple, stand-alone Defuns and have your main code store the existing to global variable, and set your custom *error* handler as current, etc.... Or, what I prefer, is to simply include your custom *error* Defun as a local variable to your main code.

Example of the former:

Code - Auto/Visual Lisp: [Select]
  1. (defun *MyError* (msg)
  2.   ;;<-- do something useful
  3.  
  4.   (cond ((not msg))                                                     ; Normal exit
  5.         ((member msg '("Function cancelled" "quit / exit abort")))      ; <esc> or (quit)
  6.         ((princ (strcat "\n** Error: " msg " ** ")))                    ; Fatal error, display it
  7.   )
  8.  
  9.   (setq *error* *OldError*)
  10.  
  11.   (princ)
  12. )
  13.  
  14. (defun c:FOO ()
  15.  
  16.   (setq *OldError* *error*)
  17.   (setq *error* *MyError*)
  18.  
  19.   ;;<-- do something useful
  20.  
  21.   (*error* nil)
  22. )
  23.  



Example of the latter:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:FOO (/ *error*)
  2.  
  3.   (defun *error* (msg)
  4.     ;;<-- do something useful
  5.  
  6.     (cond ((not msg))                                                   ; Normal exit
  7.           ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
  8.           ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
  9.     )
  10.     (princ)
  11.   )
  12.  
  13.   ;;<-- do something useful
  14.  
  15.   (*error* nil)
  16. )
  17.  



HTH
"How we think determines what we do, and what we do determines what we get."