如题,我现在分别把vb6和vb2008中的代码贴出来:
vb6的代码:
Dim acadApp As Object
Dim Thisdrawing As Object
Sub ConnectToAcad()
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
If Err.Number Then MsgBox Err.Description
End If
acadApp.documents.Add
Set Thisdrawing = acadApp.ActiveDocument
Dim newlayer As Object
Set newlayer = Thisdrawing.Layers.Add("lll")
Thisdrawing.ActiveLayer = Thisdrawing.Layers.Item("lll")
Dim plineObj As Object
Dim points(0 To 5) As Double
' 在模型空间中创建一个优化多段线对象
Set plineObj = Thisdrawing.ModelSpace.AddLightWeightPolyline(points)
Thisdrawing.Application.ZoomAll
End Sub
Private Sub Command1_Click()
Call ConnectToAcad
End Sub
vb2008的代码:
Public Class Form1
Dim acadApp As Object
Dim Thisdrawing As Object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call ConnectToAcad()
End Sub
Private Sub ConnectToAcad()
On Error Resume Next
acadApp = GetObject(, "AutoCAD.Application")
If Err.Number Then
Err.Clear()
acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
If Err.Number Then MsgBox(Err.Description)
End If
acadApp.documents.Add()
Thisdrawing = acadApp.ActiveDocument
Dim newlayer As Object
newlayer = Thisdrawing.Layers.Add("lll")
Thisdrawing.ActiveLayer = Thisdrawing.Layers.Item("lll")
' 在模型空间中创建一个优化多段线对象
Dim plineObj As Object
Dim points(0 To 5) As Double
' 定义二维多段线的点
points(0) = 2 : points(1) = 4
points(2) = 4 : points(3) = 2
points(4) = 6 : points(5) = 4
plineObj = Thisdrawing.ModelSpace.AddLightWeightPolyline(points)
Thisdrawing.Application.ZoomAll()
End Sub
End Class