The Element Parameters are retrieved by iterating through the Element ParameterSet. The following code sample illustrates how to retrieve the Parameter from a selected element.
Code Region 8-1: Getting selected element parameters |
void GetElementParameterInformation(Document document, Element element) { // Format the prompt information string String prompt = "Show parameters in selected Element:"; StringBuilder st = new StringBuilder(); // iterate element's parameters foreach (Parameter para in element.Parameters) { st.AppendLine(GetParameterInformation(para, document)); } // Give the user some information MessageBox.Show(prompt, "Revit", MessageBoxButtons.OK); } String GetParameterInformation(Parameter para, Document document) { string defName = para.Definition.Name + @"\t"; // Use different method to get parameter data according to the storage type switch (para.StorageType) { case StorageType.Double: //covert the number into Metric defName += " : " + para.AsValueString(); break; case StorageType.ElementId: //find out the name of the element ElementId id = para.AsElementId(); if (id.Value >= 0) { defName += " : " + document.GetElement(ref id).Name; } else { defName += " : " + id.Value.ToString(); } break; case StorageType.Integer: if (ParameterType.YesNo == para.Definition.ParameterType) { if (para.AsInteger() == 0) { defName += " : " + "False"; } else { defName += " : " + "True"; } } else { defName += " : " + para.AsInteger().ToString(); } break; case StorageType.String: defName += " : " + para.AsString(); break; default: defName = "Unexposed parameter."; break; } return defName; } |
Figure 26: Get wall parameters result