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

Accessing AutoCAD via a VB .NET form

24 REPLIES 24
Reply
Message 1 of 25
cctbailey
2811 Views, 24 Replies

Accessing AutoCAD via a VB .NET form

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
24 REPLIES 24
Message 2 of 25
Anonymous
in reply to: cctbailey

Is this a windows application (e.g., an .EXE file) or a DLL
that you are loading into AutoCAD via NETLOAD?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:5025884@discussion.autodesk.com...
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
Message 3 of 25
cctbailey
in reply to: cctbailey

A windows application (.exe file).

Thanks,
Christy
Message 4 of 25
Anonymous
in reply to: cctbailey

You can't use the managed wrappers for ObjectARX
in a standalone application, or from any other process.

They can only be used by a DLL that's loaded into
AutoCAD using NETLOAD.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:5026149@discussion.autodesk.com...
A windows application (.exe file).

Thanks,
Christy
Message 5 of 25
cctbailey
in reply to: cctbailey

Am I correct in my understanding that you cannot use forms with the DLL that's loaded into AutoCAD? In other words, there's no way to do what I'm trying to do with VB .NET, but rather I need to use VBA?

Thanks,
Christy
Message 6 of 25
cctbailey
in reply to: cctbailey

Or, would it be possible to create dll files for the AutoCAD stuff I need to do, and then use those dlls in a WIndows application so that I can have that functionality inside a windows (.exe) application? I've read some things that make it sound like I could do that. Would it work? Or would it still be better to use VBA?

Thanks,
Christy
Message 7 of 25
Anonymous
in reply to: cctbailey

I have had success using the .NET wrapper classes from out of process by exposing them with a DLL loaded in AutoCAD and then accessing that via .NET remoting. If this sounds like what you are looking for let me know and I will try to put together a code sample.
Message 8 of 25
Anonymous
in reply to: cctbailey

You can use forms in a DLL that's loaded into AutoCAD.

What you can't do, is load a DLL that uses AutoCAD's
managed API into another process.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:5026543@discussion.autodesk.com...
Am I correct in my understanding that you cannot use forms with the DLL that's loaded into AutoCAD? In other words, there's no way to do what I'm trying to do with VB .NET, but rather I need to use VBA?

Thanks,
Christy
Message 9 of 25

hi mike,
i am also looking for same kind of code.if you will send the code , i will be more thankful to you.
Message 10 of 25
Anonymous
in reply to: cctbailey

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).
Message 11 of 25
cctbailey
in reply to: cctbailey

Thanks everyone, for the information. I would be very interested in some code/example. I have been asked to try and make this work in VB .NET instead of VBA, however I am finding that VB .NET is a whole different ball of wax than VB. Any help would be greatly appreciated, as I am pretty much completely confused now (it seems that what I want to do is possible, but I'm not sure yet how to pull it off). I will check out your blog.

Christy
Message 12 of 25
Mikko
in reply to: cctbailey

Here's a quick very basic exe 10 minute HOW TO that may be of help.
Using Visual Studio 2005 and AutoCAD 2006.
Message 13 of 25
cctbailey
in reply to: cctbailey

I have Visual Studio 2003, and can't open this example. Can it be saved back to the 2003 version?

Thanks,
Christy
Message 14 of 25
Mikko
in reply to: cctbailey

Just create a new windows app with 2003. Set a reference to AutoCAD/ObjectDBX Common 16.0 Type Library and the AutoCAD 2006 Type Library. Add four buttons called Go, WholeDirectory, ClearList and RetrieveDwgs. Add a list box. Add a FolderBrowserDialog and OpenFileDialog control. Unzip that 2005 app and open the Form1.vb form with textpad, notepad or some such thing and cut and paste the code from that form into your code behide form in your app. You'll need to rem out one of the two acadDoc.Close(False, ThisDwg). One is in the processdwg sub and the other is in the in the try catch statment in the go sub, you only can close the drawing once so the existing code I posted has an error in it.
I don't have 2003 running at the moment.
Message 15 of 25
cctbailey
in reply to: cctbailey

OK, I am confused. Tony posted above that you can't use the managed wrappers for ObjectARX in a standalone application, however an example of a Windows application that accesses AutoCAD has been posted by Mikko above. What gives? Is Mikko not using the Managed Wrappers for Object ARX? It doesn't really matter to me how it works as long as it works. I have spend the last week and a half trying to figure out how to create a windows application that calls a dll as you have suggested, and then when I finally look at this example, there is no dll involved. Please help me understand!!

Thanks so much for your help.
Christy Message was edited by: cctbailey
Message 16 of 25
Anonymous
in reply to: cctbailey

AutoCAD exposes a number of API's. The newest is the .NET API. It has
exposed a COM API since R2000. Well, R14 if you want to get picky. The
.NET API is what is being referred to when someone says Managed Wrappers for
ObjectARX.

Here's where you are getting confused. Mikko's .NET app is targeting the
COM API, not the .NET API. Just because he is using VB.NET don't assume
that his code accessing the AutoCAD .NET API.

The COM API allows you to run code out of process with AutoCAD, just like
Mikko's code shows. However, it's important that you understand the
performance implications if you go this route. IOW, it's slow as molasses
in February. Also, the COM API exposes a completely different set of types
than the .NET API. If this isn't a concern for your app and the COM types
handle everything you need, then this is a simple route to go.

It is possible to write a windows app that runs out of process from AutoCAD
but loads a dll in process with it, eliminating the performance issue.
However this is done via COM and you will have to expose your .NET assembly
to COM in order to take advantage of it.
--
Bobby C. Jones
http://www.acadx.com

wrote in message news:5035777@discussion.autodesk.com...
OK, I am confused. Tony posted above that you can't use the managed
wrappers for ObjectARX in a standalone application, however an example of a
Windows application that accesses AutoCAD has been posted by Mikko above.
What gives? Is Mikko not using the Managed Wrappers for Object ARX? It
doesn't really matter to me how it works as long as it works. I have spend
the last week and a half trying to figure out how to create a windows
application that calls a dll as you have suggested, and then when I finally
look at this example, there is no dll involved. Please help me understand!!

Thanks so much for your help.
Christy

Message was edited by: cctbailey
Message 17 of 25
cctbailey
in reply to: cctbailey

Thanks so much for the clarification - it's starting to make sense to me, although it's still a little unclear since I'm pretty new to .NET (I've done plenty of VBA programming in AutoCAD, and some Visual Basic windows application programming years ago).

So I guess my question is, what would you use to write this program? Basically, I am trying to allow the user to select drawings, and the program will create plt files, with an option to plot the files as well. My boss has asked that I try to make this work in VB .NET, since it is "the wave of the future", but what would you recommend?

Thanks again,
Christy
Message 18 of 25
Anonymous
in reply to: cctbailey

Well, I personally would explain to the boss that what tool to use for any
given application probably shouldn't be driven by Microsoft catch phrases
:-) I would review the specifications, your current AutoCAD version and
your upgrade plans, your own knowledge, your timeline, and any number of
other variables before making that decision.

I haven't yet touched the acad .NET plot API, so I can't give you any
specific advise on it at all. I have used the COM plot API, but not to do
what you are doing. I think that the COM API can handle it. If I were in
your shoes and I had the time, I'd at least research the .NET API.

Whether you go with the COM or the .NET API you can use VB.NET as your
coding environment.
--
Bobby C. Jones
http://www.acadx.com

wrote in message news:5035955@discussion.autodesk.com...
Thanks so much for the clarification - it's starting to make sense to me,
although it's still a little unclear since I'm pretty new to .NET (I've done
plenty of VBA programming in AutoCAD, and some Visual Basic windows
application programming years ago).

So I guess my question is, what would you use to write this program?
Basically, I am trying to allow the user to select drawings, and the program
will create plt files, with an option to plot the files as well. My boss
has asked that I try to make this work in VB .NET, since it is "the wave of
the future", but what would you recommend?

Thanks again,
Christy
Message 19 of 25
mahkan
in reply to: cctbailey

hi mike,
Wincadapp has helped me a lot for the progress in my project.....i have a small doubt..how to select the drawing which is opened using the wincadapp......it will be a great help if u send me the source code for selecting the drawing
thank you....
Mahesh
Message 20 of 25
jmodglin
in reply to: cctbailey

Christy,
Forgive me if I am about to ask a stupid question but why are you trying to create something that seems to exist? What you are trying to do seems to be available in the PUBLISH command.

Am I missing something??

Josh

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