Dealing with drawing via COM sounds more pleasant to me but I dont know how to convert my class library codes to be acceptable for COM. I had some codes in my DLL file to purge and also to update some attributes.
Here is the code which I was using to Purge (in DLL file):
Private Sub PurgeBlocks()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = TryCast(trans.GetObject(db.BlockTableId, OpenMode.ForWrite), BlockTable)
For Each oid As ObjectId In bt
Dim btr As BlockTableRecord = TryCast(trans.GetObject(oid, OpenMode.ForWrite), BlockTableRecord)
If btr.GetBlockReferenceIds(False, False).Count = 0 AndAlso Not btr.IsLayout Then
btr.[Erase]()
End If
Next
trans.Commit()
End Using
End Sub And these ones to update some attributes(in DLL file):
Private Sub UpdateAttributesInDatabase(db As Database, blockName As String, attbName As String, attbValue As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
' Get the IDs of the spaces we want to process and simply call a function to process each
Dim ModelSpaceId As ObjectId
Dim PaperSpaceId As ObjectId
Dim Transactn As Transaction = db.TransactionManager.StartTransaction()
Using Transactn
Dim bt As BlockTable = DirectCast(Transactn.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
ModelSpaceId = bt(BlockTableRecord.ModelSpace)
PaperSpaceId = bt(BlockTableRecord.PaperSpace)
Transactn.Commit()
End Using
UpdateAttributesInBlock(ModelSpaceId, blockName, attbName, attbValue)
UpdateAttributesInBlock(PaperSpaceId, blockName, attbName, attbValue)
ed.Regen()
End Sub
'============================================================
Private Sub UpdateAttributesInBlock(btRecordId As ObjectId, blockName As String, attbName As String, attbValue As String)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim tr As Transaction = doc.TransactionManager.StartTransaction()
Using tr
Dim btRecord As BlockTableRecord = DirectCast(tr.GetObject(btRecordId, OpenMode.ForRead), BlockTableRecord)
For Each entId As ObjectId In btRecord
Dim ent As Entity = TryCast(tr.GetObject(entId, OpenMode.ForRead), Entity)
If ent IsNot Nothing Then
Dim br As BlockReference = TryCast(ent, BlockReference)
If br IsNot Nothing Then
Dim bd As BlockTableRecord = DirectCast(tr.GetObject(br.BlockTableRecord, OpenMode.ForRead), BlockTableRecord) 'to see whether it's a block with the name we're after
If bd.Name.ToUpper() = blockName Then ' Check each of the attributes...
For Each attReferenceId As ObjectId In br.AttributeCollection
Dim obj As DBObject = tr.GetObject(attReferenceId, OpenMode.ForRead)
Dim attReference As AttributeReference = TryCast(obj, AttributeReference)
If attReference IsNot Nothing Then 'to see whether it has the tag we're after
If attReference.Tag.ToUpper() = attbName Then ' If so, update the value and increment the counter
attReference.UpgradeOpen()
attReference.TextString = attbValue
attReference.DowngradeOpen()
End If
End If
Next
End If
UpdateAttributesInBlock(br.BlockTableRecord, blockName, attbName, attbValue) ' Recurse for nested blocks
End If
End If
Next
tr.Commit()
End Using
End Sub Any idea for getting their equivalent for COM mode? I dont mind using any other code as long as it provides my the following functionalies:
- Purge
- UpdateAttribute(TagName As String, NewValue As String)
Alternatively, if I could not find any solution for conversion, how can I load a DLL code using "NETLOAD" command?