Hi
Here's a C# snippet (maybe easier to translate to VB).
A DBDictionary named "StringArraysDictionary" is added (or overwriten) to the named object dictionary and filled with the entries of the Dictionary<string, List<string>> where each entry is considered as a Xrecord.
using System.Collections.Generic;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace DctionayDBDictionary
{
public class Commands
{
[CommandMethod("Test")]
public void Test()
{
Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
dict.Add("foo", new List<string> { "a", "b", "c" });
dict.Add("bar", new List<string> { "x", "y", "z" });
dict.Add("baz", new List<string> { "this", "is", "a", "test" });
DictionaryToDBDictionary(dict, "StringArraysDictionary");
}
private void DictionaryToDBDictionary(Dictionary<string, List<string>> dict, string dictName)
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary nod =
(DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
DBDictionary dbDict;
try
{
dbDict = tr.GetObject(nod.GetAt(dictName), OpenMode.ForWrite) as DBDictionary;
foreach (DBDictionaryEntry entry in dbDict)
{
dbDict.Remove(entry.Key);
}
}
catch
{
nod.UpgradeOpen();
dbDict = new DBDictionary();
nod.SetAt(dictName, dbDict);
tr.AddNewlyCreatedDBObject(dbDict, true);
}
foreach (KeyValuePair<string, List<string>> entry in dict)
{
Xrecord xrec = new Xrecord();
ResultBuffer datas = new ResultBuffer();
foreach (string s in entry.Value)
{
datas.Add(new TypedValue(1, s));
}
xrec.Data = datas;
dbDict.SetAt(entry.Key, xrec);
tr.AddNewlyCreatedDBObject(xrec, true);
}
tr.Commit();
}
}
}
}