.NET

Reply
*Nate Hunter
Message 1 of 11 (154 Views)

AutoCAD 2006 reference in VB 2005

154 Views, 10 Replies
11-17-2005 08:31 AM
I am a new VB 2005 programmer that is converting from VB6. Many of my VB6
programs do the following:

I reference AutoCAD 2006 Type Library then under the

Option Explicit
Public MyAcad As AutoCAD.AcadApplication
Public ThisDrawing As AutoCAD.AcadDocument


In VB2005 I try the same thing and get Type AutoCAD.AcadApplication is not
defined
So I tried:
Public MyAcad As AutoDesk.AutoCAD.Interop.AcadApplication
Public ThisDrawing As AutoDesk.AutoCAD.Interop..AcadDocument

The MyAcad will run but the ThisDrawing still does not.

Any help would be appreciated!!
Active Contributor as
Active Contributor
as
Posts: 41
Registered: ‎04-27-2005
Message 2 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-18-2005 04:05 AM in reply to: *Nate Hunter
I have created the function as show beneath in VB.Net 2003, it functions wel:

Friend Function DrawLine2D(ByVal StartPoint As Point2d, ByVal EndPoint As Point2d, ByVal Layer As AcadLayer) As AcadLine
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim nLine As AcadLine

Try
acadApp = CType(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, AcadApplication)
acadApp.Visible = True
acadDoc = acadApp.ActiveDocument
acadDoc.Application.Visible = True
nLine = acadDoc.ModelSpace.AddLine(Point2DToArray3D(StartPoint), Point2DToArray3D(EndPoint))
nLine.Layer = Layer.Name

Return nLine

Catch ex As Exception
MessageBox.Show(ex.ToString)
Return nLine

End Try
End Function


Maybe it helps you, otherwise come back again

Harold van Aarsen
*Nate Hunter
Message 3 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-21-2005 11:55 AM in reply to: *Nate Hunter
I tried:
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument

I am using the COM reference of AutoCAD 2006 Type Library.

Should I be using something else.

When I do the above AcadApplication & AcadDocument are not recognised.

I better stop writing applications. I thought VB6 to VB.Net was suppose to
be a seamless transition. Sorry I am venting a little.

Nate

wrote in message news:5017208@discussion.autodesk.com...
I have created the function as show beneath in VB.Net 2003, it functions
wel:

Friend Function DrawLine2D(ByVal StartPoint As Point2d, ByVal
EndPoint As Point2d, ByVal Layer As AcadLayer) As AcadLine
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim nLine As AcadLine

Try
acadApp =
CType(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication,
AcadApplication)
acadApp.Visible = True
acadDoc = acadApp.ActiveDocument
acadDoc.Application.Visible = True
nLine =
acadDoc.ModelSpace.AddLine(Point2DToArray3D(StartPoint),
Point2DToArray3D(EndPoint))
nLine.Layer = Layer.Name

Return nLine

Catch ex As Exception
MessageBox.Show(ex.ToString)
Return nLine

End Try
End Function


Maybe it helps you, otherwise come back again

Harold van Aarsen
Contributor
Khalique
Posts: 14
Registered: ‎11-14-2005
Message 4 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-21-2005 12:43 PM in reply to: *Nate Hunter
Did you import the name spaces for referenced autacad libraries? If not, following may help.
You need to include “Imports…….” statement at the beginning of the file where other ‘Imports’ statement are.
In Visual Studiio 2003, to find out what namespaces you need to include, expand ‘References’ under your ‘Solution’ in SolutionExplorer. Select the reference and then check its Properties in the Properties window. In the name field you will find something like this “Autodesk.AutoCad….”. This is what you need to Import.
If you do not import referenced namespaces, you will have to use statement like this:
Dim app as Autodesk.AutoCAD.Interop.AcadApplication

kr
*Nate Hunter
Message 5 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-21-2005 12:47 PM in reply to: *Nate Hunter
Here is exactly what I am trying:
Public Class Form1

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

Dim MyAcad As Autodesk.AutoCAD.Interop.AcadApplication

Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument



ThisDrawing = MyAcad.ActiveDocument ' (I get an error here stating MyAcad
has not been set)

MsgBox(ThisDrawing.Name)

End Sub

End Class







"Nate Hunter" wrote in message
news:5019338@discussion.autodesk.com...
I tried:
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument

I am using the COM reference of AutoCAD 2006 Type Library.

Should I be using something else.

When I do the above AcadApplication & AcadDocument are not recognised.

I better stop writing applications. I thought VB6 to VB.Net was suppose to
be a seamless transition. Sorry I am venting a little.

Nate

wrote in message news:5017208@discussion.autodesk.com...
I have created the function as show beneath in VB.Net 2003, it functions
wel:

Friend Function DrawLine2D(ByVal StartPoint As Point2d, ByVal
EndPoint As Point2d, ByVal Layer As AcadLayer) As AcadLine
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim nLine As AcadLine

Try
acadApp =
CType(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication,
AcadApplication)
acadApp.Visible = True
acadDoc = acadApp.ActiveDocument
acadDoc.Application.Visible = True
nLine =
acadDoc.ModelSpace.AddLine(Point2DToArray3D(StartPoint),
Point2DToArray3D(EndPoint))
nLine.Layer = Layer.Name

Return nLine

Catch ex As Exception
MessageBox.Show(ex.ToString)
Return nLine

End Try
End Function


Maybe it helps you, otherwise come back again

Harold van Aarsen
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 6 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-21-2005 01:22 PM in reply to: *Nate Hunter
VB6 to VB.NET is not a seamless transition. For more info.
http://msdn.microsoft.com/vbrun/staythepath/additionalresources/upgradingvb6/

Also have you thought about learning AutoCAD's .NET API rather than continuing to use ActiveX.

Regards - Nathan
Contributor
Khalique
Posts: 14
Registered: ‎11-14-2005
Message 7 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-21-2005 02:51 PM in reply to: *Nate Hunter
In .Net, VB behaves a bit differently.
When you Dim an object, the actual object is not created. To ceate an object after you have Declared the object, you need to do the following.
--
Dim MyAcad As Autodesk.AutoCAD.Interop.AcadApplication
Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument

MyAcad = New Autodesk.AutoCAD.Interop.AcadApplication (this creates the application object)
ThisDrawing = MyAcad.Documents.Open("drawing.dwg, false, mypassword")
Open method requires filename, ReadOnlyFlag (true or false depending on your requirement) and password ("Nothing" if none exists)
Hope this helps.
(This code example corresponds to Autocad 2005 libraries. Ido not have Autocad 2006)
kr Message was edited by: Khalique
*Nate Hunter
Message 8 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-22-2005 05:41 AM in reply to: *Nate Hunter
I would love to lean AutoCAD's .Net API. Is there any documentation out
there I could look at. I am a strong VB6 programmer that is trying to get
into the .Net side of things. All my programs are all designed around
AutoCAD & Access but the main focus is on AutoCAD. So if there is
documentation out there that could help me I would love to get my hands on
it.

I currently only have VBA books for AutoCAD.

Thanks for all your help


wrote in message news:5019465@discussion.autodesk.com...
VB6 to VB.NET is not a seamless transition. For more info.
http://msdn.microsoft.com/vbrun/staythepath/additionalresources/upgradingvb6/

Also have you thought about learning AutoCAD's .NET API rather than
continuing to use ActiveX.

Regards - Nathan
*Nate Hunter
Message 9 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-22-2005 10:57 AM in reply to: *Nate Hunter
I have found my solution!! Thanks for all your input. Here is what I did:

Public Class Form1
Dim MyAcad As Autodesk.AutoCAD.Interop.AcadApplication
Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MyAcad = GetObject(, "AutoCAD.Application.16")
ThisDrawing = MyAcad.ActiveDocument
MsgBox(ThisDrawing.Name)
End Sub

End Class

I would still be interested in any books or documentation any one could
point me to for VB.Net & AutoCAD

"Nate Hunter" wrote in message
news:5019916@discussion.autodesk.com...
I would love to lean AutoCAD's .Net API. Is there any documentation out
there I could look at. I am a strong VB6 programmer that is trying to get
into the .Net side of things. All my programs are all designed around
AutoCAD & Access but the main focus is on AutoCAD. So if there is
documentation out there that could help me I would love to get my hands on
it.

I currently only have VBA books for AutoCAD.

Thanks for all your help


wrote in message news:5019465@discussion.autodesk.com...
VB6 to VB.NET is not a seamless transition. For more info.
http://msdn.microsoft.com/vbrun/staythepath/additionalresources/upgradingvb6/

Also have you thought about learning AutoCAD's .NET API rather than
continuing to use ActiveX.

Regards - Nathan
Distinguished Contributor
NathTay
Posts: 1,691
Registered: ‎12-15-2003
Message 10 of 11 (154 Views)

Re: AutoCAD 2006 reference in VB 2005

11-22-2005 01:18 PM in reply to: *Nate Hunter
The .NET documentation is currently part of the ObjectARX documentation located here.
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=773180
And here are some labs.
http://discussion.autodesk.com/thread.jspa?messageID=4859028

Regards - Nathan
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.