不知道是算法欠佳,还是其他问题,同样是选择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
|