Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active May 13, 2021 03:53
Show Gist options
  • Save chuongmep/46f060907621248860d8c9c66e058357 to your computer and use it in GitHub Desktop.
Save chuongmep/46f060907621248860d8c9c66e058357 to your computer and use it in GitHub Desktop.
GetParameterValue DynamoRevit C#
public static object GetParameterValue(Autodesk.Revit.DB.Parameter param)
{
object result;
switch (param.StorageType)
{
case StorageType.ElementId:
int valueId = param.AsElementId().IntegerValue;
if (valueId > 0)
{
var elem = ElementIDLifecycleManager<int>.GetInstance().GetFirstWrapper(valueId) as Element;
result = ElementSelector.ByElementId(valueId, elem == null ? true : elem.IsRevitOwned);
}
else
{
int paramId = param.Id.IntegerValue;
if (paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM || paramId == (int)BuiltInParameter.ELEM_CATEGORY_PARAM_MT)
{
var categories = DocumentManager.Instance.CurrentDBDocument.Settings.Categories;
result = new Category(categories.get_Item((BuiltInCategory)valueId));
}
else
{
result = param.AsValueString();
}
}
break;
case StorageType.String:
result = param.AsString();
break;
case StorageType.Integer:
result = param.AsInteger();
break;
case StorageType.Double:
result = param.AsDouble() * Revit.GeometryConversion.UnitConverter.HostToDynamoFactor(param.Definition.GetSpecTypeId());
break;
default:
throw new Exception(string.Format(Properties.Resources.ParameterWithoutStorageType, param));
}
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment