I see you trying to use a Dictionary<string, List<string[]>>-----I missed the extra parentheses
kaefer's solution is better but here is one hard-coded and doing what gile mentioned in previous post.
This is a example and has it pit falls but just for example to show you one way of nesting it.
So you need to modify it.
This made me go cross-eyed using Dictionary<string, List<string[]>>
Commands
const string DIC_NAME = "HpadDictionary";
[CommandMethod("XrecordDictionaryAdd")]
public void XrecordDictionaryAdd()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
Dictionary<string, List<string[]>> dictionary = new Dictionary<string, List<string[]>>();
string[] valsA1 = { "A1-1", "A1-2" };
string[] valsA2 = { "A2-1", "A2-2" };
dictionary.Add("A", new List<string[]> {valsA1, valsA2});
string[] valsB1 = { "B1-1", "B1-2" };
string[] valsB2 = { "B2-1", "B2-2" };
dictionary.Add("B", new List<string[]> { valsB1, valsB2 });
XrecordInfo xi = new XrecordInfo(DIC_NAME);
xi.AddDict(dictionary);
trx.Commit();
}
}
[CommandMethod("XrecordDictionaryGet")]
public void XrecordDictionaryGet()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
XrecordInfo xi = new XrecordInfo(DIC_NAME);
Dictionary<string, List<string[]>> dictionary = xi.GetDict();
foreach (KeyValuePair<string, List<string[]>> kvp in dictionary)
{
ed.WriteMessage("\n{0}", kvp.Key);
int i = 1;
foreach (string[] strings in kvp.Value)
{
ed.WriteMessage("\n{0,15:D} {1}","Array", i);
foreach (string str in strings)
{
ed.WriteMessage("\n{0,15:D}", str);
}
i++;
}
}
trx.Commit();
}
}
Not very good but for example Helper Class
public class XrecordInfo
{
private Database _db;
private Transaction _trx;
Database db { get { return _db; } }
Transaction trx { get { return _trx; } }
string DictionaryName { get; set; }
public XrecordInfo()
{
_db = HostApplicationServices.WorkingDatabase;
_trx = _db.TransactionManager.TopTransaction;
}
public XrecordInfo(string dictName)
: this()
{
DictionaryName = dictName;
}
public void AddDict(Dictionary<string, List<string[]>> dict)
{
DBDictionary nod = (DBDictionary)trx.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
DBDictionary dic = new DBDictionary();
nod.SetAt(DictionaryName, dic);
trx.AddNewlyCreatedDBObject(dic, true);
foreach(KeyValuePair<string, List<string[]>> kvp in dict)
{
DBDictionary nestedDic = new DBDictionary();
dic.SetAt(kvp.Key, nestedDic);
trx.AddNewlyCreatedDBObject(nestedDic, true);
int i = 1;
foreach (string[] vals in kvp.Value)
{
Xrecord xr = new Xrecord();
TypedValueList tvl = new TypedValueList();
foreach (string val in vals)
{
tvl.Add(1, val);
}
xr.Data = tvl;
nestedDic.SetAt(String.Format("array{0}", i), xr);
trx.AddNewlyCreatedDBObject(xr, true);
i++;
}
}
}
public Dictionary<string, List<string[]>> GetDict()
{
Dictionary<string, List<string[]>> dictionary = new Dictionary<string, List<string[]>>();
DBDictionary nod = (DBDictionary)trx.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
DBDictionary dic = (DBDictionary)trx.GetObject(nod.GetAt(DictionaryName), OpenMode.ForRead);
foreach (DBDictionaryEntry entry in dic)
{
DBDictionary nestedDic = (DBDictionary)trx.GetObject(dic.GetAt(entry.Key), OpenMode.ForRead);
List<string[]> vals = new List<string[]>();
foreach (DBDictionaryEntry nestedEntry in nestedDic)
{
Xrecord xr = (Xrecord)trx.GetObject(nestedDic.GetAt(nestedEntry.Key), OpenMode.ForRead);
TypedValueList tvl = xr.Data;
string[] strings = new string[tvl.Count];
for (int i = 0; i < tvl.Count; i++)
{
strings[i] = tvl[i].Value.ToString();
}
vals.Add(strings);
}
dictionary.Add(entry.Key, vals);
}
return dictionary;
}
}
Uses Tony T's TypedValueList
public class TypedValueList : List<TypedValue>
{
// With thanks to Tony Tanzillo
// http://www.theswamp.org/index.php?topic=14495.msg186823#msg186823
//
public TypedValueList(params TypedValue[] args)
{
AddRange(args);
}
// Make it a bit easier to add items:
public void Add(int typecode, object value)
{
base.Add(new TypedValue(typecode, value));
}
public void Add(LispDataType type, object value)
{
Add(new TypedValue((int)type, value));
}
public void Add(DxfCode code, object value)
{
Add(new TypedValue((int)code, value));
}
// Implicit conversion to SelectionFilter
public static implicit operator SelectionFilter(TypedValueList src)
{
return src != null ? new SelectionFilter(src) : null;
}
// Implicit conversion to ResultBuffer
public static implicit operator ResultBuffer(TypedValueList src)
{
return src != null ? new ResultBuffer(src) : null;
}
// Implicit conversion to TypedValue[]
public static implicit operator TypedValue[](TypedValueList src)
{
return src != null ? src.ToArray() : null;
}
// Implicit conversion from TypedValue[]
public static implicit operator TypedValueList(TypedValue[] src)
{
return src != null ? new TypedValueList(src) : null;
}
// Implicit conversion from SelectionFilter
public static implicit operator TypedValueList(SelectionFilter src)
{
return src != null ? new TypedValueList(src.GetFilter()) : null;
}
// Implicit conversion from ResultBuffer
public static implicit operator TypedValueList(ResultBuffer src)
{
return src != null ? new TypedValueList(src.AsArray()) : null;
}
}