Home General VB.NET Get Started With AutoCad and VB.NET
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Get Started With AutoCad and VB.NET PDF Print E-mail
User Rating: / 3
PoorBest 
Tutorials

Using Visual Basic 2008 Express Edition you can create applications that can communicate with AutoCad. Download Visual Basic 2008 Express from the microsoft site for free (here).

NOTE you do need the ObjectArx to complete this tutorial.

1. OPEN VISUAL BASIC .NET

Open .NET and select Class Library.

"Impression of the New Project Window"

2. SELECT SHOW ALL

On the right in the Solution Explorer select the Show All button. (If the Solution Explorer is not visible then hit CTRL+ALT+L).

"Show All Button"

This will make the Reference tab visible.

3. SHOW REFERENCE WINDOW

Right Click the Reference tab and select "Add Reference".

4. SELECT AUTOCAD REFERENCE

In the reference window goto the BROWSE tab and browse to your AutoCad installation folder and add acdbmgd.dll and acmgd.dll. Both files are located in the C:\Program Files\AutoCad XXXX\ directory)

reference

"Reference Window"

5. IMPORT NAMESPACES

If you do not want to fully qualify everything then you can import the namespaces. Add the namespaces below to your class.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop.Common

 

6. READY FOR PROGRAMMING

Now that all references are set and namespaces are imported you can use VB.NET to communicate with AutoCad.

Add the code below to a class or Form with commandbutton to test the application.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput

 

 

tarted With Autocad

If this window appears then the tutorial has been succesfull! Well Done...

 

Public Class Class2

    Public Function StartAutoCADSession() As Object

        '*********************************************
        '*********Code from VisibleVisual.com*********
        '*********************************************

        On Error Resume Next

        Dim AcadApp As Object
        'Check if a AutoCad session Exists
        AcadApp = GetObject(, "AutoCAD.Application")
        If Err.Number <> 0Then
            Err.Clear()
            'If there is no AutoCad session active then there will be one created
            AcadApp = CreateObject("AutoCAD.Application")
        End If

        If Err.Number <> 0 Then
            StartAutoCADSession = Nothing
            Exit Function
        End If

        'if successful set visibility status
        AcadApp.Visible = 1
        'opened OK
        Return AcadApp

    End Function

    Sub TestNETprogram()

        Dim AcadApp As Object
        Dim AcadDoc As Object
        Dim prompt1
As String
        Dim pnt As Object

       AcadApp = StartAutoCADSession()
       AcadApp.Visible = True

        AcadDoc = AcadApp.Activedocument

        prompt1 = vbCrLf & "Enter block insert point: "
        pnt = AcadApp.Activedocument.Utility.GetPoint(, prompt1)

        MsgBox("You have selected the folowing coordinates:" _
                & vbCr & "X: " & pnt(0) _
                & vbCr & "Y: " & pnt(1) _
                & vbCr & "Z: " & pnt(2))
    End Sub

End Class


test

 

 

 

"Set Reference"
Attachments:
FileDescriptionFile sizeDownloads
Download this file (StartAutoCad Session.zip)StartAutoCad Session.zipGet Started With Autocad. NET15 Kb796
 

Comments   

 
0 #1 Guest 2011-07-17 17:44
Awesome, thanks! going in the library.
Quote
 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade