Hi,
I'm trying to develop a routine for editing attributes. I want to select a block reference and pull its attributes into a dialog where they can be edited. Then click a save button and the attributes are updated. I'm having an issue with updating the attributes when using an external database (Database.ReadDwgFile). This is how I am cycling through the attributes and assigning a new value to attRef.TextString. The command completes without any errors, but the attributes have not changed... am I missing something?
Dim db2 As Database = New Database(False, False)
If File.Exists(btr.PathName) Then
db2.ReadDwgFile(btr.PathName, FileShare.ReadWrite, False, "")
Using trx2 As Transaction = db2.TransactionManager.StartTransaction()
'HostApplicationServices.WorkingDatabase = db2
Dim xrefBt As BlockTable = trx2.GetObject(db2.BlockTableId, OpenMode.ForWrite)
Dim btrMs2 As BlockTableRecord = trx2.GetObject(xrefBt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim blkRef2 As BlockReference
Dim bID As ObjectId
For Each id2 As ObjectId In btrMs2
If id2.ObjectClass = RXClass.GetClass(GetType(BlockReference)) Then
bID = id2
blkRef2 = TryCast(trx2.GetObject(id2, OpenMode.ForRead, False), BlockReference)
attRefIds = blkRef2.AttributeCollection
For Each attrefid As ObjectId In attRefIds
Dim attref As AttributeReference = trx2.GetObject(attrefid, OpenMode.ForRead, False)
Select Case attref.Tag
Case "PartDescription"
partDesc = attref.TextString
Case "PartNumber"
partNum = attref.TextString
End Select
Next
End If
Next
Dim frmEditAtts As New frmEditAttributes
If frmEditAtts.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim bref As BlockReference = TryCast(trx2.GetObject(bID, OpenMode.ForWrite), BlockReference)
For Each attrefid As ObjectId In bref.AttributeCollection
Dim attref As AttributeReference = trx2.GetObject(attrefid, OpenMode.ForWrite)
Select Case attref.Tag
Case "PartDescription"
attref.TextString = txtPartDesc.Text
Case "PartNumber"
attref.TextString = txtPartNum.Text
End Select
Next
trx2.Commit()
Else
frmEditAtts.Dispose()
End If
End Using
End If
db2.Dispose()
Thanks,
-Ted