We talked about collecting FamilyParameter values before. Now let’s see how FamilyParameter Value Collector of RevitAddinWizard can assist us to achieve the same goal. The FamilyParameter Value Collector can be found either from the Revit Addin Coder sub-menu under the Tools or from the Revit Addin Coder toolbar.
When the menu item or button is clicked, the FamilyParameter Value Collector window will show up:
If the settings as above are accepted and the OK button is clicked, the following FamilyParameter Value Collector code will be created and added into the chosen class:
public static Dictionary<string, List<KeyValuePair<string, object>>> RawNameToTypeValuesMap(FamilyManager famMan)
{
Dictionary<string, List<KeyValuePair<string, object>>> fpNameToTypeValuesMap
= new Dictionary<string, List<KeyValuePair<string, object>>>();
foreach (FamilyParameter p in famMan.Parameters)
{
List<KeyValuePair<string, object>> typeValuePairs = new List<KeyValuePair<string, object>>();
foreach (FamilyType type in famMan.Types)
{
switch (p.StorageType)
{
case StorageType.Double:
typeValuePairs.Add(new KeyValuePair<string, object>(type.Name, type.AsDouble(p)));
break;
case StorageType.Integer:
typeValuePairs.Add(new KeyValuePair<string, object>(type.Name, type.AsInteger(p)));
break;
case StorageType.String:
typeValuePairs.Add(new KeyValuePair<string, object>(type.Name, type.AsString(p)));
break;
case StorageType.ElementId:
typeValuePairs.Add(new KeyValuePair<string, object>(type.Name, type.AsElementId(p)));
break;
case StorageType.None:
typeValuePairs.Add(new KeyValuePair<string, object>(type.Name, "N/A"));
break;
default:
typeValuePairs.Add(new KeyValuePair<string, object>(type.Name, null));
break;
}
}
fpNameToTypeValuesMap.Add(p.Definition.Name, typeValuePairs);
}
return fpNameToTypeValuesMap;
}
public string RawFamilyParameterValuesInfoToCSVString(
Dictionary<string, List<KeyValuePair<string, object>>> values, out string title)
{
title = "Parameter Name,Family Type,Parameter Value";
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, List<KeyValuePair<string, object>>> kvp in values)
{
sb.Append(kvp.Key + ",," + Environment.NewLine);
foreach (KeyValuePair<string, object> pair in kvp.Value)
{
sb.Append(","+pair.Key + ",");
sb.Append((pair.Value == null ? "null" : pair.Value.ToString()) + Environment.NewLine);
}
}
return sb.ToString();
}
In terms of how to use these methods, please refer to previous posts for ideas and code examples.
FamilyParameter Value Collector of RevitAddinWizard can create all these in a second.
Recent Comments