I wasn't sure where to post this. This could be a "show your stuff, AutoLISP, or .NET" post. I made an AutoLISP wrapper for a .NET LISP function.
; Name: J. Overkamp
; Date: 09/23/2020
; Provided a C# .NET Wrapper to allow .NET
; to call the *error* function and pass on
; an error message as well as cancel the LISP
; Function
(defun DotNetWrapper (fun args / *error* temp rtn)
(defun *error* (msg)
(princ)
)
(defun temp (fun args / *error*)
(defun *error* (msg)
(princ "\n; error: ")
(princ msg)
(setq error t)
)
(vl-acad-defun '*error*)
(apply fun (list args))
)
(setq rtn (temp fun args))
(and error (/ 1 0))
rtn
)
Here is the .NET code I used to test this:
try
{
throw new System.Exception("test successful");
}
catch (System.Exception e)
{
ResultBuffer error = new ResultBuffer(
new TypedValue((int)LispDataType.Text, "*error*"),
new TypedValue((int)LispDataType.Text, e.Message)
);
ResultBuffer rtn = Application.Invoke(error);
}
In a nutshell I finally found a way to push an error in LISP from .NET and have the LISP function stop.