rahulp Posted May 11, 2009 Posted May 11, 2009 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 Quote
bsamc2000 Posted May 11, 2009 Posted May 11, 2009 This should get you started. You could also just run the program inside of AutoCAD as a dll. [size=2][color=#0000ff][size=2][color=#0000ff]Imports[/color][/size][/color][/size][size=2] Autodesk.AutoCAD.Interop[/size] [size=2][color=#0000ff][size=2][color=#0000ff]Try[/color][/size] [/color][/size] [size=2] vAcadApp = GetObject([/size][size=2][color=#a31515][size=2][color=#a31515]"AutoCAD.Application"[/color][/size][/color][/size][size=2])[/size] [size=2][color=#0000ff][size=2][color=#0000ff]Catch[/color][/size][/color][/size][size=2] ex [/size][size=2][color=#0000ff][size=2][color=#0000ff]As[/color][/size][/color][/size][size=2] Exception[/size] [size=2] vAcadApp = CreateObject([/size][size=2][color=#a31515][size=2][color=#a31515]"AutoCAD.Application"[/color][/size][/color][/size][size=2])[/size] [size=2][color=#0000ff][size=2][color=#0000ff]End[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]Try[/color][/size] [/color][/size] [size=2]vAcadApp.Visible = [/size][size=2][color=#0000ff][size=2][color=#0000ff]True[/color][/size] [/color][/size] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.