Revit is a parameter driven product and parameters can be found everywhere in Revit. Though the Revit API is somewhat object oriented and has many classes and properties a lot of things have not been wrapped into classes or exposed as properties. Using the Parameter API to access some information is really necessary many times.
Revit Parameter Organizer can organize various Revit parameters such as Shared Parameters, Family Parameters, Project Parameters and Built-in Parameter in many good ways.
Each native Parameter has a BuiltInParameter enumerator value as its unique identifier but not every BuiltInParameter value can find a counterpart Parameter instance due to legacy matters or something else. Let’s take the window family instance/symbol for example and introduce these in more detail.
There is no such a class as Window in the Revit API. Each visible window in Revit models is represented by a FamilyInstance of type of some window FamilySymbol. The FamilyInstance class only provides common properties to all family instances and the FamilySymbol one common to all family symbols.
If we’d like to get something specific to a window, we have to resort to the Parameter API. For example, if we want the head height, sill height, width and height of a window element, what should we do?
Regarding the head height, we need to retrieve the BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM parameter from the window element (FamilyInstance) directly; the sill height, BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM from the same instance; the width, BuiltInParameter.WINDOW_WIDTH from its FamilySymbol instead; the height, BuiltInParameter.WINDOW_HEIGHT from the same symbol.
Here is the code to do so:
public static Parameter GetParameterWindowHeadHeight(Element e)
{
return e.get_Parameter(BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM);
}
public static Parameter GetParameterWindowSillHeight(Element e)
{
return e.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM);
}
public static Parameter GetParameterWindowWidth(Element e)
{
return e.get_Parameter(BuiltInParameter.WINDOW_WIDTH);
}
public static Parameter GetParameterWindowHeight(Element e)
{
return e.get_Parameter(BuiltInParameter.WINDOW_HEIGHT);
}
The last two are somewhat straightforward as the BuiltInParameter enum values WINDOW_WIDTH and WINDOW_HEIGHT are self explanatary which have both the window keyword and the meansure one. However, the first two are not and we have to make some guess and do some experiments to sort them out.
The above help methods along with the following calling test code:
Element element = SelectElement(cmdData.Application.ActiveUIDocument.Selection).Element;
Element winType = CachedDoc.get_Element(element.GetTypeId());
Parameter p = GetParameterWindowHeadHeight(element);
string str = string.Format("Head height: {0}\n", p.AsValueString());
p = GetParameterWindowSillHeight(element);
str += string.Format("Sill height: {0}\n", p.AsValueString());
p = GetParameterWindowWidth(winType);
str += string.Format("Window width: {0}\n", p.AsValueString());
p = GetParameterWindowHeight(winType);
str += string.Format("Window height: {0}\n", p.AsValueString());
MessageBox.Show(str, "Window Parameters");
may yield the following result if a window is selected in a model:
Though the argument type of the four help methods are all Element as can be seen from the calling code the first two only apply to FamilyInstance and the last two to FamilySymbol.
Things seem fine so far, but wait a moment, let’s look at another case. As can be seen, staying side by side with the WINDOW_WIDTH and WINDOW_HEIGHT values, another similar one WINDOW_THICKNESS just come in sight. What is it and how to use it?
If the following help method and test code are run, an exception will be thrown out:
public static Parameter GetParameterWindowThickness(Element e)
{
return e.get_Parameter(BuiltInParameter.WINDOW_THICKNESS);
}
p = GetParameterWindowThickness(winType);
MessageBox.Show(p.AsValueString(), "Window Thickness");
Things would not have changed if a FamilyInstance instead of a FamilySymbol were provided to the method.
That could indicate the WINDOW_THICKNESS needs to be purged out from the BuiltInParameter value list or in some very rare cases it might really return something. In this particular case, the wall thickness can be retrieved and used as the thickness of the hosted window, it seems.
The selection help method and the ISelectionFilter derivative have also been appended below to make the code complete:
public static Reference SelectElement(Selection selection)
{
Reference picked = selection.PickObject(ObjectType.Element, new RevitAddinCS.SelectionFilter3(), "Select an element");
return picked;
}
public class SelectionFilter3 : ISelectionFilter
{
public bool AllowElement(Element elem)
{
if (elem.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows) return true;
return false;
}
public bool AllowReference(Reference refer, XYZ pos)
{
return true;
}
}
Parameter Retrieve of RevitAddinWizard can help find a BuiltInParameter enumerator value of interest quickly and create paramter retrieving methods accordingly for various element classes.
Links to some related articles:
Parameter Retriever of RevitAddCoder
Parameter of Revit API - Parameter Information
Parameter Infoer of RevitAddCoder
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