.NET

Reply
Active Contributor
WWFreeman
Posts: 27
Registered: ‎09-02-2012
Message 1 of 3 (442 Views)

Adding custom metadata to Documents

442 Views, 2 Replies
04-07-2013 12:00 PM

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.

*Expert Elite*
norman.yuan
Posts: 1,049
Registered: ‎04-27-2009
Message 2 of 3 (392 Views)

Re: Adding custom metadata to Documents

04-08-2013 06:47 AM 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.

Active Contributor
WWFreeman
Posts: 27
Registered: ‎09-02-2012
Message 3 of 3 (380 Views)

Re: Adding custom metadata to Documents

04-08-2013 11:06 AM 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
}

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!