- 积分
- 255
- 明经币
- 个
- 注册时间
- 2016-4-4
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2016-4-4 15:59:54
|
显示全部楼层
本帖最后由 imustsun 于 2016-4-4 16:01 编辑
你好,楼主,请教个问题,我是在VB6中运行以下代码:
Private Sub Command1_Click()
Dim dblStart As Double, dblStep As Double
Dim dblStart0 As Double
On Error Resume Next
dblStart = 0
dblStep = 1
Form1.Hide
ConnectAutoCAD
dblStart = ThisDrawing.Utility.GetReal(vbCrLf + "请输入起始高程值(0): ")
If Err.Number = -2145320928 Then Err.Clear
dblStart0 = dblStart
dblStep = ThisDrawing.Utility.GetReal("请输入增量高程值(1): ")
If Err.Number = -2145320928 Then Err.Clear
Dim index As Integer
loop1:
'接受输入起止点
dblStart = dblStart0
On Error GoTo ExitLabel
Dim Pnt1 As Variant, Pnt2 As Variant
Pnt1 = ThisDrawing.Utility.GetPoint(, "请输入起点: ")
Pnt2 = ThisDrawing.Utility.GetPoint(Pnt1, "请输入终点: ") '选择线段经过的多段线, 构成选择集
'选择线段经过的多段线,构成选择集
On Error Resume Next
Dim ssetObj As AcadSelectionSet
Set ssetObj = ThisDrawing.SelectionSets("CONTOUR_SSET")
If ssetObj Is Nothing Then
Set ssetObj = ThisDrawing.SelectionSets.Add("CONTOUR_SSET")
Err.Clear
End If
Dim FilterType(0 To 4) As Integer, FilterData(0 To 4) As Variant
'填充类型和填充数据
FilterType(0) = -4
FilterData(0) = "< OR"
FilterType(1) = 0
FilterData(1) = "LWPOLYLINE" 'olyline" '轻义多段线
FilterType(2) = 0
FilterData(2) = "POLYLINE" 'olyline" '二维多段线
FilterType(3) = 0
FilterData(3) = "LINE" 'ine"
FilterType(4) = -4
FilterData(4) = "OR> "
Dim PntList(0 To 5) As Double
PntList(0) = Pnt1(0): PntList(1) = Pnt1(1): PntList(2) = Pnt1(2)
PntList(3) = Pnt2(0): PntList(4) = Pnt2(1): PntList(5) = Pnt2(2)
'/////
ssetObj.Clear
Set ssetObj = ThisDrawing.SelectionSets.Add("CONTOUR_SSET")
ssetObj.SelectByPolygon acSelectionSetFence, PntList, FilterType, FilterData
'依次为选择集中每条多段线设置高程
'Dim ent As AcadSelectionSet
Dim ent As Object
Dim NP As Variant
Dim i As Integer
For Each ent In ssetObj
Select Case TypeName(ent)
Case "IAcadLine"
'给直线的起止点赋高程
NP = ent.StartPoint
NP(2) = dblStart
ent.StartPoint = NP
NP = ent.EndPoint
NP(2) = dblStart
ent.EndPoint = NP
Case "IAcadLWPolyline"
'给 LWPolyline 赋高程
ent.Elevation = dblStart
Case "IAcadPolyline"
'给 LWPolyline 赋高程
ent.Elevation = dblStart
Case Else '给 3DPolyline 赋高程
ReDim NPS(UBound(ent.Coordinates)) As Double
NPS = ent.Coordinates
For i = 2 To UBound(ent.Coordinates) Step 3
NPS(i) = dblStart
Next i
ent.Coordinates = NPS
End Select
ent.Color = acRed
dblStart = dblStart + dblStep
Next
'输出执行结果汇报
If Err.Number = 0 Then
ThisDrawing.Utility.Prompt "已成功的为等高线设置高程。 " + vbCrLf
Else
ThisDrawing.Utility.Prompt "执行过程中出现错误。 " + vbCrLf
MsgBox Err.Description
End If
GoTo loop1
ThisDrawing.SelectionSets("CONTOUR_SSET").Delete
Exit Sub
ExitLabel:
MsgBox Err.Description
Form1.Show
End Sub
这段代码运行后总提示 ssetObj.SelectByPolygon 参数无效,不知道问题出在哪里了 |
|