.NET

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

Adding custom metadata to Documents

367 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: 959
Registered: ‎04-27-2009
Message 2 of 3 (317 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 (305 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
}

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community