Author Topic: Error trapping. Question  (Read 2149 times)

0 Members and 1 Guest are viewing this topic.

Dilan

  • Newt
  • Posts: 23
Error trapping. Question
« on: March 06, 2020, 01:03:15 AM »
Hello.
I get the coordinates of the point:
Code: [Select]
(setq pt (getpoint "\nPick point to extract surface elevation: "))Then I get the surface level in the coordinates of this point:
Code: [Select]
(setq lavelTin (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'FindElevationAtXY (car pt) (cadr pt)))
But if the coordinates of my point "pt" out of border surface - I get an error. And it is clear
How can I do so in this case my variable "lavelTin" was equal for example: "out_of_border"?

Thank you all for your attention.

rayakmal

  • Newt
  • Posts: 49
Re: Error trapping. Question
« Reply #1 on: March 06, 2020, 01:58:47 AM »
Hello.
I get the coordinates of the point:
Code: [Select]
(setq pt (getpoint "\nPick point to extract surface elevation: "))Then I get the surface level in the coordinates of this point:
Code: [Select]
(setq lavelTin (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'FindElevationAtXY (car pt) (cadr pt)))
But if the coordinates of my point "pt" out of border surface - I get an error. And it is clear
How can I do so in this case my variable "lavelTin" was equal for example: "out_of_border"?

Thank you all for your attention.


Maybe you can use this:

Code: [Select]
(if (AND
      (setq pt (getpoint "\nPick point to extract surface elevation: "))
      (setq lavelTin (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'FindElevationAtXY (car pt) (cadr pt)))
    )
   (princ "OK")
)

Dilan

  • Newt
  • Posts: 23
Re: Error trapping. Question
« Reply #2 on: March 06, 2020, 02:06:16 AM »
Not. I get the same error

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Error trapping. Question
« Reply #3 on: March 06, 2020, 08:09:49 AM »
I don't use the Verticals, but try this -
Code - Auto/Visual Lisp: [Select]
  1.     (and
  2.         (setq pt (getpoint "\nPick point to extract surface elevation: "))
  3.         (setq en (car (entsel)))
  4.     )
  5.     (if (vl-catch-all-error-p (setq lavelTin (vl-catch-all-apply 'vlax-invoke (list (vlax-ename->vla-object en) 'FindElevationAtXY (car pt) (cadr pt)))))
  6.         (princ "\nError obtaining elevation.")
  7.         (princ lavelTin)
  8.     )
  9. )

Dilan

  • Newt
  • Posts: 23
Re: Error trapping. Question
« Reply #4 on: March 06, 2020, 04:07:40 PM »
I don't use the Verticals, but try this -
Code - Auto/Visual Lisp: [Select]
  1.     (and
  2.         (setq pt (getpoint "\nPick point to extract surface elevation: "))
  3.         (setq en (car (entsel)))
  4.     )
  5.     (if (vl-catch-all-error-p (setq lavelTin (vl-catch-all-apply 'vlax-invoke (list (vlax-ename->vla-object en) 'FindElevationAtXY (car pt) (cadr pt)))))
  6.         (princ "\nError obtaining elevation.")
  7.         (princ lavelTin)
  8.     )
  9. )
thanks. That's what I need.Everything works as it should.