We talked about collecting Shared Parameter information before. Now let’s see how SharedParameter Infoer of RevitAddinWizard can assist us to achieve the same goal. The SharedParameter 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 SharedParameter Infoer window will show up:
If all default settings are accepted and the OK button is clicked, the following SharedParameter Infoer code will be created and added into the chosen class:
public class RawSharedParameterInfo
{
public static string FileName { get; set; }
public string Name { get; set; }
public string GUID { get; set; }
public string Owner { get; set; }
public BuiltInParameterGroup Group { get; set; }
public ParameterType Type { get; set; }
public bool ReadOnly { get; set; }
public bool Visible { get; set; }
}
public static List<RawSharedParameterInfo> RawGetSharedParametersInfo(DefinitionFile defFile)
{
RawSharedParameterInfo.FileName = defFile.Filename;
List<RawSharedParameterInfo> paramList =
(from DefinitionGroup dg in defFile.Groups
from ExternalDefinition d in dg.Definitions
select new RawSharedParameterInfo
{
Name = d.Name,
GUID = d.GUID.ToString(),
Owner = d.OwnerGroup.Name,
Group = d.ParameterGroup,
Type = d.ParameterType,
ReadOnly = d.IsReadOnly,
Visible = d.Visible,
}).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