Jump to content

Recommended Posts

Posted

I'm getting this warning when running my script:

 

______________________________

Question

Assignment to protected symbol:

TYPE

Enter break loop?

 

YES/NO

______________________________

 

Can anyone tell me what this means? If I click YES several times the script does carry on through ok, but would rather it didn't do this in the first place....

Posted

Ok - still don't really know what it means or how it came to be interrupting my script, but with the help of Google I have found that changing the general options under environmental options in VLISP from "Prompt to Enter Break Loop" to "transparent" solves the problem. Just for anyone else's reference....

Posted

My guess is that you are trying to use the word "type" as a variable or name of a function. It is a protected name in that it is an AutoLISP function

 

(setq type 123.456)

or

(defun type () my_foo)

Both of which are no nos. -David

Posted
My guess is that you are trying to use the word "type" as a variable or name of a function. It is a protected name in that it is an AutoLISP function

 

Aah! I see. Yes, the LISP that I use at the point where the warning appears does have a variable called 'type' ..... not any more! Thanks :)

Posted

Easily avoided using vlide to type functions - LISP commands are coloured blue instead of black.

Posted

Lee,

 

I'm surprised that you are not getting a similar warning about the way that you are tryng to localize the *error* symbol. I use Ally lisp analyzer and it shows up as a warning. I tried localizing 'type' as a test similar to what Rooster had:

 

ALLY - A Lisp Analyzer (tm) Version 3.0

WARNINGS: 1 reported
 Reserved symbols reset or redefined:
   type 1,3

1  (defun my_test (/ type) 
2  
3    (setq type 123.456) 
4  
5    (prin1))

And then your scenario

ALLY - A Lisp Analyzer (tm) Version 3.0

WARNINGS: 1 reported
 Reserved symbols reset or redefined:
   *error* 1


1  (defun my_test (/ *error*) 
2  
3    (defun *error* (s) 
4           (while (> (getvar "CMDACTIVE") 0) 
5                  (command)) 
6           (prin1 s)) 
7  
8    (prin1)) 

I've seen discussions a long time ago about calling *error* directly, and I think that for the most part, they agreed that it is not intent of *error* to be called directly. When I first saw you use (*error* ""), I thought that you were declaring an error state to exit, but it looks like that you trying use it as a closing statement.

 

Here is the template I use to start a full blown routine

 

* create error trapping

* save the existing settings

* set your modes

* UNDO everything that you have done in an error condition

* resetting all mode to their original state

 

;++++++++++++ Set Modes & Error ++++++++++++++++++++++++++++++++++
(defun nw_smd ()
(SetUndo)
(setq oldlay (getvar "CLAYER")
      olderr *error*
     *error* (lambda (e)
               (while (> (getvar "CMDACTIVE") 0)
                      (command))
               (and (/= e "quit / exit abort")
                    (princ (strcat "\nError: *** " e " *** ")))
               (and (= (logand (getvar "UNDOCTL")  8)
                    (command "_.UNDO" "_END" "_.U"))
               (nw_rmd))
      nw_var '(("CMDECHO"   . 0) ("MENUECHO"   . 0)
               ("MENUCTL"   . 0) ("MACROTRACE" . 0)
               ("OSMODE"    . 0) ("SORTENTS"   . 119)
               ("MODEMACRO" . ".")
               ("LUPREC"    . 2)
               ("BLIPMODE"  . 0) ("EXPERT"     . 0)
               ("SNAPMODE"  . 1) ("PLINEWID"   . 0)
               ("ORTHOMODE" . 1) ("GRIDMODE"   . 0)
               ("ELEVATION" . 0) ("THICKNESS"  . 0)
               ("FILEDIA"   . 0) ("FILLMODE"   . 0)
               ("SPLFRAME"  . 0) ("UNITMODE"   . 0)
               ("TEXTEVAL"  . 0) ("ATTDIA"     . 0)
               ("AFLAGS"    . 0) ("ATTREQ"     . 1)
               ("ATTMODE"   . 1) ("UCSICON"    . 1)
               ("HIGHLIGHT" . 1) ("REGENMODE"  . 1)
               ("COORDS"    . 2) ("DRAGMODE"   . 2)
               ("DIMZIN"    . 1) ("PDMODE"     . 0)
               ("CECOLOR"   . "BYLAYER")
               ("CELTYPE"   . "BYLAYER")))
(foreach v nw_var
  (and (getvar (car v))
       (setq nw_rst (cons (cons (car v) (getvar (car v))) nw_rst))
       (setvar (car v) (cdr v))))
(princ (strcat (getvar "PLATFORM") " Release " (ver)))
(princ))

(PDot);++++++++++++ Return Modes & Error +++++++++++++++++++++++++++++++
(defun nw_rmd ()
 (SetLayer oldlay)
 (setq *error* olderr)
 (foreach v nw_rst (setvar (car v) (cdr v)))
 (command "_.UNDO" "_END")
 (prin1))

(PDot);++++++++++++ Set And Start An Undo Group ++++++++++++++++++++++++
(defun SetUndo ()
(and (zerop (getvar "UNDOCTL"))
     (command "_.UNDO" "_ALL"))
(and (= (logand (getvar "UNDOCTL") 2) 2)
     (command "_.UNDO" "_CONTROL" "_ALL"))
(and (= (logand (getvar "UNDOCTL")  8)
     (command "_.UNDO" "_END"))
(command "_.UNDO" "_GROUP"))

(PDot);++++++++++++ Make Layer Current +++++++++++++++++++++++++++++++++
(defun SetLayer (name / ldef flag)
 (command "_.LAYER")
 (if (not (tblsearch "LAYER" name))
     (command "_Make" name)
     (progn
       (setq ldef (tblsearch "LAYER" name)
             flag (cdr (assoc 70 ldef)))
       (and (= (logand flag  1)  1)
            (command "_Thaw" name))
       (and (minusp (cdr (assoc 62 ldef)))
            (command "_On" name))
       (and (= (logand flag  4)  4)
            (command "_Unlock" name))
       (and (= (logand flag 16) 16)
            (princ "\nCannot Set To XRef Dependent Layer")
            (quit))
       (command "_Set" name)))
 (command "")
 name)

;************ Main Program ***************************************
(defun nw_ (/ olderr oldlay nw_var nw_rst)
 (nw_smd)

 ;;;DO YOUR THING HERE
 
 (nw_rmd)) 

(defun C:NW () (nw_))
(if nw_ (princ "\nNew Loaded\n"))
(prin1)

Some people used to refer to this as a push/pop scenario, I used the set modes and reset modes.

 

*error* itself does not stop the evaluation process. It is there to capture the error message and process the statements in the *error* SUBR, if it has been defined.

 

Regards. -David

Posted

Ahh, thanks David, your help is much appreciated.

 

I used (*error* "") as this was an example that CAB provided on here a while back, so I just got into the habit of using it.

Posted

Did you create that Error trap yourself? It seems extremely advanced!

Posted

Lee,

 

Like most things, it has evolved over the years. I found routines from the early '90s that is very close to what I posted.

 

Some earlier samples:

 

(setq *error* (lambda (s)                      ;Set User Error So That
    (cond ((= s "Function cancelled"))        ;If Cancel Or
          ((= s "quit / exit abort"))         ;Abort Exit Clean
          ((princ (strcat "\nError: " s))))   ;Else Print Error
    (command "UNDO" "END" "U")                ;Undo All Changes
    (fo_rmd)))                                ;Then Return Old Modes

(setq *error* (lambda (e)                      ;Aurgmented Error
    (princ (strcat "\nError: " e "  "))       ;Replacement
    (command "_.UNDO" "_END" "_.U")           ;Undo All Changes
    (ve_rmd)))                                ;Then Return Old Modes

Posted

(setq *error* (lambda (s)                      ;Set User Error So That
    (cond ((= s "Function cancelled"))        ;If Cancel Or
          ((= s "quit / exit abort"))         ;Abort Exit Clean
          ((princ (strcat "\nError: " s))))   ;Else Print Error
    (command "UNDO" "END" "U")                ;Undo All Changes
    (fo_rmd)))                                ;Then Return Old Modes

 

Thanks David,

 

Just one more question and this may be a stupid question - but, where you have used the "cond" statement in the code above, in the conditions:

 

((= s "Function cancelled"))

 

and

 

((= s "quit / exit abort")) 

 

What does the function return in these cases?

 

how I understand it is, if "s" is equal to the statements, "function cancelled" or "quit / exit abort", then do something, but the something doesn't seem to be specified within the condition statement.

 

If that makes any sense whatsoever...

Posted

Lee,

 

A cond test only that returns T by itself does nothing, but does stop the cond testing, so in this case a clean display

 

A bit more verbose would be:

 

((= s "quit / exit abort") nil)

or

((= s "quit / exit abort") (princ))

-David

Posted

Ahh, I understand now.

 

I am not used to using (cond) statements without specifying what to do when a result returns T.

 

This clarifies it.

 

Thanks.

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