<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Unable to get reference to AutoCAD application. Using vb.NET. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/unable-to-get-reference-to-autocad-application-using-vb-net/m-p/12723367#M4358</link>
    <description>&lt;P&gt;Good evening. I am a newbie when it comes to coding in vb.NET in conjunction with AutoCAD.&lt;/P&gt;&lt;P&gt;I have loaded the COM files for AutoCAD.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here is a snippet of my code&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Unfortunately every time I run the code it always gets stuck in &lt;STRONG&gt;line 13&lt;/STRONG&gt;, meaning the program is unable to reference AutoCAD. I don't know what I'm doing wrong. Can anyone help with this?&lt;/P&gt;</description>
    <pubDate>Sun, 21 Apr 2024 15:13:59 GMT</pubDate>
    <dc:creator>gdimitro6BBER</dc:creator>
    <dc:date>2024-04-21T15:13:59Z</dc:date>
    <item>
      <title>Unable to get reference to AutoCAD application. Using vb.NET.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-get-reference-to-autocad-application-using-vb-net/m-p/12723367#M4358</link>
      <description>&lt;P&gt;Good evening. I am a newbie when it comes to coding in vb.NET in conjunction with AutoCAD.&lt;/P&gt;&lt;P&gt;I have loaded the COM files for AutoCAD.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here is a snippet of my code&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Unfortunately every time I run the code it always gets stuck in &lt;STRONG&gt;line 13&lt;/STRONG&gt;, meaning the program is unable to reference AutoCAD. I don't know what I'm doing wrong. Can anyone help with this?&lt;/P&gt;</description>
      <pubDate>Sun, 21 Apr 2024 15:13:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-get-reference-to-autocad-application-using-vb-net/m-p/12723367#M4358</guid>
      <dc:creator>gdimitro6BBER</dc:creator>
      <dc:date>2024-04-21T15:13:59Z</dc:date>
    </item>
  </channel>
</rss>

