AutoLISP messagebox to C# text box

AutoLISP messagebox to C# text box

Anonymous
Not applicable
1,744 Views
4 Replies
Message 1 of 5

AutoLISP messagebox to C# text box

Anonymous
Not applicable

Hi,

 

I am using AutoLISP for measuring total length of a line and it shows autocad message box as shown in picture.

 

Capture.JPG

 

But I want to display the length into winform of C#.

is it possible to do that?

 

Any kind of help is badly needed.

 

regards

Banna

 

0 Likes
Accepted solutions (1)
1,745 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Mixing LISP and .NET often brings more issues than easy solutions.

 

Anyway, you can show a winform from within LispFunction attributed method.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

dgorsman
Consultant
Consultant

Doesn't even need to be a winform - a MessageBox would do, as it's very similar to the LISP (alert ...) function.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 4 of 5

Anonymous
Not applicable

Can you please share the code?

0 Likes
Message 5 of 5

_gile
Consultant
Consultant

Hi,

 

To use the standard MessageBox, you can simply build a simple LispFunction method:

        [LispFunction("messagebox")]
        public bool MessagegBox(ResultBuffer resbuf)
        {
            if (resbuf != null)
            {
                var arg = resbuf.AsArray()[0];
                if (arg.TypeCode == (int)LispDataType.Text)
                {
                    MessageBox.Show(arg.Value.ToString());
                    return true;
                }
            }
            return false;
        }

Usage:

(messagebox "Total length of selected objects is 1523.401")

 

If you want to use a "custom" message box, you can use the same way.

 

A trivial example of custom message box:

    public class MsgBox : Form
    {
        public MsgBox(string msg)
        {
            Size = new System.Drawing.Size(250, 110);
            StartPosition = FormStartPosition.CenterParent;
            Text = "Message from LISP";
            FormBorderStyle = FormBorderStyle.FixedDialog;
            AutoSize = true;
            MinimizeBox = false;
            MaximizeBox = false;

            Controls.Add(new Label()
            {
                AutoSize = true,
                Location = new System.Drawing.Point(13, 13),
                Text = msg
            });

            Controls.Add(new Button
            {
                DialogResult = DialogResult.OK,
                Location = new System.Drawing.Point(80, 37),
                Text = "OK"
            });
        }
    }

The LISP function:

        [LispFunction("msgbox")]
        public bool MsgBox(ResultBuffer resbuf)
        {
            if (resbuf != null)
            {
                var arg = resbuf.AsArray()[0];
                if (arg.TypeCode == (int)LispDataType.Text)
                {
                    using (var dlg = new MsgBox(arg.Value.ToString()))
                    {
                        Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(dlg);
                    }
                    return true;
                }
            }
            return false;
        }

Usage:

(msgbox "Total length of selected objects is 1523.401")


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes