Get or Set the TextNote Property with Vb.Net

Get or Set the TextNote Property with Vb.Net

jpkycek
Enthusiast Enthusiast
507 Views
0 Replies
Message 1 of 1

Get or Set the TextNote Property with Vb.Net

jpkycek
Enthusiast
Enthusiast

Just wanted to share how to get/set the TextNote

property for any entity with vb.net.

 

 

 

Public Function GetNote(ByVal oEnt As Entity) As String
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim tr As Transaction = doc.Database.TransactionManager.StartTransaction()
            Dim oDict As DBDictionary
            Dim oDictId As ObjectId
            Dim o As Object

            GetNote = ""

            If oEnt.ExtensionDictionary = ObjectId.Null Then
                GoTo pass
            End If

            oDictId = oEnt.ExtensionDictionary()
            oDict = tr.GetObject(oDictId, OpenMode.ForRead)

            If oDict.Item("AEC_TEXT_NOTE") = ObjectId.Null Then
                GoTo pass
            Else
                o = tr.GetObject(oDict.Item("AEC_TEXT_NOTE"), OpenMode.ForRead)
                GetNote = o.note
            End If

pass:
            tr.Commit()

        End Function


        Public Sub SetNote(ByVal oEnt As Entity, ByVal sNote As String)
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim tr As Transaction = doc.Database.TransactionManager.StartTransaction()
            Dim oDict As DBDictionary
            Dim oDictId As ObjectId
            Dim o As Object

            If oEnt.ExtensionDictionary = ObjectId.Null Then
                GoTo pass
            End If

            oDictId = oEnt.ExtensionDictionary()
            oDict = tr.GetObject(oDictId, OpenMode.ForRead)

            If oDict.Item("AEC_TEXT_NOTE") = ObjectId.Null Then
                GoTo pass
            Else
                o = tr.GetObject(oDict.Item("AEC_TEXT_NOTE"), OpenMode.ForWrite)
                o.note = sNote
            End If

pass:
            tr.Commit()

        End Sub

0 Likes
508 Views
0 Replies
Replies (0)