首先我们看下CAD中画圆在vba中的语法:
vba中圆心坐标为变体变量variant,而vb.net中无variant这以数据类型,较为接近的有object类型,但是运行时会保存,经调试,改为double类型可正常运行。
代码如下:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cad As Object
Try
cad = GetObject("autocad.Application")
Catch ex As Exception
cad = CreateObject("autocad.Application")
End Try
cad.Visible = True
cad.documents.Add
For i = 1 To 100
Dim center(0 To 2) As Double
center(0) = i : center(1) = 2 * i
Dim radius As Double = 2
cad.activedocument.modelspace.AddCircle(center, radius)
Next i
cad.zoomextents
MsgBox("ok")
Me.Dispose(True)
End Sub
End Class
活到老学到老,每天进步一点,加油!