Q: I need to store some information in a dwg file, which would describe this drawing and let to integrate it with another software system. Can I write such custom information into a drawing and read it later? Can it be done without opening the drawing in AutoCAD?
A: You may use so called Named Object Dictionary (NOD) to store custom data in a drawing. NOD is an essential part of an AutoCAD drawing database and it is created automatically when the drawing is created.
As always with database operations, your program may open a dwg file invisibly to the user via Database.ReadDwgFile() method, i.e. it does not have to be the drawing in the active AutoCAD window.
Here is an example:
// Write some data to the NOD
public void WriteToNOD()
Database db = new Database();
// We will write to C:\Temp\Test.dwg. Make sure it exists!
// Load it into AutoCAD
System.IO.FileShare.ReadWrite, false, null);
using( Transaction trans =
// Find the NOD in the database
DBDictionary nod = (DBDictionary)trans.GetObject(
// We use Xrecord class to store data in Dictionaries
Xrecord myXrecord = new Xrecord();
myXrecord.Data = new ResultBuffer(
new TypedValue((int)DxfCode.Int16, 1234),
"This drawing has been processed"));
// Create the entry in the Named Object Dictionary
// Now let's read the data back and print them out
// to the Visual Studio's Output window
ObjectId myDataId = nod.GetAt("MyData");
Xrecord readBack = (Xrecord)trans.GetObject(
foreach (TypedValue value in readBack.Data)
"===== OUR DATA: " + value.TypeCode.ToString()
+ ". " + value.Value.ToString());
} // using
catch( Exception e )
} // End of WriteToNOD()
You can treat the NOD as a place to keep "document-level" data.
If you need to store some data related to particular objects in the drawing, consider using their Extension Dictionaries.