Error message

Error message

k005
Advisor Advisor
1,404 Views
17 Replies
Message 1 of 18

Error message

k005
Advisor
Advisor

Hello everyone

How can I get the error message when the command does not work in the below line of code?

Thank you.

 

 private void btnYap_Click(object sender, EventArgs e)
        {
            this.Hide();
            Adoc.SendStringToExecute("elev1_symbol\n", true, false, true);
            this.Close();
        }
0 Likes
Accepted solutions (1)
1,405 Views
17 Replies
Replies (17)
Message 2 of 18

_gile
Consultant
Consultant

Hi,

 

See this topic.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 18

k005
Advisor
Advisor

Hi


I added the try-catch structure before posting on the forum. I also put a message box.
It didn't show the message when I tested it.

0 Likes
Message 4 of 18

k005
Advisor
Advisor

@_gile 

 

elev1_symbol

 

this is a lisp command. It works from within the lisp routine.

 

I don't know if it makes a difference... in this case, how should the example try catch structure be?

 

Thank you.

0 Likes
Message 5 of 18

_gile
Consultant
Consultant

Is there any error message in the AutoCAD command line/text screen?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 18

hippe013
Advisor
Advisor
(defun myLispFoo ()
  (princ "\nHello World")
  (princ)
  )

 

aDoc.SendStringToExecute("(myLispFoo) ", True, False, True)

 

Notice the parentheses before and after function name and then a space after that.  

0 Likes
Message 7 of 18

k005
Advisor
Advisor

command line message: Unknown command "elev1_symbol". Press F1 for help.

 

The classic answer of autocad. In fact, it is clear from this message. but I will specify the lisp name with the

 

messagebox...

0 Likes
Message 8 of 18

k005
Advisor
Advisor

i did it this way. but I didn't get the message.

 private void btnOfsetAt_Click(object sender, EventArgs e)
        {
            this.Hide();
            try
            {
                Adoc.SendStringToExecute("(elev1_symbol) ", true, false, true);
            }
            catch (Exception)
            {

                //throw;
                MessageBox.Show("abcdef lispi yüklü değil.");
            }
            
            this.Close();
        }
0 Likes
Message 9 of 18

hippe013
Advisor
Advisor

Were you expecting an error? 

0 Likes
Message 10 of 18

k005
Advisor
Advisor

Yes. As I mentioned in my question.

 

 

 

so the elev1_symbol command is not available... so I should get an error.

0 Likes
Message 11 of 18

hippe013
Advisor
Advisor
(defun c:myLispCmd ()
  (princ "\nHello Command!")
  (princ)
  )
aDoc.SendStringToExecute("(c:myLispCmd) ", True, False, True)
(defun myLispFoo ()
  (princ "\nHello Function!")
  (princ)
  )
aDoc.SendStringToExecute("(myLispFoo) ", True, False, True)

 

 

0 Likes
Message 12 of 18

hippe013
Advisor
Advisor

An error in the execution of the lisp will not bubble up to be an error in the execution of the .NET portion of your code. The try catch will catch errors in your SendStringToExecute and not an error within the lisp itself. That is my understanding anyways. 

0 Likes
Message 13 of 18

k005
Advisor
Advisor

I understand.

 

I cannot use the try catch construct for this situation.

 

Thank you.

0 Likes
Message 14 of 18

hippe013
Advisor
Advisor

If you are trying to catch the error within your lisp, use the *error* definition to catch the error. I was showing how send the lisp using the SendStringToExcecute method. What did you want the Try-Catch to catch? 

0 Likes
Message 15 of 18

k005
Advisor
Advisor

now on this i'm not talking about coding an error message in lisp.

 

only lisp relation should be in button click event. which, if lisp already exists, the command works. If not, it gives an

 

error on the command line. not found etc...

 

I wanted to receive the not found message with the message box.

0 Likes
Message 16 of 18

hippe013
Advisor
Advisor

How about creating a .NET lisp function that checks for the existence of the defined lisp command and returns a boolean? 

0 Likes
Message 17 of 18

norman.yuan
Mentor
Mentor
Accepted solution

If you are using SendStringToExecute(), regardless of the code being executed is LISP command or .NET command, there is no use to wrap it with try...catch..., because the SendStringToExecute() is async and only runs AFTER the calling routine ends (in your case, the execution runs through the try...catch... and the button click routine is done, then the action called in SendStringToExecute() starts). So even there is error because of the SendStringToExecute(), the error cannot be send back to the calling routine, because it HAS ALREADY ENDED.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 18 of 18

k005
Advisor
Advisor

 

Many thanks for the detailed explanation.

 

I'm closing the issue.

0 Likes