VB.NET 按颜色显示图元,运行效率欠佳,请高手赐教
不知道是算法欠佳,还是其他问题,同样是选择41张a1图中显示某几种颜色,此程序需10s,而msteel箱仅2s左右,请高手优化,谢谢。YXX ,按色显示,QXX,全部显示。_
Public Sub YXX()
'' 获得当前文档和数据库 Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim acLyrTblRec As LayerTableRecord
Dim acLyrTbl As LayerTable
On Error Resume Next
''启动一个事务 Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'Dim ColorList As New List(Of String)
'Dim ColorList As New ArrayList
Dim ColorList As New List(Of String)
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
If Not IsDBNull(acSSObj) Then
Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite)
If Not IsDBNull(acEnt) Then
Dim acEntColor As String = acEnt.Color.ToString
'MsgBox(acEntColor)
If acEntColor = "BYLAYER" Then
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead)
acLyrTblRec = acTrans.GetObject(acLyrTbl(acEnt.Layer), OpenMode.ForWrite)
acEntColor = acLyrTblRec.Color.ToString
'MsgBox(acEntColor)
End If
'去重
If ColorList.Contains(acEntColor) = False Then
ColorList.Add(acEntColor)
End If
End If
End If
Next
End If
Dim acSSPrompt1 As PromptSelectionResult = acDoc.Editor.SelectAll()
If acSSPrompt1.Status = PromptStatus.OK Then
Dim acSSet1 As SelectionSet = acSSPrompt1.Value
For Each acSSObj1 As SelectedObject In acSSet1
If Not IsDBNull(acSSObj1) Then
Dim acEnt1 As Entity = acTrans.GetObject(acSSObj1.ObjectId, OpenMode.ForWrite)
If Not IsDBNull(acEnt1) Then
Dim acEnt1Color As String = acEnt1.Color.ToString
'MsgBox(acEntColor)
If acEnt1Color = "BYLAYER" Then
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead)
acLyrTblRec = acTrans.GetObject(acLyrTbl(acEnt1.Layer), OpenMode.ForWrite)
acEnt1Color = acLyrTblRec.Color.ToString
'MsgBox(acEntColor)
End If
If ColorList.Contains(acEnt1Color) = True Then
acEnt1.Visible = True
Else
acEnt1.Visible = False
End If
End If
End If
Next
End If
acTrans.Commit()
End Using
End Sub
_
Public Sub QXX()
'' 获得当前文档和数据库 Get the current document and database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'On Error Resume Next
''启动一个事务 Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acSSPrompt1 As PromptSelectionResult = acDoc.Editor.SelectAll()
If acSSPrompt1.Status = PromptStatus.OK Then
Dim acSSet1 As SelectionSet = acSSPrompt1.Value
For Each acSSObj1 As SelectedObject In acSSet1
If Not IsDBNull(acSSObj1) Then
Dim acEnt1 As Entity = acTrans.GetObject(acSSObj1.ObjectId, OpenMode.ForWrite)
acEnt1.Visible = True
End If
Next
End If
acTrans.Commit()
End Using
End Sub
你的代码是全图选择图元
用过滤器要快些的
我的思路是:1.任选几个图元,取图元色彩集。2.遍历所有对象,取每个对象颜色,若在色彩集中则显示,反之关闭。
过滤器?通过色彩不太好选,不同层,不同色,颜色随层时,都是256(BYLAYER),选不中啊
.visible的对象不能是选择集。。所以遍历了所有图元判断. http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75642最后一个帖子我贴了按线型过滤的例子 颜色过滤类似
页:
[1]