[c#]代码库
public string FindParameter(string parameterName, FamilyInstance familyInstanceName)
{
ParameterSetIterator i = familyInstanceName.Parameters.ForwardIterator();
i.Reset();
string valueOfParameter = null;
bool iMoreAttribute = i.MoveNext();
while (iMoreAttribute)
{
bool isFound = false;
object o = i.Current;
Parameter familyAttribute = o as Parameter;
if (familyAttribute.Definition.Name == parameterName)
{
//find the parameter whose name is same to the given parameter name
Autodesk.Revit.DB.StorageType st = familyAttribute.StorageType;
switch (st)
{
//get the storage type
case (Autodesk.Revit.DB.StorageType.Double):
{
if (parameterName == "Angle" )
{
//make conversion between degrees and radians
Double temp = familyAttribute.AsDouble();
valueOfParameter = Math.Round(temp * 180/(Math.PI),3).ToString();//+ "'";
}
else
{
valueOfParameter = familyAttribute.AsDouble().ToString();
}
break;
}
case (Autodesk.Revit.DB.StorageType.ElementId):
{
//get elementId as string
valueOfParameter = familyAttribute.AsElementId().ToString();
break;
}
case (Autodesk.Revit.DB.StorageType.Integer):
{
//get Integer as string
valueOfParameter = familyAttribute.AsInteger().ToString();
break;
}
case (Autodesk.Revit.DB.StorageType.String):
{
//get string
valueOfParameter = familyAttribute.AsString();
break;
}
default:
{
break;
}
}
isFound = true;
}
if(isFound)
{
break;
}
iMoreAttribute = i.MoveNext();
}
//return the value.
return valueOfParameter;
}