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

AutoCAD 2006 reference in VB 2005

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
582 Views, 10 Replies

AutoCAD 2006 reference in VB 2005

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!!
10 REPLIES 10
Message 2 of 11
as
in reply to: Anonymous

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
Message 3 of 11
Anonymous
in reply to: Anonymous

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
Message 4 of 11
Khalique
in reply to: Anonymous

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
Message 5 of 11
Anonymous
in reply to: Anonymous

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
Message 6 of 11
NathTay
in reply to: Anonymous

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
Message 7 of 11
Khalique
in reply to: Anonymous

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
Message 8 of 11
Anonymous
in reply to: Anonymous

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
Message 9 of 11
Anonymous
in reply to: Anonymous

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
Message 10 of 11
NathTay
in reply to: Anonymous

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
Message 11 of 11
Anonymous
in reply to: Anonymous

Using GetObject(, "AutoCAD.Application.16") is a bad idea as if there are
multiple sessions of acad running you cannot garuntee that it will get the
acad you app is loaded in

in C# I use
Autodesk.AutoCAD.Interop.AcadApplication _AcadApp =
(AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplic
ation;
or VB
Dim _AcadApp Autodesk.AutoCAD.Interop.AcadApplication =
Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;


Mark
"Nate Hunter" wrote in message
news:5020349@discussion.autodesk.com...
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

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