Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I found this code at Kean Walmsley's blog [here]
It works just fine, however I'm having some trouble adapting the code.
I do not want to pick a block, I want to use a specific named block.
e.g (blk.Name = "MyBlock" or Blk.Name = "MyOtherBlock")
I started commenting some of it, but when I get Dim selSet As SelectionSet = res.Value I get lost.
How can this be done?
Imports Autodesk.AutoCAD Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Namespace MyApplication Public Class DumpAttributes <CommandMethod("LISTATT")> _ Public Sub ListAttributes() Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim db As Database = HostApplicationServices.WorkingDatabase Dim tr As Transaction = db.TransactionManager.StartTransaction ' Start the transaction Try ' Build a filt
er list so that only ' block references are selected Dim filList() As TypedValue = New TypedValue() {New TypedValue(CType(DxfCode.Start,Integer), "INSERT")} Dim filter As SelectionFilter = New SelectionFilter(filList) Dim opts As PromptSelectionOptions = New PromptSelectionOptions opts.MessageForAdding = "Select block references: " Dim res As PromptSelectionResult = ed.GetSelection(opts, filter) ' Do nothing if selection is unsuccessful If (res.Status <> PromptStatus.OK) Then Return End If Dim selSet As SelectionSet = res.Value Dim idArray() As ObjectId = selSet.GetObjectIds For Each blkId As ObjectId In idArray Dim blkRef As BlockReference = CType(tr.GetObject(blkId, OpenMode.ForRead),BlockReference) Dim btr As BlockTableRecord = CType(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead),BlockTableRecord) ed.WriteMessage((""& vbLf&"Block: " + btr.Name)) btr.Dispose Dim attCol As AttributeCollection = blkRef.AttributeCollection For Each attId As ObjectId In attCol Dim attRef As AttributeReference = CType(tr.GetObject(attId, OpenMode.ForRead),AttributeReference) Dim str As String = (""& vbLf&" Attribute Tag: " _ + (attRef.Tag + (""& vbLf&" Attribute String: " + attRef.TextString))) ed.WriteMessage(str) Next Next tr.Commit Catch ex As Autodesk.AutoCAD.Runtime.Exception ed.WriteMessage(("Exception: " + ex.Message)) Finally tr.Dispose End Try End Sub End Class End Namespace
Solved! Go to Solution.