Hi, I try to write a lisp to get elevation from TIN surface in AutoCAD Civil 3D. But coordinate can be not on surface. In this case I get an error and my lisp execution stops. Here are a function
(defun GetElevationAtXY (coordinate surfaceName / ) (vlax-invoke-method surfaceName "FindElevationAtXY" (car coordinate) (cadr coordinate))) )
If coordinate are not on surface I would like to return nil, and continue lisp execution. nil would be handled later in another function. Is it possible in lisp?
P.S.
error message I get are
Error. Automation Error. Triangle is deleted
Solved! Go to Solution.
I found I can use vl-catch-all-apply for this, and added it to my function. But now I get error message like this
Error: bad argument type: symbolp nil
This is my curent function
(defun GetElevationAtXY (coordinate surfaceName / z) (set z (vl-catch-all-apply 'vlax-invoke-method (list surfaceName "FindElevationAtXY" (car coordinate) (cadr coordinate))) ) (if (= (vl-catch-all-error-p z) T) (setq z nil) (setq z z) ) )
This error is in line
(vl-catch-all-apply 'vlax-invoke-method (list surfaceName "FindElevationAtXY" (car coordinate) (cadr coordinate)))
http://www.lee-mac.com/errormessages.html
Here's the page where you can check the different error codes and what they mean, as well as tutorials on how to fix them.
Typically what follows a call to -invoke-method is a method, it appears as if that may not be the case in your line of code but perhaps im wrong
Here are samething wrong with list I make
To test (vl-catch-all-apply 'vlax-invoke-method li) I have creaded li in AutoCAD command line
(setq li (list surfaceName "FindElevationAtXY" (car coordinate) (cadr coordinate)))
And I got back this
(#<VLA-OBJECT IAeccTinSurface 000000002f769c80> "FindElevationAtXY" 419214 6144697)
look at "FindElevationAtXY".
But if I do this in lisp
(defun GetElevationAtXY (coordinate surfaceName / z li) (setq li (list surfaceName "FindElevationAtXY" (car coordinate) (cadr coordinate))) (princ li) (set z (vl-catch-all-apply 'vlax-invoke-method li) ) (if (= (vl-catch-all-error-p z) T) (setq z nil) (setq z z) ) )
I get this printed
(#<VLA-OBJECT IAeccTinSurface 000000002f769c80> FindElevationAtXY 419143.0 6.14477e+006)
"FindElevationAtXY" became FindElevationAtXY. So probably it is treated as variable and not as string. But here are no variable FindElevationAtXY so it is equal to nil.
But how to fix it?