Jump to content

Error message when trying to load up a *error* function lisp routine


Lee Chu Chu

Recommended Posts

I have been getting this error in autocad 2015 but not in 2014 for some reason.

 

Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).

Converting (command) calls to (command-s) is recommended.

 

Can anybody please help me understand what this means? I have been using this code from Afralisp

 

(defun c:drawline ()					;define function
(initerr)					;intit error
(setvar "cmdecho" 0)				;reset variables
(setvar "osmode" 32)
(command "undo" "m")				;set mark
(setq pt1 (getpoint "\nPick First Point: "))	;get points
(setq pt2 (getpoint pt1 "\nPick Second Point: "))
(command "LAYER" "M" "2" "")			;change layer
(command "Line" pt1 pt2 "")			;draw line
(setq pt3 (getpoint pt2 "\nPick Third Point: "));get 3rd point
(setvar "osmode" 0)				;reset snap
(command "Line" pt2 pt3 "")			;draw line
(reset)						;reset variables
  (princ)
)

(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 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" 1)
 (setvar "menuecho" 0)
 (setvar "highlight" 1)
 (setvar "osmode" oldsnap)
 (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" 1)
 (setvar "menuecho" 0)
 (setvar "highlight" 1)
 (setvar "osmode" oldsnap)
 (setvar "pickbox" oldpick)
 (princ)
);defun

 

You can find the code here: http://www.afralisp.net/autolisp/tutorials/error-trapping.php

Link to comment
Share on other sites

Please try to replace this part

(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

with:

(defun trap (errmsg)     ;define trap
 ([color=magenta]command-s[/color])
 (if (not (member errmsg '("console break" "Function Cancelled"))
     )
   (princ (strcat "\nError: " errmsg))   ;print message
 )                 
 ([color=magenta]command-s[/color] "undo" "b")     ;undo back

Is recomended to use said function in error traps and seems that AutoCAD 2015 is enforcing stronger this rule; from help:

The command-s function is a variation of the command function which has some restrictions on command token content, but is both faster than command and can be used in *error* handlers due to internal logic differences.
Link to comment
Share on other sites

Thanks that seemed to do the trick. I have another question if you dont mind. I am using this as a test so make sure that you are aware that if this works on this particular function, it should work for the rest of my functions. I can't seem to get the error trapping to work. Could you please help me out?

(defun c: trec()
 (initerr)
 (setvar "clayer" "text_25")
 (setvar "osmode" 2)
 (command "undo" "m")
 (command "rectang")
 (reset)

 (princ)
);defun

 

For some reason, when this function is called up, the variables dont get set so it the original settings before this command is called up is still there. Could you please help me figure out why the clayer and osmode doesnt get set for this?

Link to comment
Share on other sites

The RESET function isn't reached due to the way you called the command. This will ensure that AutoLISP is resumed:

...
(command "[color=red]_[/color]rectang")
[color=red] (while (> (getvar "CMDACTIVE") 0)[/color]
[color=red]  (command pause)[/color]
[color=red] )[/color]
(reset)
)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...