<CommandMethod("ALLATTRIBSTOTEST")> _
Public Sub SetAllBlockAttributesToTest()
'' Initiate empty string for logging purposes
Dim log As String = ""
'' Get the current document and database
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
''Lock The Document because we are working from a modeless window
Using acLckDoc As DocumentLock = acDoc.LockDocument()
'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
'' Open the Block table record Model space for read
Dim acBlkTblRec As BlockTableRecord = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForRead)
'' Step through the Block table record
For Each acObjId As ObjectId In acBlkTblRec
''Check if the block is of the INSERT type - ignore LINE, CIRCLE, POLYGON ...
If acObjId.ObjectClass().DxfName = "INSERT" Then
'If TRUE create Log Entry with DXF name, ObjectID and Handle
log = log + vbLf & "DXF name: " & acObjId.ObjectClass().DxfName
log = log + vbLf & "ObjectID: " & acObjId.ToString()
log = log + vbLf & "Handle: " & acObjId.Handle.ToString()
log = log + vbLf
''Open Block Reference of Current Block for Read
Dim BlocRef As BlockReference = acObjId.GetObject(OpenMode.ForRead)
''Check if the NAME of the Block currently Referenced start with Callens
''(Others are not necessary for the Equipment List)
If BlocRef.Name.StartsWith("Callens") Then
'Get the Attribute Collection of the Block that is currently in use by our Block Reference
Dim BlocRefAttrCollection As AttributeCollection = BlocRef.AttributeCollection
'If there are no attributes, do nothing
'MsgBox(BlocRefAttrCollection.Count)
If BlocRefAttrCollection.Count > 0 Then
For Each BlocRefAttrID As ObjectId In BlocRefAttrCollection
'' Go through all AttributesReferences in the AttributesCollection
Dim BlocRefAttr As New AttributeReference
BlocRefAttr = acTrans.GetObject(BlocRefAttrID, OpenMode.ForRead)
log = log + vbLf & "Tag: " & BlocRefAttr.Tag.ToString()
log = log + vbLf & "Textstring: " & BlocRefAttr.TextString()
log = log + vbLf
''OPEN THE ATTRIBUTEREFERENCE FOR WRITE AND SET "TEST" TO ATTRIBUTE TEXTSTRING
''
'BlocRefAttr = acTrans.GetObject(BlocRefAttrID, OpenMode.ForWrite)
'BlocRefAttr.TextString = "TEST"
''
''
''
Next
MsgBox(log
) ''Show log in Message Box log = "" ''Clear log for next block
End If '' End BlocRefAttrCollection.Count
End If '' End BlocRef.Name StartsWith Callens
End If '' End DXFName is INSERT
'acTrans.Commit()
Next
'' Dispose of the transaction
End Using
''Unlock Document
End Using
''Update Current Active Document with Changes
'Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = acDoc
End Sub