Jump to content

Recommended Posts

Posted

1.) Is this a typical error function ?

2.) How this works? (when there is error on my code, this will break the program correct)

(defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (prompt (strcat "\nError: " errmsg))
    ); if

3.) Can i add this to my lisps, if required when it's required to update further . . . 

Posted (edited)

1. Yes

2. If the error contains any of the following in the wcwatch it will not display the error message that is all.  if its a different error it will display that error.

    The lisp has already stopped due to the error.

 

Example:

type ZE command

Autocad zoom extents and waits for object selection.

*hit esc key*

error: Function Cancled

 

3. Yes just add it before or after your code. more details here

                                                                                                or here

 

 

This is my zoom Extents macro it has a second "command" to zoom to object if i select anything but usually just hit esc and dont want to see an error when i do.

;;------------------------------------------------------------------------------------------------------------;;
;; Zoom Extents Then Zoom to object if needed
(defun C:ZE (/ SS *error*)
  (defun *error* (errmsg)
    (if (not (member errmsg '( "Console Break" "Function cancelled")))
      (princ (strcat "\nError: " errmsg))
    )
  )
  (vl-cmdf "_.Zoom" "E")
  (if (setq SS (ssget))
    (progn
      (vl-cmdf "_.Zoom" "OB" SS "")
      (vl-cmdf "_.Zoom" "0.95x")
    )
  )
)

 

Edited by mhupp
  • Like 1
Posted

A minor point, but always be sure to declare the redefined *error* symbol as local to the function (i.e. within the list of local arguments & variables), so that the scope of the redefinition is limited to the function in which it is redefined; without this declaration, you are redefining the error function globally and therefore affecting all other AutoLISP functions defined within the active document namespace.

  • Like 1
Posted

updated the code to reflect what you said.

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...