|
如题,我现在分别把vb6和vb2008中的代码贴出来:
vb6的代码:
Dim acadApp As Object
Dim Thisdrawing As Object
Sub ConnectToAcad()
On Error Resume Next
Set acadApp = GetObject(, ".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
' 定义二维多段线的点
points(0) = 2: points(1) = 4
points(2) = 4: points(3) = 2
points(4) = 6: points(5) = 4
' 在模型空间中创建一个优化多段线对象
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
分别运行后,vb6中可以将图层“lll”设置为当前图层,但是vb2008没有,可是vb2008也没有报错,请问是怎么回事?对后者出现的问题有没有什么解决办法?
|
|