Author Topic: How do I know witch action produced the error????  (Read 3179 times)

0 Members and 1 Guest are viewing this topic.

LogicTools

  • Newt
  • Posts: 36
How do I know witch action produced the error????
« on: January 31, 2021, 01:00:48 PM »
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:ErrorTest  (/ ActiveDocument Utility the_prompt MyError object base_point)
  3.  (setvar "errno" 0)
  4.  (setq
  5.   Utility        (vla-get-utility ActiveDocument)
  6.   the_prompt     "Select object"
  7.   MyError        (vl-catch-all-apply 'vla-getentity (list Utility 'object 'base_point the_prompt))
  8.   )
  9.  (while (not MyError)
  10.   (print object)
  11.   (setq
  12.    MyError (vl-catch-all-apply 'vla-getentity (list Utility 'object 'base_point the_prompt))
  13.    )
  14.   )
  15.  (print (getvar "errno"))
  16.  (setvar "errno" 0)
  17.  (princ)
  18.  )
  19.  

Running ErrorTest:
If selecting 2 objects an a third object is not pickup, the function returns:
Code - Auto/Visual Lisp: [Select]
  1. #<VLA-OBJECT IAcad3DSolid 0000024deaca5358>
  2. #<VLA-OBJECT IAcad3DSolid 0000024deaca5358>
  3. 7
  4. "Automation Error. Description was not provided."
  5.  

If after selecting 2 objects ESC is pressed, the function returns:
Code - Auto/Visual Lisp: [Select]
  1. #<VLA-OBJECT IAcad3DSolid 0000024deaca5358>
  2. #<VLA-OBJECT IAcad3DSolid 0000024deaca5358>
  3. 52
  4. "Automation Error. Description was not provided."
  5.  

If after selecting 2 objects ENTER is pressed, the function returns:
Code - Auto/Visual Lisp: [Select]
  1. #<VLA-OBJECT IAcad3DSolid 0000024deaca5358>
  2. #<VLA-OBJECT IAcad3DSolid 0000024deaca5358>
  3. 52
  4. "Automation Error. Class not registered\r\n"
  5.  

By the value of "errno" 7 I am able to identify the reason when the error happens if an object is not pickup but the "errno" value 52 is the same for the other two reasons.
For these the error message is different, but is shows in the installer local language so, how do I know what the translation is for the message in other languages or, is there any other way to identify the difference ?
Any ideas will be greatly appreciated.

BIGAL

  • Swamp Rat
  • Posts: 1420
  • 40 + years of using Autocad
Re: How do I know witch action produced the error????
« Reply #1 on: January 31, 2021, 05:42:13 PM »
If you want solids use ssget with the correct filter this will force select "solid" the ssget can have multi filters so then can check Objectname and do correct code.

A man who never made a mistake never made anything

LogicTools

  • Newt
  • Posts: 36
Re: How do I know witch action produced the error????
« Reply #2 on: January 31, 2021, 09:28:54 PM »
Thank you Bigal for your suggestion, but my problem is to detect it the user hits ESC, ENTER or any other action.
Perhaps this part:
Code - Auto/Visual Lisp: [Select]
  1.    MyError (vl-catch-all-apply 'vla-getentity (list Utility 'object 'base_point the_prompt))
  2.    )
  3.   )
should be like:
Code - Auto/Visual Lisp: [Select]
  1.   the_prompt     "Select object, ESC to exit, or ENTER to continue"
  2.    MyError (vl-catch-all-apply 'vla-getentity (list Utility 'object 'base_point the_prompt))
  3.    )
  4.   )

If the option is ENTER then the program will proceed with the objects selected. Any other option will exit.
Also, in my case the objects must be selected one by one to be able to be arranged in a certain order.
Thank you again for your help.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How do I know witch action produced the error????
« Reply #3 on: February 01, 2021, 03:53:21 AM »
You can switch to entsel. This will return nil in case of a miss or if enter is pressed.
Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply 'entsel)

LogicTools

  • Newt
  • Posts: 36
Re: How do I know witch action produced the error????
« Reply #4 on: February 01, 2021, 12:19:19 PM »
Thanks roy_043, but with entsel I don't have the possibility of distinguishing between a pick miss or entering ESC, ENTER or SPC because all of them return nil.
So I came to this solution that retrieves the objects' list if the user presses  ENTER, SPC, or ESC and filters pick misses and objects names.
I am open to any other, simpler solution.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ErrorTest  (/ object_list ActiveDocument Utility the_prompt return_list object object_name object_list)
  2.  (setvar "errno" 0)
  3.  (setq
  4.   Utility        (vla-get-utility ActiveDocument)
  5.   object_list    '()
  6.   the_prompt     "Select object"
  7.   return_list    (getentity the_prompt)
  8.   )
  9.  (while (and return_list (< (car return_list) 52))
  10.   (if (= (car return_list) 0)
  11.    (progn
  12.     (setq
  13.      object      (cadr return_list)
  14.      object_name (vla-get-objectname object)
  15.      )
  16.     (if (/= object_name "AcDb3dSolid")
  17.      (alert "Selected object was not a 3DSolid")
  18.      (setq
  19.       object_list (append object_list (list object))
  20.       )
  21.      )
  22.     )
  23.    (alert "No object was selected")
  24.    )
  25.   (setq
  26.    the_prompt  "\nSelect next object or ESC, SPC or ENTER to end selection"
  27.    return_list (getentity the_prompt)
  28.    )
  29.   )
  30.  object_list
  31.  )
  32.  
  33. (defun getentity  (the_prompt / error object base_point return errno)
  34.  (setvar "errno" 0)
  35.  (setq
  36.   error (vl-catch-all-apply 'vla-getentity (list Utility 'object 'base_point the_prompt))
  37.   )
  38.  (if (not error)
  39.   (setq
  40.    return (list 0 object base_point)
  41.    )
  42.   (setq
  43.    errno  (getvar "errno")
  44.    return (list errno nil nil)
  45.    )
  46.   )
  47.  )

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How do I know witch action produced the error????
« Reply #5 on: February 01, 2021, 12:30:47 PM »
I did not understand well what you need, maybe this can give you some ideas
Code: [Select]
; Function: ALE_SsGetFilter
;
; Version 1.00 - 22/02/2005
; Version 1.01 - 04/03/2006 - added (setvar "ERRNO" 0)
; Version 1.02 - 13/09/2007 - removed "ERRNO" > do not work with multiple objects
;                             but only with (ssget "_:E:S") or similar
; Description:
;   Ssget with filter list
;
; Arguments:
;   PrmStr = User prompt [STR]
;   FltLst = ssget filter list [LIST] or nil for no filter
;
; Example:
;  (ALE_SsGetFilter "Select attibuted block(s)" '((0 . "INSERT") (66 . 1)))
;
; Return Values:
;   [PICKSET] Selection set
;
(defun ALE_SsGetFilter (PrmStr FltLst / FlgSlt SelSet)
    (princ "\n_ ")
    (prompt (setq PrmStr (strcat "\n" PrmStr ": ")))
    (while (not FlgSlt)
      (if (setq SelSet (ssget FltLst))
        (setq FlgSlt T)
;|e|;   (prompt (strcat "\nNo valid objects, try again!" PrmStr))
      )
    )
    SelSet
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: How do I know witch action produced the error????
« Reply #6 on: February 01, 2021, 12:48:59 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / err sel)
  2.   (setvar 'errno 0)
  3.   (setq sel (vl-catch-all-apply 'entsel))
  4.   (cond
  5.       (princ "\nEsc was pressed ")
  6.     )
  7.     (sel
  8.       (princ "\nSucces! ")
  9.     )
  10.     ((= (setq err (getvar 'errno)) 52)
  11.       (princ "\nEnter was pressed ")
  12.     )
  13.     ((= err 7)
  14.       (princ "\nMissed it! Try again please: ")
  15.     )
  16.   )
  17.   (princ)
  18. )

LogicTools

  • Newt
  • Posts: 36
Re: How do I know witch action produced the error????
« Reply #7 on: February 01, 2021, 01:06:45 PM »
Grazie Marco. Nice way of using ssget an filters for the purpose.
Also, perhaps a simpler way to do it with entsel instead of vla-getentity as suggested by roy_043.
Thank you guys!!!!


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How do I know witch action produced the error????
« Reply #8 on: February 02, 2021, 02:17:49 AM »
Maybe this was the right tip for your use…  :oops: IMHO using vla-get-objectname is a little less practical  :blink:
Code: [Select]
; Function: ALE_EntSelFilter
;
; Version 1.00 - 22/02/2005
; Version 1.01 - 04/03/2006 - added (setvar "ERRNO" 0)
;
; Description:
;   Ssget for one entity with filter list
;
; Arguments:
;   PrmStr = User prompt [STR]
;   FltLst = ssget filter list [LIST]
;
; Example:
;  (ALE_EntSelFilter "Select attibuted block" '((0 . "INSERT") (66 . 1)))
;
; Return Values:
;   [ENAME] Entity name
;   nil if user press 'Return' or 'Space'

(defun ALE_EntSelFilter (PrmStr FltLst / FlgSlt EntNam)
    (setvar "ERRNO" 0)
    (princ "\n_ ")
    (prompt (setq PrmStr (strcat "\n" PrmStr ": ")))
    (if
      (while (not FlgSlt)
        (if (setq EntNam (ssget "_:E:S" FltLst))
          (not (setq FlgSlt T))
          (if (= 52 (getvar "ERRNO"))
            (setq FlgSlt T)
            (prompt (strcat "\nNo objects selected or valid, try again!" PrmStr))
          )
        )
      )
      (not (princ "\nFunction cancelled.  "))
      (ssname EntNam 0)
    )
)

LogicTools

  • Newt
  • Posts: 36
Re: How do I know witch action produced the error????
« Reply #9 on: February 02, 2021, 10:11:11 PM »
Molto interesante Marco.
My purpose to start with was to distinguish when the user was hitting SPC, ESC or ENTER to end the loop.
The last prompt should have been: "Select next object or ENTER to end selection", if at that point SPC or ESC were hit the function will quit, if ENTER is pressed then the function will proceed with the selected objects list.
But that's my problem, I don't know how to differentiate which key has been pressed to end the loop.

PKENEWELL

  • Bull Frog
  • Posts: 320
Re: How do I know witch action produced the error????
« Reply #10 on: February 03, 2021, 11:56:01 AM »
Just as a side note: When troubleshooting an error, you can add the Visual Lisp function (vl-bt) into your error handler. This will provide a full backtrace of the error.

As an example - I use this command to clear my global error handlers and add backtrace when I'm troubleshooting an AutoLISP function

Code - Auto/Visual Lisp: [Select]
  1. (defun c:pjk-errnil ()
  2.     (setq *error* nil pjk-error nil pjk:debugflag T)
  3.     (setvar "cmdecho" 1)
  4.     (defun *error* (msg)(vl-bt))
  5.     (defun pjk-error (msg)(vl-bt))
  6.     (princ)
  7. )
  8.  
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: How do I know witch action produced the error????
« Reply #11 on: February 03, 2021, 03:57:10 PM »
My purpose to start with was to distinguish when the user was hitting SPC, ESC or ENTER to end the loop.
The last prompt should have been: "Select next object or ENTER to end selection", if at that point SPC or ESC were hit the function will quit, if ENTER is pressed then the function will proceed with the selected objects list. But that's my problem, I don't know how to differentiate which key has been pressed to end the loop.

Under most circumstances, SPACE, ENTER & right-click are equivalent & indistinguishable; unless you opt to roll your own selection function through the use of grread to monitor and differentiate between all forms of user input - but even given the work involved to implement this, having the function quit on the user pressing SPACE, but continue on ENTER is counter to standard AutoCAD behaviour and will confuse long time users.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: How do I know witch action produced the error????
« Reply #12 on: February 04, 2021, 02:58:29 AM »
Under most circumstances, SPACE, ENTER & right-click are equivalent & indistinguishable; unless you opt to roll your own selection function through the use of grread to monitor and differentiate between all forms of user input - but even given the work involved to implement this, having the function quit on the user pressing SPACE, but continue on ENTER is counter to standard AutoCAD behaviour and will confuse long time users.
I fully agree, I always use the space bar and use the enter key only when necessary… and so do everyone I know.  :-)

LogicTools

  • Newt
  • Posts: 36
Re: How do I know witch action produced the error????
« Reply #13 on: February 04, 2021, 05:26:07 PM »
PKENEWELL thanks for pointing out that your very useful function and thank you Carlo and Lee for your observations.
So my question is how do I know when the user is finishing selecting objects and continue to proceed them or is entering ESC, for instance, because he wants to cancel and not continuing with the selection?

LogicTools

  • Newt
  • Posts: 36
Re: How do I know witch action produced the error????
« Reply #14 on: February 09, 2021, 12:10:49 PM »
So, as there is not possibility of knowing when the user is finishing selecting objects and proceed or when he/she wants to cancel, I opted for asking to enter the total number of objects to be selected and processed at the beginning of the function.
Like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ErrorTest  (/ object_list ActiveDocument Utility obj_num getobj_list the_prompt return_list object object_name)
  2.  (if (null g::obj_num)
  3.   (setq
  4.    object_list nil
  5.    g::obj_num  3
  6.    )
  7.   )
  8.  (setq
  9.   Utility        (vla-get-utility ActiveDocument)
  10.   )
  11.  (initget 6)
  12.  (setq
  13.   obj_num (getint (strcat "Number of objects to be selected" ": <" (itoa g::obj_num) ">"))
  14.   )
  15.  (if (not obj_num)
  16.   (setq
  17.    obj_num g::obj_num
  18.    )
  19.   (setq
  20.    g::obj_num obj_num
  21.    )
  22.   )
  23.  (if obj_num
  24.   (progn
  25.    (setq
  26.     object_list '()
  27.     the_prompt  "Select first object"
  28.     obj_count   0
  29.     )
  30.    (while (< obj_count obj_num)
  31.     (setq
  32.      getobj_list (getobj the_prompt object_list)
  33.      )
  34.     (if (and getobj_list (car getobj_list))
  35.      (progn
  36.       (setq
  37.        obj_count  (+ (car getobj_list) obj_count)
  38.        the_prompt (strcat "\n" (itoa obj_count) " of " (itoa obj_num) " objects selected"
  39.                           "\n Select next object :")
  40.        )
  41.       (if (> (car getobj_list) 0)
  42.        (setq
  43.         object_list (append object_list (list (last getobj_list)))
  44.         )
  45.        )
  46.       )
  47.      (setq
  48.       obj_count obj_num
  49.       object_list nil
  50.       )
  51.      )
  52.     )
  53.    )
  54.   )
  55.  object_list
  56.  )
  57.  
  58. (defun getobj  (the_prompt object_list / return error object base_point object_name)
  59.  (setvar "errno" 0)
  60.  (setq
  61.   return nil
  62.   error  (vl-catch-all-apply 'vla-getentity (list Utility 'object 'base_point the_prompt))
  63.   )
  64.  (if (not error)
  65.   (progn
  66.    (setq
  67.     object_name (vla-get-objectname object)
  68.     )
  69.    (cond
  70.     (
  71.      (/= object_name "AcDb3dSolid")
  72.      (setq
  73.       return (list 0 nil)
  74.       )
  75.      (alert "Selected object was not a 3DSolid")
  76.      )
  77.     (
  78.      (member object object_list)
  79.      (setq
  80.       return (list 0 nil)
  81.       )
  82.      (alert "Object was previously selected")
  83.      )
  84.     )
  85.    )
  86.   (progn
  87.    (if (< (getvar "errno") 52)
  88.     (progn
  89.      (setq
  90.       return (list 0 nil)
  91.       )
  92.      (alert "No object was selected")
  93.      )
  94.     (progn
  95.      (setq
  96.       return (list nil nil)
  97.       )
  98.      (alert "Not enougth data to proceed")
  99.      )
  100.     )
  101.    )
  102.   )
  103.  (if (not return)
  104.   (setq
  105.    return (list 1 object)
  106.    )
  107.   )
  108.  return
  109.  )
  110.  
CAUTION: The code had not been fully tested !!!!