Hello. Me and my colleagues are trying to program an AutoCAD application using VB.NET (actually, VB 2008). We followed the below procedure closely:
AutoCAD programming using VB.Net, C#.Net, AutoCAD Customization using Net
You can program AutoCAD using VB.Net/C#.Net using following methos:
1. Using ObjectARX managed wrapper classes
2. Using AutoCAD COM APIs
3. Using combination of both
If you are currently using AutoCAD VBA then you can use AutoCAD COM APIs to start AutoCAD programming using .Net immediately.
Procedure to use AutoCAD COM API with .Net is explained below:
- Start Microsoft Visual Studio 2005
- Create a new Class Library project in VB.Net
- Add reference to AutoCAD Type Library (acax17enu.tlb), AutoCAD / ObjectDBX Common Type Library (axdb17enu.tlb), acdbmgd.dll and acmgd.dll.
- Type the following code (This code creates a line)
Imports Autodesk.AutoCAD.Runtime
Public Class Class1
<'CommandMethod("MyLine")> _
Public Shared Sub CreateLine()
Dim AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim acaddoc As Autodesk.AutoCAD.Interop.AcadDocument
Dim pt As Object
Dim pt1 As Object
AcadApp = GetObject(, "Autocad.Application")
acaddoc = AcadApp.ActiveDocument
pt = acaddoc.Utility.GetPoint(, "Pick point:")
pt1 = acaddoc.Utility.GetPoint(pt, "Pick second point:")
acaddoc.ModelSpace.AddLine(pt, pt1)
End Sub
End Class
- Build Solutions
- Start AutoCAD
- Give NetLoad command
- Select dll file created by above application
- Once the loading is completed you can give MyLine command to take the trial of above program.
__________________________________________________ ____
However, with all the necessary adage of references intact, we encountered this error:
"A project with an Output Type of Class Library cannot be started directly. In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project"
What could be the solution to this? We foremost tried building the project without clicking F5 after creating a Windows app and changing the startup page, left with scant measures (i.e. double-checking the references if they are complete)to determine the best possible solution instantly.