Author Topic: New UCS on Cancel  (Read 3182 times)

0 Members and 1 Guest are viewing this topic.

ChrisCarlson

  • Guest
New UCS on Cancel
« on: February 24, 2014, 09:29:28 AM »
*Cancel*
_UCS
Current ucs name:  WATUCS
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: D
Enter UCS name(s) to delete <none>: WATUCS Deleted 1 UCS name.
Command: _UCS
Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: S
Enter name to save current UCS or [?]: WATUCS
Command:


I have a lisp with a standard while command and if you cancel the lisp with esc it creates a new UCS. Is my usage of while( incorrect?

Code: [Select]
(while
(setq atp_polyline
(car
             (nentsel "\nSELECT POLYLINE TO OFFSET AND LOCATE")))

Bhull1985

  • Guest
Re: New UCS on Cancel
« Reply #1 on: February 24, 2014, 11:37:27 AM »
Its hard to say from what you've provided.
Please post the more complete routine :)

ChrisCarlson

  • Guest
Re: New UCS on Cancel
« Reply #2 on: February 24, 2014, 01:03:46 PM »
Code: [Select]
(setq atp_polyline
(car
             (nentsel "\nSELECT POLYLINE TO OFFSET AND LOCATE")))
(if
(and atp_polyline
(setq atp_polylineDXF (entget atp_polyline))
(member (cdr (assoc 0 atp_polylineDXF))'("LWPOLYLINE" "POLYLINE" "LINE" "ARC"))
)
(progn
(setq atp_linelength (vla-get-length(vlax-ename->vla-object atp_polyline)))
(if (> atp_linelength atp_maxdistance)
(progn
(setq atp_atquantity
(1+(fix(/ atp_linelength atp_maxdistance))))
(vl-cmdf "._divide" atp_polyline "B" atp_symbol "N" atp_atquantity)
(vl-cmdf "._draworder" "_L" "" "_F" )
(setq atp_layer  (ssget "X" (list (cons 0 "INSERT")(cons 2 atp_symbol))))
(if (tblsearch "LAYER" "E-LGHT-SYM")
(command "_.chprop" atp_layer "" "_LA" "E-LGHT-SYM" "")
(princ "Layer Not Found??")
) ; end if
) ;end Progn
(alert (strcat "\nERROR RUN MUST BE GREATER THAN ("
(rtos atp_maxdistance 4 1) ") FEET "))
) ;end if
) ;end progn
(princ "\nERROR MUST SELECT A LINE POLYLINE or ARC")
) ; end if
); end while

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: New UCS on Cancel
« Reply #3 on: February 24, 2014, 06:15:00 PM »
Have you defined a local *error* function containing expressions to change the UCS?
If not, does the behaviour still occur if you type (setq *error* nil) at the command-line before running the program?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: New UCS on Cancel
« Reply #4 on: February 24, 2014, 07:09:36 PM »
@ChrisCarlson
Chris,
You have fallen into the trap that is common for the majority of people looking for help.
The code you posted is incomplete and non functioning.
A lot of people here are able to look at your code and decipher ( with a little thought ) the intent.
Having unassigned variables in your code means that anyone perusing your code has to guess the intended value, which is not good.

I can get the code to work in isolation without error

Note that you have unbalanced parenthesis in your code

This works for me.
Code - Auto/Visual Lisp: [Select]
  1. (setq atp_maxdistance 10
  2.       atp_layername "ST00"   ;;<== expected to exist
  3.       atp_symbol "MARKER"   ;;<== expected to exist
  4. )
  5. ;; ^^^ assumed values listed above
  6.  
  7. (while (setq atp_polyline
  8.               (car
  9.                 (nentsel "\nSELECT POLYLINE TO OFFSET AND LOCATE")
  10.               )
  11.        )
  12.   (if (and atp_polyline
  13.            (setq atp_polylinedxf (entget atp_polyline))
  14.            (member (cdr (assoc 0 atp_polylinedxf))
  15.                    '("LWPOLYLINE" "POLYLINE" "LINE" "ARC")
  16.            )
  17.       )
  18.     (progn
  19.       (setq atp_linelength (vla-get-length
  20.                              (vlax-ename->vla-object atp_polyline)
  21.                            )
  22.       )
  23.       (if (> atp_linelength atp_maxdistance)
  24.         (progn
  25.           (setq atp_atquantity
  26.                  (1+ (fix (/ atp_linelength atp_maxdistance))
  27.                  )
  28.           )
  29.           (vl-cmdf "._divide"     atp_polyline
  30.                    "B"            atp_symbol
  31.                    "N"            atp_atquantity
  32.                   )
  33.           (vl-cmdf "._draworder" "_L" "" "_F")
  34.           (setq
  35.             atp_layer (ssget
  36.                         "X"
  37.                         (list (cons 0 "INSERT") (cons 2 atp_symbol))
  38.                       )
  39.           )
  40.           (if (tblsearch "LAYER" atp_layername)
  41.             (command "_.chprop" atp_layer "" "_LA" atp_layername "")
  42.             (princ "Layer Not Found??")
  43.           )
  44.         )
  45.         (alert (strcat "\nERROR: RUN MUST BE GREATER THAN ("
  46.                        (rtos atp_maxdistance 4 1)
  47.                        ") FEET "
  48.                )
  49.         )
  50.       )
  51.     )
  52.     (princ "\nERROR MUST SELECT A LINE POLYLINE or ARC")
  53.   )
  54. )
  55.  

Summary.
The code posted does nothing with the UCS so it is not necessarily relevant.

Have you tried stepping through your entire code attempting to find the real source of your error. ?
« Last Edit: February 24, 2014, 07:17:10 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ChrisCarlson

  • Guest
Re: New UCS on Cancel
« Reply #5 on: February 25, 2014, 08:08:36 AM »
Have you defined a local *error* function containing expressions to change the UCS?
If not, does the behaviour still occur if you type (setq *error* nil) at the command-line before running the program?

The behavior changes, it resorts to what amounts to an undo command. Would make sense that esc/cancel would be interpreted as a "error" I guess I'm curious now why AutoCAD determines that an error involves making a new UCS.

@ChrisCarlson
Chris,
You have fallen into the trap that is common for the majority of people looking for help.
The code you posted is incomplete and non functioning.
A lot of people here are able to look at your code and decipher ( with a little thought ) the intent.
Having unassigned variables in your code means that anyone perusing your code has to guess the intended value, which is not good.

I can get the code to work in isolation without error

Note that you have unbalanced parenthesis in your code

This works for me.
Code - Auto/Visual Lisp: [Select]
  1. (setq atp_maxdistance 10
  2.       atp_layername "ST00"   ;;<== expected to exist
  3.       atp_symbol "MARKER"   ;;<== expected to exist
  4. )
  5. ;; ^^^ assumed values listed above
  6.  
  7. (while (setq atp_polyline
  8.               (car
  9.                 (nentsel "\nSELECT POLYLINE TO OFFSET AND LOCATE")
  10.               )
  11.        )
  12.   (if (and atp_polyline
  13.            (setq atp_polylinedxf (entget atp_polyline))
  14.            (member (cdr (assoc 0 atp_polylinedxf))
  15.                    '("LWPOLYLINE" "POLYLINE" "LINE" "ARC")
  16.            )
  17.       )
  18.     (progn
  19.       (setq atp_linelength (vla-get-length
  20.                              (vlax-ename->vla-object atp_polyline)
  21.                            )
  22.       )
  23.       (if (> atp_linelength atp_maxdistance)
  24.         (progn
  25.           (setq atp_atquantity
  26.                  (1+ (fix (/ atp_linelength atp_maxdistance))
  27.                  )
  28.           )
  29.           (vl-cmdf "._divide"     atp_polyline
  30.                    "B"            atp_symbol
  31.                    "N"            atp_atquantity
  32.                   )
  33.           (vl-cmdf "._draworder" "_L" "" "_F")
  34.           (setq
  35.             atp_layer (ssget
  36.                         "X"
  37.                         (list (cons 0 "INSERT") (cons 2 atp_symbol))
  38.                       )
  39.           )
  40.           (if (tblsearch "LAYER" atp_layername)
  41.             (command "_.chprop" atp_layer "" "_LA" atp_layername "")
  42.             (princ "Layer Not Found??")
  43.           )
  44.         )
  45.         (alert (strcat "\nERROR: RUN MUST BE GREATER THAN ("
  46.                        (rtos atp_maxdistance 4 1)
  47.                        ") FEET "
  48.                )
  49.         )
  50.       )
  51.     )
  52.     (princ "\nERROR MUST SELECT A LINE POLYLINE or ARC")
  53.   )
  54. )
  55.  

Summary.
The code posted does nothing with the UCS so it is not necessarily relevant.

Have you tried stepping through your entire code attempting to find the real source of your error. ?

My apologies, it's a pain to post full code because the "higher ups" want to make sure there isn't anything proprietary  :ugly: should have seen the email chain just to post that snippet. They say we are in a very competitive market ya de da de da. Anyhow I plan on going through the code line by line I know it still has a few other bugs but what lee mentioned sort of makes sense. I guess I always assumed I didn't need to error handle a while command, in fact error handling is next on the agenda to learn about.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: New UCS on Cancel
« Reply #6 on: February 25, 2014, 09:21:35 AM »
Chris, you don't need to post your actual code, you just need to post code that reliably reproduces the problem. Create a copy of your code, then start trimming out anything that doesn't affect the behavior. If you do this, you'll either find the error yourself, or you'll end up with a short piece of code that others can easily test and/or spot the error in.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: New UCS on Cancel
« Reply #7 on: February 25, 2014, 04:31:44 PM »
The behavior changes, it resorts to what amounts to an undo command. Would make sense that esc/cancel would be interpreted as a "error" I guess I'm curious now why AutoCAD determines that an error involves making a new UCS.

If Esc is used to terminate a program, this is handled as an error and as such, AutoCAD will evaluate the *error* function (if defined by the program) or the standard AutoLISP error handler.

If the code has defined a local *error* function (or indeed, if another program has redefined the *error* function and hasn't declared it local to the program), then AutoCAD will evaluate this redefined *error* function upon the user pressing Esc. Therefore, if such *error* functions contain expressions to reset the UCS, or perform an Undo, then this might explain the behaviour you are witnessing.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: New UCS on Cancel
« Reply #8 on: February 25, 2014, 05:31:57 PM »

The command line dump from the first post is not an undo sequence.
A command is being run that explicitly sets/resets the UCS.

This MAY even be caused by the system trying to evaluate a set of closed quoted which evaluate as ENTER which may be re-running the previous  command after an error.

Search your code for "WATUCS". there is a fair chance that you will find the code that is being run ... then you just determine why it is running.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.