.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding custom metadata to Documents

2 REPLIES 2
Reply
Message 1 of 3
WWFreeman
1266 Views, 2 Replies

Adding custom metadata to Documents

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.

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: WWFreeman

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

Drive CAD With Code

EESignature

Message 3 of 3
WWFreeman
in reply to: 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
}

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost