Issue
Using AutoCAD Architecture and Civil 3D, you can add Notes to an entity on the Extended Data tab of Property Palette. How can we do the same programmatically?
Solution
A Note is an AEC object. It is AecDbTextNote or TextNote in .NET.
In .NET API, Autodesk.Aec.DatabaseServices.TextNote class is exposed in AecBaseMgd.dll .NET assembly. You can write a .NET application to access Note objects by referencing to AecBaseMgd.dll. This assembly is also installed with Civil 3D. This means you can access this AEC object in Civil 3D as well.
Here is the command written in VB.NET. It asks you select a line and add Notes.
Imports AcDb2 = Autodesk.AutoCAD.DatabaseServices
Imports AecDb = Autodesk.Aec.DatabaseServices
Public Class TextNote
<CommandMethod("AddTextNote")> _
Public Sub AddTextNote()
' Get hold of some common objects
Dim doc As Document = Application.DocumentManager.
MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim trMgr As TransactionManager = doc.TransactionManager
Dim db As Database = doc.Database
' Select a line
Dim optEnt As New PromptEntityOptions(vbLf & "Select a line")
optEnt.SetRejectMessage(
vbLf & "Selected entity is NOT a line, try again...")
optEnt.AddAllowedClass(GetType(Line), False)
Dim resEnt As PromptEntityResult = ed.GetEntity(optEnt)
If resEnt.Status <> PromptStatus.OK Then
ed.WriteMessage("Selection error - aborting")
Exit Sub
End If
' Open for wrote
Dim tr As Transaction = trMgr.StartTransaction
Try
Dim obj As AcObject =
tr.GetObject(resEnt.ObjectId, AcDb2.OpenMode.ForWrite)
obj.CreateExtensionDictionary()
' Create a Note object
Dim txt As AecDb.TextNote = New AecDb.TextNote()
txt.Note = "My Notes created by VB.NET"
' Create Extension dictionary
Dim extDict As DBDictionary =
tr.GetObject(
obj.ExtensionDictionary(), AcDb2.OpenMode.ForWrite, False)
' Add the Note to Extension dictionary
' TextNote.ExtensionDictionaryName is "AEC_TEXT_NOTE"
extDict.SetAt(AecDb.TextNote.ExtensionDictionaryName, txt)
tr.AddNewlyCreatedDBObject(txt, True)
tr.Commit()
Catch
MsgBox("Error: accessing to Notes failed!")
Finally
tr.Dispose()
End Try
End Sub
End Class
If you are working on AutoCAD Architecture, AecDbTextNote class has been exposed in OMF. No API for TextNote is exposed in VBA. This feature was exposed since 2007 releases.