Message 1 of 3
Not applicable
09-23-2015
09:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on an AutoCAD .net application that lists all block definitions in the active drawing in a TreeView Control with the attributes of that block listed a child nodes (AutoCAD 2015). When the user selects a block definition my code will highlight each block instance within the drawing. I also want it to Hihglight ONLY the attribute if an Attribute node is selected. Here is my code - for some reason the attributes are not being highlighted. Any assistance would be greatly appreciated.
Private Sub BlocksUltraTree_AfterSelect(sender As Object, e As Infragistics.Win.UltraWinTree.SelectEventArgs) Handles BlocksUltraTree.AfterSelect
acActiveDocument = acDocumentManager.MdiActiveDocument
acActiveDocumentDatabase = acActiveDocument.Database
Dim acTrans As Transaction = acActiveDocumentDatabase.TransactionManager.StartTransaction
Using acTrans
'clear any existing entity highlights
Dim acBlockTable As BlockTable = acTrans.GetObject(acActiveDocumentDatabase.BlockTableId, OpenMode.ForRead)
For Each acBlockTableRecordId As ObjectId In acBlockTable
Dim acBlockTableRecord As BlockTableRecord = CType(acTrans.GetObject(acBlockTableRecordId, OpenMode.ForRead), BlockTableRecord)
For Each acEntityId As ObjectId In acBlockTableRecord
Dim myEnt As Entity = TryCast(acTrans.GetObject(acEntityId, OpenMode.ForRead), Entity)
myEnt.Unhighlight()
Next
Next
'highlight selected blocks in the drawing
Dim UserSelectedNode As Infragistics.Win.UltraWinTree.UltraTreeNode = Me.BlocksUltraTree.SelectedNodes(0)
Dim acActiveDocumentEditor As Editor = acActiveDocument.Editor
If UserSelectedNode.Tag = "Block" Then
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.BlockName, UserSelectedNode.Text), 0)
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim acSSPromptRslt As PromptSelectionResult
acSSPromptRslt = acActiveDocumentEditor.SelectAll(acSelFtr)
If acSSPromptRslt.Status = PromptStatus.OK Then
For i = 0 To acSSPromptRslt.Value.Count - 1
Dim myBlk As BlockReference = TryCast(acTrans.GetObject(acSSPromptRslt.Value(i).ObjectId, OpenMode.ForRead), BlockReference)
myBlk.Highlight()
Next
End If
End If
'highlight selected attributes within the blocks in the drawing
If UserSelectedNode.Tag = "Attribute" Then
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.BlockName, UserSelectedNode.Parent.Text), 0)
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
Dim acSSPromptRslt As PromptSelectionResult
acSSPromptRslt = acActiveDocumentEditor.SelectAll(acSelFtr)
If acSSPromptRslt.Status = PromptStatus.OK Then
For i = 0 To acSSPromptRslt.Value.Count - 1
Dim myBlk As BlockReference = TryCast(acTrans.GetObject(acSSPromptRslt.Value(i).ObjectId, OpenMode.ForRead), BlockReference)
Dim attCol As AttributeCollection = myBlk.AttributeCollection
For Each attObjId As ObjectId In attCol
Dim att As AttributeReference = TryCast(acTrans.GetObject(attObjId, OpenMode.ForRead), AttributeReference)
If Not att Is Nothing Then
If att.Tag = UserSelectedNode.Text Then
MsgBox(att.TextString)
att.Highlight()
End If
End If
Next
Next
End If
End If
End Using 'acTrans
End SubNote that the msgbox (att.TextString) line is simply there to know I was indeed getting each seperate instance of that attribute within the drawing.
Solved! Go to Solution.