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

Unable to get reference to AutoCAD application. Using vb.NET.

0 REPLIES 0
Reply
Message 1 of 1
gdimitro6BBER
149 Views, 0 Replies

Unable to get reference to AutoCAD application. Using vb.NET.

Good evening. I am a newbie when it comes to coding in vb.NET in conjunction with AutoCAD.

I have loaded the COM files for AutoCAD.

I'm trying to reference AutoCAD when my executable starts and bind it to the CADApp variable and when I press the btn1 button AutoCAD should come to the foreground for the user to pick a point manually.

Here is a snippet of my code

Imports Microsoft.VisualBasic.Interaction
Public Class FormMain
    Private CADApp As Object 'AutoCAD application object
    Private Editor As Object 'AutoCAD editor object
    Private CADDoc As Object 'Autocad current Document
    Dim moSpace As Object
    Dim UtilObj As Object
Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Try 'to connect to the AutoCAD application
        CADApp = Interaction.GetObject(, "AutoCAD.Application")
        If CADApp Is Nothing Then
            MessageBox.Show("Failed to get reference to AutoCAD application")
        End If
    Catch ex As Exception
        MsgBox("AutoCAD not Running...trying to open")
        Try
            CADApp = CreateObject("AutoCAD.Application")
            'showMessageWhenConnectedToACAD()
        Catch ex1 As Exception
            MsgBox("Cannot connect to AuToCAD")
        End Try
    End Try
    CADApp.Visible = True
    CADDoc = CADApp.ActiveDocument
    moSpace = CADDoc.ModelSpace
    UtilObj = CADDoc.Utility
    End Sub
    Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
        ' Optional: Bring AutoCAD window to the front
        CADApp.Visible = True
        CADDoc = CADApp.ActiveDocument

    End Sub
End Class

 Unfortunately every time I run the code it always gets stuck in line 13, meaning the program is unable to reference AutoCAD. I don't know what I'm doing wrong. Can anyone help with this?

Tags (2)
Labels (3)
0 REPLIES 0

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report