public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Autodesk.Revit.DB.View view = doc.ActiveView;
Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "");
Wall wall = doc.GetElement(refer) as Wall;
Transaction tran = new Transaction(doc, "BIM");
tran.Start();
SchemaBuilder bulder = new SchemaBuilder(new Guid("11111111-bbbb-2222-cccc-333333333333"));
bulder.SetReadAccessLevel(AccessLevel.Public);
bulder.SetWriteAccessLevel(AccessLevel.Public);
bulder.SetSchemaName("WallDictionary");
bulder.SetDocumentation("Data store for dictionary");
FieldBuilder fiedBuilder = bulder.AddMapField("dictionary", typeof(string), typeof(string));
Schema schema = bulder.Finish();
Entity ent = new Entity(schema);
Field field = schema.GetField("dictionary");
IDictionary(string, string) stringMap = new Dictionary(string, string)();
stringMap.Add("Key1", "123456");
stringMap.Add("Key2", "654321");
ent.Set(IDictionary(string, string))(field, stringMap);
wall.SetEntity(ent);
tran.Commit();
return Result.Succeeded;
IList listGuid = wall.GetEntitySchemaGuids();
Schema sa = Schema.Lookup(listGuid[0]);
Entity entity = wall.GetEntity(sa);
IDictionary(string, string) dicMap = entity.Get(IDictionary(string, string))(sa.GetField("dictionary"));
for (int i = 0; i < dicMap.Count; i++)
{
MessageBox.Show(dicMap.Keys.ElementAt(i) + "\t" + dicMap.Values.ElementAt(i));
}