1、在引用项中,AutoCAD XXX打勾。 2、用object方法。 在VB中,引用引用选择Autocad,可以像在AutoCAD一样操作方便。 问题存在(AutoCad不同版本问题), Private Sub Form_Load() Dim ojbLine As AcadLine Dim pp(0 To 2) As Double, ppp(0 To 2) As Double For jj = 0 To 1 pp(jj) = jj ppp(jj) = jj * 5 Next jj Set objline = objModelSpace.AddLine(pp, ppp) Dim xlSheet1 As Worksheet Set xlSheet1 = xlsMdb.xlSheet For ii = 1 To 10 xlSheet1.Cells(ii, 2) = ii Next ii End Sub Function objModelSpace() As AcadModelSpace Dim appAutoCad As AutoCAD.AcadApplication On Error Resume Next Set appAutoCad = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set appAutoCad = CreateObject("AutoCAD.Application") End If appAutoCad.Visible = True Dim AcadDoc As AcadDocument Set AcadDoc = appAutoCad.ActiveDocument 'Dim objModelSpace As AcadModelSpace Set objModelSpace = AcadDoc.ModelSpace End Function 用object方法操作不能像在autocad中自如。但不存在版本问题。!! Dim obj_Acad As Object, obj_Doc As Object, obj_ModelSpace As Object Dim boo As Boolean Public Sub AutoCADConnect() '连接AutoCAD On Error Resume Next Set obj_Acad = GetObject(, "autocad.application") If Err Then Err.Clear On Error Resume Next Set obj_Acad = CreateObject("autocad.application") If Err Then Err.Clear MsgBox "不能运行AutoCAD,请检查是否安装!", vbOKOnly, "警告!" Exit Sub End If End If obj_Acad.Visible = True Set obj_Doc = obj_Acad.ActiveDocument Set obj_ModelSpace = obj_Doc.ModelSpace MsgBox "运行结束!", vbOKOnly, "工程1!" boo = True End Sub Private Sub Command1_Click() Call AutoCADConnect '调用连接AutoCAD的子程序 End Sub
|