推荐一本书:visual basic .net二次开发 AutoCAD,清华大学出版社
画图之前,先添加引用autocad 2004 type library 及
然后连接autocad
Imports Autodesk Imports Autodesk.AutoCAD.Interop Imports Autodesk.AutoCAD.Interop.Common
Dim cadApp As AcadApplication
'获得应用程序进程 cadApp = GetObject(, "AutoCAD.AcadApplication")
If Err.Number Then Err.Clear() Try '定义一个进程 Dim cadprocess As New Process '进程启动可执行文件 'cadprocess.Start("D:\Program Files\AutoCAD 2006\acad.exe")
'创建应用程序进程 cadApp = CreateObject("AutoCAD.AcadApplication") Catch ex As Exception If Err.Number Then MsgBox("不能启动AutoCAD,请检查是否安装!或文件路径是否正确!") End If End Try '软件可见 'cadApp.Visible = True '软件成最大化状态 'cadApp.WindowState = Common.AcWindowState.acMax '显示软件界面 'AppActivate(cadApp.Caption) End If
cadApp.Documents.Add()
Dim newline As AcadLine
Dim spoints(2), epoints(2) As Double spoints(0) = 0 : spoints(1) = 100 epoints(0) = 0 : epoints(1) = 100
newline = cadApp.ActiveDocument.ModelSpace.AddLine(spoints, epoints)
cadApp.ZoomAll() |