.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
The_Caddie
11690 Views, 9 Replies

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

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?

9 REPLIES 9
Message 2 of 10
Hallex
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
Message 3 of 10
The_Caddie
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...

Message 4 of 10
The_Caddie
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)

Message 5 of 10
Hallex
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 🙂

 

~'J'~

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 10
The_Caddie
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

Message 7 of 10
Hallex
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
Message 8 of 10
dgorsman
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.
"I don't know" is the beginning of knowledge, not the end.


Message 9 of 10
The_Caddie
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)

Message 10 of 10
fxcastil
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.

 

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost