PDA

View Full Version : AutoCAd and VB.net



rahulp
11th May 2009, 06:37 am
i have an application where i need to create autoCAD drawing on a button click event.
i did some search and found that we can do this using
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

but i am not able to find exact example of how to create a new drawing.
i had got a nice article which gave the entire code in VB6, can i convert it to vb.net, if so how?
the following is vb6 code
Sub Main()
Dim xAP As Excel.Application
Dim xWB As Excel.Workbook
Dim xWS As Excel.Worksheet
Set xAP = Excel.Application
Set xWB = xAP.Workbooks.Open("C:\A2K2_VBA\IUnknown.xls")
Set xWS = xWB.Worksheets("Sheet1")
MsgBox "Excel says: """ & Cells(1, 1) & """"

Dim A2K As AcadApplication
Dim A2Kdwg As AcadDocument
Set A2K = CreateObject("AutoCAD.Application")
Set A2Kdwg = A2K.Application.Documents.Add
MsgBox A2K.Name & " version " & A2K.Version & _
" is running."

Dim Height As Double
Dim P(0 To 2) As Double
Dim TxtObj As AcadText
Dim TxtStr As String
Height = 1
P(0) = 1: P(1) = 1: P(2) = 0
TxtStr = Cells(1, 1)
Set TxtObj = A2Kdwg.ModelSpace.AddText(TxtStr, _
P, Height)

A2Kdwg.SaveAs "C:\A2K2_VBA\IUnknown.dwg"
A2K.Documents.Close
A2K.Quit
Set A2K = Nothing

xAP.Workbooks.Close
xAP.Quit
Set xAP = NothingEnd Sub
Please Help me :huh: