Hello again.
I wonder whether it is possible to add custom attirbutes to AutoCAD Documents. Like, when adding new key-value pairs to the OS registry. I see this as a function that can add a pair "attribute" => "value" to the Document's database (or another saveable component) and later pull the "value" back by passing the "attribute" to another function.
It wouldn't surprise me if this didn't exist but still why wondering when I can ask more experienced... Thanks.
I assume you want to add/attach some kind of data to the document/drawing, so the data get persisted inside the drawing file and can be accessed when the file is loaded into AutoCAD.
There are at least 2 options you can look into, depending on the data you want to add
1. Drawing custom properties
2, Named dictionary
Both are key-value paired data sotrage mechanism. But to be aware, they can only be accessed to when the document is loaded into AutoCAD (or application based on RealDwg.
Norman Yuan
Yes, that is what I am aiming to do. Since there was some digging and guessing involved in seeing how this works in ObjectARX 2013, I will add some code:
Writing:
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; DatabaseSummaryInfoBuilder infoBuilder = new DatabaseSummaryInfoBuilder(); infoBuilder.CustomPropertyTable["key1"] = "value1"; infoBuilder.CustomPropertyTable["key2"] = "value2"; doc.Database.SummaryInfo = infoBuilder.ToDatabaseSummaryInfo(); doc.Database.SaveAs("test.dwg", DwgVersion.Current);
Reading:
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; DatabaseSummaryInfo info = db.SummaryInfo; System.Collections.IDictionaryEnumerator cust = info.CustomProperties; while(cust.MoveNext()) { string key = cust.Entry.Key as string; string value = cust.Entry.Value as string; // Write the pair wherever you want it for later, or just use it }