Hey Guys,
I've been using this piece of code for a year or two, However I recently changed my hard drive, Thus re installed all programs since then I have received several new errors.
I have since started a new project but have had several issues regarding me existing library features. I have loaded up some older programs & they too have the same issues.
The line "TryCast(blkAttID.GetObject(OpenMode.ForWrite)" does not work any more, Thus I have to implement code that's commented out.
<Extension()> Public Function GetAttribute(ByVal BlkRef As BlockReference) As List(Of AttributeReference)
Dim BlkAttributeNames As New List(Of AttributeReference)
'Using AcTrans As Transaction = BlkRef.Database.TransactionManager.StartTransaction
' For Each blkAttID As ObjectId In BlkRef.AttributeCollection
' Dim BlkAttribute As AttributeReference = TryCast(AcTrans.GetObject(blkAttID, OpenMode.Forread), AttributeReference)
' If BlkAttribute IsNot Nothing Then
' BlkAttributeNames.Add(BlkAttribute)
' End If
' Next
' Return BlkAttributeNames
'End Using
For Each blkAttID As ObjectId In BlkRef.AttributeCollection
Dim BlkAttribute As AttributeReference = TryCast(blkAttID.GetObject(OpenMode.ForWrite), AttributeReference)
If BlkAttribute IsNot Nothing Then
BlkAttributeNames.Add(BlkAttribute)
End If
Next
Return BlkAttributeNames
End Function
This code will no longer "MyAttribute.UpgradeOpen()" will no longer open the entity for write & throws an error, nor does upgrading the parent & putting the value in "MyAttribute.TextString = Value"
<Extension()> Public Function Attribute(ByVal BlkRef As BlockReference, ByVal TagName As String, ByVal Value As String) As Boolean
Using AcTrans As Transaction = BlkRef.Database.TransactionManager.StartTransaction
Dim MyAttribute As AttributeReference = GetAttribute(BlkRef, TagName)
If MyAttribute IsNot Nothing Then
' BlkRef.UpgradeOpen()
MyAttribute.UpgradeOpen()
MyAttribute.TextString = Value
Return True
End If
AcTrans.Commit()
End Using
Return Nothing
End Function
<Extension()> Public Function GetAttribute(ByVal BlkRef As BlockReference, ByVal TagName As String) As AttributeReference
Dim lResults As List(Of AttributeReference) = GetAttribute(BlkRef)
For Each BlkAttribute As AttributeReference In lResults
If BlkAttribute.Tag = TagName Then
Return BlkAttribute
End If
Next
Return Nothing
End Function
Do you have any idea's why this code is now failing & more importantly how I can solve the issues for the second part of the code?