vb和vb.net后期绑定cad后设置当前图层时为什么会有这样的差别?
如题,我现在分别把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
' 定义二维多段线的点
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也没有报错,请问是怎么回事?对后者出现的问题有没有什么解决办法?
用vb.net时, Thisdrawing.Active*这种都不起作用,但是也不报错,到底是怎么回事,我的问题贴出来好几天了,怎么没有人回答啊,论坛这么多高手,没有人好好研究研究吗? 用vb.net时, Thisdrawing.Active*这种都不起作用,但是也不报错,到底是怎么回事,我的问题贴出来好几天了,怎么没有人回答啊,论坛这么多高手,没有人好好研究研究吗? 你的vb.net不是真正的vb.net,是从vb6转过来的。 是的,我用的是vb6的那种方法,可是您说的这是问题的原因所在吗? lwd899 发表于 2011-7-24 14:36 static/image/common/back.gif
是的,我用的是vb6的那种方法,可是您说的这是问题的原因所在吗?
你好,加Q593122168,咱们的做法一样,希望能够探讨,你的这个问题可以解决,加我发你。 我也碰到这个问题,thisdrawing.layer可以添加图层,但thisdrawing.activelayer,就是不同用。求教啊 折腾一晚上,找到了一个折衷办法。用vb.net的Application.SetSystemVariable("CLAYER",“图层名”),可以解决。Thisdrawing.ActiveLayer确定是有的,但不知为何,在VS2010+AutoCAD2014下就是没法用。
页:
[1]