<LispFunction.....Call VB.NET Function that use VB Forms?

<LispFunction.....Call VB.NET Function that use VB Forms?

Anonymous
Not applicable
1,899 Views
2 Replies
Message 1 of 3

<LispFunction.....Call VB.NET Function that use VB Forms?

Anonymous
Not applicable

Can the LispFunction "feature" be used to call other VB.NET Functions which load VB.NET forms?

0 Likes
1,900 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant

Hi,

 

You can do the same things under the LipFunction attribute as under CommandMethod one.

The only difference is the lispFunction method must have an argument (a ResultBuffer) and should return a value: any LISP valid type : String ,Integer, Double, SelectionSet, ObjectId (ename) Point3d, TypedValue (T or nil) or a ResultBuffer contain these kind of values (as a LISP list). Except with A2008 which seems to only allows ResulBuffer as return type.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

norman.yuan
Mentor
Mentor

Sure. Here is an example (in C#. it is simple enough to translate to VB.NET, or you can find an online C#<->VB.NET converting site):

 

In the Acad DLL project, add Win form with c ouople of tex boxes to get user input:

 

using System;
using System.Text;
using System.Windows.Forms;

namespace LispInputFromForm
{
        public Form1()
        {
            InitializeComponent();
        }

        public string Text1
        {
	    get { return TextBox1.Text; }
        }

        public string Text2
        {
	    get { return TextBox2.Text; }
        }
}

The form would typically has 2 buttons: Cancel button with its DialogResult property set to "Cancel" and OK button with DialogResult property set to "OK". Of course you'd have user input validation logic in place before OK button can be clicked.

 

Then you can use the form in a [ListFunction]-tagged function:

 

[LispFunction("Do_This")]
public static ResultBuffer GetLispData()
{
    ResultBuffer res = null;

    string t1="", t2="";
    bool cancelled = false;
    using (Form1 frm = new Form1())
    {
        DialogResult dlg = Autodesk.AutoCAD.ApplicationServices.
	                       Application.ShowModalDialog(frm);
        if (dlg == DialogResult.OK)
        {
                    t1 = frm.Text1;
                    t2 = frm.Text2;
        }
        else
        {
            cancelled = true;
        }
    }

    if (!cancelled)
    {
        TypedValue[] data=new TypedValue[]{
            new TypedValue((int)LispDataType.Text,t1),
            new TypedValue((int)LispDataType.Text,t2)
            };

        res = new ResultBuffer(data);
    }

    return res;
}

 Natually, the form should be shown as Modal dialog so that the user must dismiss the form before the function can continue.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes