We talked about collecting Parameter information before. Now let’s see how the RevitAddinWizard can help to do the same work. The Parameter Infoer can be found from either the Revit Addin Coder sub-menu under the Tools or the following Revit Addin Coder toolbar:
When the button is clicked, the Parameter Infoer window will show up:
By default, all available properties are checked off. If we accept the settings and click the OK button, the following Parameter Infoer class and all necessary help methods will be created in the chosen class:
public class RawParameterInfo
{
public string Name { get; set; }
public string ID { get; set; }
public string Value { 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 static string RawGetDUTString(Parameter p)
{
string unitType = string.Empty;
try { unitType = p.DisplayUnitType.ToString(); }
catch { }
return unitType;
}
public static List<RawParameterInfo> RawGetParametersInfo(Element e)
{
List<RawParameterInfo> paramList =
(from Parameter p in e.Parameters
select new RawParameterInfo
{
Name = p.Definition.Name,
ID = p.IsShared ? p.GUID.ToString() : (p.Definition as InternalDefinition).BuiltInParameter.ToString(),
Value = p.AsValueString(),
Group = p.Definition.ParameterGroup,
Type = p.Definition.ParameterType,
Storage = p.StorageType,
Unit = RawGetDUTString(p),
Shared = p.IsShared,
ReadOnly = p.IsReadOnly,
}).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();
}
If the information is too much, a few properties can be unchecked from the list box:
Then a light version of the Parameter Infoer class will be created:
public class RawParameterInfo
{
public string Name { get; set; }
public string ID { get; set; }
public string Value { get; set; }
public BuiltInParameterGroup Group { get; set; }
public StorageType Storage { get; set; }
public bool ReadOnly { get; set; }
}
public static string RawGetDUTString(Parameter p)
{
string unitType = string.Empty;
try { unitType = p.DisplayUnitType.ToString(); }
catch { }
return unitType;
}
public static List<RawParameterInfo> RawGetParametersInfo(Element e)
{
List<RawParameterInfo> paramList =
(from Parameter p in e.Parameters
select new RawParameterInfo
{
Name = p.Definition.Name,
ID = p.IsShared ? p.GUID.ToString() : (p.Definition as InternalDefinition).BuiltInParameter.ToString(),
Value = p.AsValueString(),
Group = p.Definition.ParameterGroup,
Storage = p.StorageType,
ReadOnly = p.IsReadOnly,
}).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 the class and help methods, please refer to previous posts for ideas and code examples.
Give Parameter Infoer of RevitAddinWizard a try and you will save your precious time.
Parameter of Revit API - BuiltInParameter
Parameter Retriever of RevitAddCoder
Parameter of Revit API - Parameter Information
Parameter of Revit API - ParameterType And StorageType
Parameter Typer of RevitAddCoder
Parameter of Revit API - BuiltInParameterGroup
Parameter Grouper of RevitAddCoder
Parameter Filter of RevitAddCoder
Parameter of Revit API - Read/Write Parameter Values
Recent Comments