.NET

.NET

Reply
Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 1 of 10 (2,890 Views)
Accepted Solution

how to send a command from a vb.net form to AutoCAD?

2890 Views, 9 Replies
09-05-2012 12:16 AM

I don’t often used VB.net but I would like to know how I can create a form with a button that will send a command to AutoCAD. I’ve goggled but get nothing near enough to what I find understandable.

 

Could anybody assist in this?

Okay lets put this simple wher can I get the very basics of vb.net in relation to AutoCAD. Is it even possible to Build a form with a button as a trigger in VB.net express which is responsible for sending a command to AutoCAD, which triggers my lisp?

 

(the problem is theres no simple basic introduction online, it all just seams to jump in somewhere)

Well VBA seemed a lot simpler I would only need the following code.

Don’t even know where to start replicating this in vb.net?

 

Private Sub CommandButton1_Click()
ThisDrawing.SendCommand ("(c:MYcustomLISPcommand)" & vbCr)
Unload UserForm1
End Sub

 

How can I do this in vb.net (my apologies I wasn’t thinking it doesn’t need to be in form of an exe it may also be in form of a DLL file)

you need to get started by reaing the Autocad VB.net developers guide

 

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html

 

First you need to install MicroSoft Visual Studio VB.net (Express version is free)

 

Then add references to the required AutoCad files which allow Visual Studio VB to access the Autocad .net libraries. Configure Visual Studio for the right version of .NET depending on your version of AutCAD.

 

Create a userform and code, then compile to a DLL which is loaded into AutoCAD using "NETLOAD" AutoCAD command.

 

Hallex described the details to help you after you do the other things first.

 

 

 

 

 

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 10 (2,879 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-05-2012 01:26 AM in reply to: The_Caddie

Not clearly enough for me

Do you want to create stand alone

project using .exe application or

you want to create managed API call?

And also, what the language you're prefering?

 

~'J'~

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 3 of 10 (2,875 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-05-2012 01:40 AM in reply to: The_Caddie

What I would like is to make an exe which sends a comand to autocad. I'm not all to concerned about automatically starting autocad or any of that as the exe would be called up ussing a lisp function/ command hens AutoCAD is already running otherewise you couldnt just run the exe.

 

Im ussing vb.net to create an application, think thats clear enougth...

Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 4 of 10 (2,877 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-05-2012 02:21 AM in reply to: The_Caddie

Okay lets put this simple wher can I get the very basics of vb.net in relation to AutoCAD. Is it even possible to Build a form with a button as a trigger in VB.net express which is responsible for sending a command to AutoCAD, which triggers my lisp?

 

(the problem is theres no simple basic introduction online, it all just seams to jump in somewhere)

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 10 (2,866 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-05-2012 03:22 AM in reply to: The_Caddie

I will be back in a 2-3 hours back,

Wait, please, if somebody else could not

add an example you need,

Cheers :smileyhappy:

 

~'J'~

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 6 of 10 (2,858 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-05-2012 06:24 AM in reply to: The_Caddie

Okay from what I get is that I have to create a class1.vb and attach a user form by adding a usser controll from eher on im lost

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 7 of 10 (2,850 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-05-2012 07:25 AM in reply to: The_Caddie

create Windows Forms Application, name it "LoadLisp" or something else,

drop Button1 on form and add caption on the button, say "Load my lisp" add references to:

 AutoCAD xxxx Type Library

AutoCAD ObjectDBX/Common xx.x Type Library

Add following code on form module, click Build solution

Then go to folder ///...bin/Debug select application and load

its  icon on windows screen, then try it

(change lisp file name in command within the code before)

 

'______________________________________'
Imports System.Reflection

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Hide()
        LoadLisp()
        Me.Show()
    End Sub
    Public Sub LoadLisp()
        Dim appver As Object = TryCast(My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Autodesk\AutoCAD", "CurVer", Nothing), Object)
        If appver Is Nothing Then
            MessageBox.Show("Out of luck, sorry, you get a problem to read Registry", "Bad for you")
            Return
        End If
        Dim oAcadApp As AcadApplication = New AcadApplication

        Try
            If oAcadApp Is Nothing Then
                oAcadApp = GetObject(, "AutoCAD.Application" + appver.ToString())
            End If
        Catch ex As System.Exception
            MessageBox.Show("Working in opened document only!")
            Return
        End Try
        oAcadApp.Visible = True
        oAcadApp.WindowState = AcWindowState.acMax
        Dim oAcDoc = oAcadApp.ActiveDocument
        '' lisp with command C:SPLASH is loaded from disk C:\Test\Splash.lsp
        ''------------------------------------------------------''
        '' Change both lines of next code block to suit:
        Dim command As String = "(load ""C:/Test/Splash.lsp"")"
        oAcDoc.SendCommand(command & "(C:SPLASH) ")
        ''------------------------------------------------------''
    End Sub


End Class  


''___________________________________________________''

 I can't help you other then that, coz I have very limited

 skills with work from forms

 

~'J'~

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
dgorsman
Posts: 5,698
Registered: ‎10-12-2006
Message 8 of 10 (2,836 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-05-2012 01:34 PM in reply to: The_Caddie

There can't be a "simple" introduction, as there is no such thing.  Even forms require a fair understanding of a number of programming concepts.  Where you're at is the creation of an application, which involves tying together those various programming and IDE concepts into a working product.

 

dotNET is certainly *not* plug-and-play.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 9 of 10 (2,807 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-06-2012 01:52 AM in reply to: dgorsman

Well VBA seemed a lot simpler I would only need the following code.

Don’t even know where to start replicating this in vb.net?

 

Private Sub CommandButton1_Click()

ThisDrawing.SendCommand ("(c:MYcustomLISPcommand)" & vbCr)

Unload UserForm1

End Sub

 

How can I do this in vb.net (my apologies I wasn’t thinking it doesn’t need to be in form of an exe it may also be in form of a DLL file)

Distinguished Contributor
fxcastil
Posts: 404
Registered: ‎11-11-2002
Message 10 of 10 (2,779 Views)

Re: how to send a command from a vb.net form to AutoCAD?

09-06-2012 03:08 PM in reply to: The_Caddie

you need to get started by reaing the Autocad VB.net developers guide

 

http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html

 

First you need to install MicroSoft Visual Studio VB.net (Express version is free)

 

Then add references to the required AutoCad files which allow Visual Studio VB to access the Autocad .net libraries. Configure Visual Studio for the right version of .NET depending on your version of AutCAD.

 

Create a userform and code, then compile to a DLL which is loaded into AutoCAD using "NETLOAD" AutoCAD command.

 

Hallex described the details to help you after you do the other things first.

 

 

 

 

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.