Add attribute to block: Autocad API VB.net
<p>I am using below code to add attribute to certain block,</p>

<p>But it does not work, I am not getting what exactly going wrong and there is no error.</p>

<pre><code>Public Class addattribute
    Public Function addnewattribute()


        Dim attdef As New AttributeReference
        Dim templatepath As String = "C:\Users\sesa388372\Documents\Visual Studio 2015\Projects\SchneiderMacros\Wtemplate.DWG"
        Dim db As Database = New Database
        db.ReadDwgFile(templatepath, System.IO.FileShare.ReadWrite, False, "")
        Using tr As Transaction = db.TransactionManager.StartTransaction
            attdef.SetDatabaseDefaults(db)
            attdef.Tag = "Cell location"
            attdef.TextString = "AAA"


            Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForWrite)
            Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.PaperSpace), OpenMode.ForWrite)
            For Each objid As ObjectId In btr
                If objid.ObjectClass.Name = "AcDbBlockReference" Then
                    Dim blkref As BlockReference = tr.GetObject(objid, OpenMode.ForWrite)
                    If blkref.Name = "TB-D-ATTR" Then

                        blkref.AttributeCollection.AppendAttribute(attdef)

                    End If
                End If
            Next

            tr.AddNewlyCreatedDBObject(attdef, True)
            tr.Commit()

        End Using

        Return Nothing
    End Function
End Class
</code></pre>