VBA代码: Dim aa As New 工程1.Class1 Sub ff() aa.xuexi3 End Sub VB代码: Option Explicit Public Function addline(ByVal document As AcadDocument, ByVal ptSt As Variant, ByVal ptEn As Variant) As AcadLine Set addline = document.ModelSpace.addline(ptSt, ptEn) End Function Sub ABC() On error resume next Dim objline As AcadLine Dim acadapp As AcadApplication Dim acaddoc As AcadDocument Set acaddoc = acadapp.ActiveDocument Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double pt1(0) = 10: pt1(1) = 10: pt1(2) = 0 pt2(0) = 150: pt2(1) = 150: pt2(2) = 0 Set objline = acaddoc.ModelSpace.addline(pt1, pt2) objline.Update End Sub Sub xuexi3() Dim acadapp As Object 'AcadApplication ' Dim acaddoc As Object Set acadapp = GetObject(, "AutoCAD.Application") Set acaddoc = acadapp.ActiveDocument acadapp.WindowState = acMax Call ABC End Sub |