我想使用excelvba在autocad中绘制一条线。 我尝试了以下代码,但它显示了一些运行时错误显示"对象不支持此属性或方法"在最后一行。 请帮我解决这个问题。
Dim point1(1 To 3) As Double
Dim point2(1 To 3) As Double
Dim lineobj As Object
Dim myapp As Object
Dim AcadDwg As AcadDocument
Sub access_autocad()
On Error GoTo ERRORHANDLER
Set myapp = GetObject(, "autocad.application")
ERRORHANDLER:
If Err.Description <> "" Then
Set myapp = CreateObject("autocad.application")
End If
myapp.Visible = True
Set AcadDwg = myapp.ActiveDocument
point1(1) = 0: point1(2) = 0
point2(1) = 1: point2(2) = 1
Set lineobj = AcadDwg.AddLine(point1, point2)
End Sub
答案 0 :(得分:0)
您只需进行一次更改即可。在倒数第二行,更改:
Set lineobj = AcadDwg.AddLine(point1, point2)
要:
Set lineobj = AcadDwg.ModelSpace.AddLine(point1, point2)