[求助]如何在VB.net开发Autocad时在创建选择集时加入过滤机制
看看下面的代码,不知有何错误?总是通不过,请各位大侠帮忙!Public AcadApp As AutoCAD.AcadApplication
Public CurrentDocument As AutoCAD.AcadDocument
Private Sub Test()
Try
AcadApp = GetObject(, "AutoCAD.Application")
Catch
AcadApp = CreateObject("AutoCAD.Application")
Finally
AcadApp.Visible = True
End Try
CurrentDocument = AcadApp.ActiveDocument
Dim sset As AutoCAD.AcadSelectionSet
Try
sset = CurrentDocument.SelectionSets.Item("NewSet")
sset.Clear()
Catch
sset = CurrentDocument.SelectionSets.Add("NewSet")
End Try
Dim FilterType(0) As Integer
Dim FilterData(0) As Object
FilterType(0) = 0
FilterData(0) = "Line"
sset.SelectOnScreen(FilterType, FilterData)
End Sub
VBA的基本用法
对于一些VBA的基本用法,可能你还不太了解。对于这句Dim FilterData(0) As Object,既然已经声明为对象型的,后面赋值时应该用Set 变量=对象,而你却用了FilterData(0) = "Line",这是对字符型进行赋值,明显错误。注:过滤机制中也没有用到对象型的数据。
在VB.net中给对象赋值无需使用Set
确实,在VB.Net中,对一些数据类型做了改变,原来的Variant类型已经被Object所取代。而对于数据类型占用的字节数,也发生了变化。如VB6的Integer类型被Short所取代。而VB6的Long类型被Integer所取代。上例中的Dim FilterType(0) As Integer应更改为Dim FilterType(0) As Short,才符合所占的字节长度。 Sub newselt(ByVal Ptt1 As Object, ByVal Ptt2 As Object)
myCad.ActiveDocument.Utility.Prompt("请等待...")
'创建选择集
On Error GoTo ERROR_HANDLER
sset = CreateSSet("ss1")
Dim mode As Integer
mode = AcSelect.acSelectionSetCrossing
Dim gpCode(0) As Object
Dim dataValue(0) As Object
gpCode(0) = 0
dataValue(0) = "LINE"
gpCode(0) = -4
dataValue(0) = "<Or"
gpCode(1) = -4
dataValue(1) = "<And"
gpCode(2) = 0
dataValue(2) = "LINE"
gpCode(3) = -4
dataValue(3) = "And>" gpCode(4) = -4
dataValue(4) = "<And"
gpCode(5) = 0
dataValue(5) = "POLYLINE"
gpCode(6) = -4
dataValue(6) = "And>" gpCode(7) = -4
dataValue(7) = "<And"
gpCode(8) = 0
dataValue(8) = "LWPOLYLINE"
gpCode(9) = -4
dataValue(9) = "And>" gpCode(10) = -4
'dataValue(10) = "Or>" Dim groupCode As Object, dataCode As Object
groupCode = gpCode
dataCode = dataValue
sset.Select(mode, Ptt1, Ptt2,groupCode,dataCode)
MsgBox(sset.Count) Exit Sub
ERROR_HANDLER:
MsgBox("Error In GetIntersectionPoints: " & Err.Number & ", " & Err.Description)
End Sub上述代码中sset.Select(mode, Ptt1, Ptt2,groupCode,dataCode)内后两个参数有问题,如取消就可运行,但没法过滤不要的东西,哪个大侠帮忙,看下有什么问题,急急急………………………………
太牛了 就是字节的问题,郁闷了我半天,一下子豁然开朗了
页:
[1]