using System;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using System.Collections.Generic;
namespace TestTool
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class TestTool : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document document = uidoc.Document;
ICollection<ElementId> selectedIds = uidoc.Selection.GetElementIds();
foreach (ElementId id in selectedIds)
{
Element element = document.GetElement(id);
GetElementParameterInformation(document, element);
}
return Autodesk.Revit.UI.Result.Succeeded;
}
void GetElementParameterInformation(Document document, Element element)
{
String prompt = "■Show parameters in selected Element \r\n";
StringBuilder st = new StringBuilder();
foreach (Parameter para in element.Parameters)
{
st.AppendLine(GetParameterInformation(para, document));
}
TaskDialog.Show("Revit", prompt + st.ToString());
}
String GetParameterInformation(Parameter para, Document document)
{
string defName = para.Definition.Name + "\t : ";
string defValue = string.Empty;
switch (para.StorageType)
{
case StorageType.Double:
//covert the number into Metric
defValue = para.AsValueString();
break;
case StorageType.ElementId:
//find out the name of the element
Autodesk.Revit.DB.ElementId id = para.AsElementId();
if (id.IntegerValue >= 0)
{
defValue = document.GetElement(id).Name;
}
else
{
defValue = id.IntegerValue.ToString();
}
break;
case StorageType.Integer:
if (ParameterType.YesNo == para.Definition.ParameterType)
{
if (para.AsInteger() == 0)
{
defValue = "False";
}
else
{
defValue = "True";
}
}
else
{
defValue = para.AsInteger().ToString();
}
break;
case StorageType.String:
defValue = para.AsString();
break;
default:
defValue = "Unexposed parameter.";
break;
}
return defName + defValue;
}
}
}
|