Accessing AutoCAD via a VB .NET form

Accessing AutoCAD via a VB .NET form

Anonymous
Not applicable
6,220 Views
24 Replies
Message 1 of 25

Accessing AutoCAD via a VB .NET form

Anonymous
Not applicable
I am working on an existing program that a colleague of mine started and I have inherited to make work (the employee is no longer with our company). It is a VB Windows Application project that contains a form. The form allows the user to browse and select dwg files that will then be used to create plot files. I am running into an error message when I first try to access AutoCAD. Here is what I have so far:

Imports System
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices

Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application


Public Class frmMain
Inherits System.Windows.Forms.Form


Public dwgBrowse As String
Public pltBrowse As String

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'load set defaults for paper tabs
Me.Text = "PBK Plot Utility " & System.Windows.Forms.Application.ProductVersion


End Sub

Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click



Dim x As Integer
Dim sWait As Integer = 0

acadApp.MainWindow.Visible = True
End Sub


There is a lot more to the program (I haven't included all the routines that browse and select files, for example), but this is what I'm trying to accomplish right now. When the program gets to the line:

acadApp.MainWindow.Visible = True,

It highlights the line:

Public Class frmMain

And I get the following error:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in system.windows.forms.dll
Additional information: File or assembly name acmgd, or one of its dependencies, was not found.

I have loaded acmgd.dll and acdbmgd.dll into the References. I am running AutoCAD 2006 and Visual Studio 2003. Any help would be greatly appreciated.

Thanks,
Christy
0 Likes
6,221 Views
24 Replies
Replies (24)
Message 21 of 25

Anonymous
Not applicable
Christy,

I'm trying to get a VB app (not VBA) to run inside AutoCAD 2004...do you think you could help me get this working?

I have the simplest of VB programs (dropping in an MText entity)...trying to use VB 2005 to do this.

I know there are issues with using wrappers, but I'd still like to explore this combination of programs...(soon to be moving on to ACAD 2008)...

Many thanks!

Pete
0 Likes
Message 22 of 25

Anonymous
Not applicable
Mike,

You wrote: "Reply From: mike.king
Date: Dec/02/05 - 07:43 (EST)

Re: Accessing AutoCAD via a VB .NET form
I am currently working on a series of posts about this topic on my blog (http:\\snippetsandmusings.blogspot.com). I know this is a transparent effort to get some hits, but actually it is a lot easier to lay things out and present a thorough tutorial in one's own space. Also, I am doing it anyway so why duplicate code (it's a sin). "

I tried accessing the blogspot but it says I must be invited. How about it?
0 Likes
Message 23 of 25

Anonymous
Not applicable
How do we get access to your blog? It seems to be by invitation only?
0 Likes
Message 24 of 25

Anonymous
Not applicable
An invitation-only blog ?

Lol. What a riot.

Don't waste your time.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5694786@discussion.autodesk.com...
How do we get access to your blog? It seems to be by invitation only?
0 Likes
Message 25 of 25

Anonymous
Not applicable

I could do it as below code, which is similar to VBA coding.

When you add reference, you need to browse "Autodesk.autoCAD.Interop.dll" and "Autodesk.autoCAD.Interop.Common.dll" from AutoCAD installation directory.

 

===================================================================

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

 

Public Class frm_Main

 

    Dim AcadApp As New Autodesk.AutoCAD.Interop.AcadApplication
    Dim AcadDoc As Autodesk.AutoCAD.Interop.AcadDocument
    Dim ThisDwg As String

 

    '----Open blank drawing in C:\, Event when form load.

    Private Sub frm_Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ThisDwg = "C:\Test.dwg"

        AcadDoc = AcadApp.ActiveDocument
        AcadDoc.Application.Documents.Open(ThisDwg)
        AcadDoc = AcadApp.ActiveDocument
        AcadApp.Visible = True

    End Sub

 

    '----Event for button click

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim lineObj As AcadLine

        Dim Point1(2) As Double
        Dim Point2(2) As Double
        Dim Point3(2) As Double
        Dim Point4(2) As Double

 

        Point1(0) = 0 : Point1(1) = 0
        Point2(0) = 1 : Point2(1) = 1
        Point3(0) = 2 : Point3(1) = 1
        Point4(0) = 3 : Point4(1) = 4

        lineObj = AcadDoc.ModelSpace.AddLine(Point1, Point2)
        lineObj = AcadDoc.ModelSpace.AddLine(Point2, Point3)
        lineObj = AcadDoc.ModelSpace.AddLine(Point3, Point4)

 

    End Sub


End Class

0 Likes