We talked about collecting FamilyParameter information before. Now let’s see how FamilyParameter Infoer of RevitAddinWizard can assist us to do fulfill the same task. The FamilyParameter Infoer can be found from either the Revit Addin Coder sub-menu under the Tools or from Revit Addin Coder toolbar.
When the menu item or button is clicked, the FamilyParameter Infoer window will show up:
If all default settings are accepted and the OK button is clicked, the following FamilyParameter Infoer code will be created and added into the chosen class:
public class RawFamilyParameterInfo
{
public string Name { get; set; }
public string ElementID { get; set; }
public string GUID { get; set; }
public string BuiltinID { get; set; }
public BuiltInParameterGroup Group { get; set; }
public ParameterType Type { get; set; }
public StorageType Storage { get; set; }
public string Unit { get; set; }
public bool Shared { get; set; }
public bool ReadOnly { get; set; }
public bool Instance { get; set; }
public bool Reporting { get; set; }
public bool FormulaDetermined { get; set; }
public bool CanAssignFormula { get; set; }
}
public static string RawGetDUTString(FamilyParameter p)
{
string unitType = string.Empty;
try { unitType = p.DisplayUnitType.ToString(); }
catch { }
return unitType;
}
public static List<RawFamilyParameterInfo> RawGetFamilyParametersInfo(Document doc)
{
List<RawFamilyParameterInfo> paramList =
(from FamilyParameter p in doc.FamilyManager.Parameters
select new RawFamilyParameterInfo
{
Name = p.Definition.Name,
ElementID = p.Id.IntegerValue.ToString(),
GUID = (p.Definition as ExternalDefinition) != null ? (p.Definition as ExternalDefinition).GUID.ToString() : string.Empty,
BuiltinID = (p.Definition as InternalDefinition) != null ? (p.Definition as InternalDefinition).BuiltInParameter.ToString() : string.Empty,
Group = p.Definition.ParameterGroup,
Type = p.Definition.ParameterType,
Storage = p.StorageType,
Unit = RawGetDUTString(p),
Shared = (p.Definition as ExternalDefinition) != null,
ReadOnly = p.IsReadOnly,
Instance = p.IsInstance,
Reporting = p.IsReporting,
FormulaDetermined = p.IsDeterminedByFormula,
CanAssignFormula = p.CanAssignFormula,
}).ToList();
return paramList;
}
public static string RawParametersInfoToCSVString<T>(List<T> infoList, ref string title)
{
StringBuilder sb = new StringBuilder();
PropertyInfo[] propInfoArrary = typeof(T).GetProperties();
foreach (PropertyInfo pi in propInfoArrary)
{
title += pi.Name + ",";
}
title = title.Remove(title.Length - 1);
foreach (T info in infoList)
{
foreach (PropertyInfo pi in propInfoArrary)
{
object obj = info.GetType().InvokeMember(pi.Name, BindingFlags.GetProperty, null, info, null);
IList list = obj as IList;
if (list != null)
{
string str = string.Empty;
foreach (object e in list)
{
str += e.ToString() + ";";
}
str = str.Remove(str.Length - 1);
sb.Append(str + ",");
}
else
{
sb.Append((obj == null ? string.Empty : obj.ToString()) + ",");
}
}
sb.Remove(sb.Length - 1, 1).Append(Environment.NewLine);
}
return sb.ToString();
}
In terms of how to use these methods, please refer to previous posts for ideas and code examples.
FamilyParameter Infoer of RevitAddinWizard can create all these in a second.
Recent Comments