KeachyPeenReturns
KeachyPeenReturns

Reputation: 71

How do I differentiate between Revit Parameter storage types since Revit stores Booleans as integer(1,0)?

I was trying to call up a list of Parameters (from two different families) in order to reconcile slight Parameter naming differences, and wanted to figure out what type of variable it was. I tried the code below:

switch (One_Param.StorageType)
{
    case StorageType.Double: { Double_Params.Add(One_Param); break; }
    case StorageType.Integer: { Integer_Params.Add(One_Param); break; }
    case StorageType.String: { String_Params.Add(One_Param); break; }
}

This did not give me what I needed, since Booleans are stored as integers as are line weights.

The correct code would be:

switch (Bogus_Param.Definition.ParameterType)
{
    case ParameterType.Length: { Correct_Param.Set(Bogus_Param.AsDouble()); break; }
    case ParameterType.Number: { Correct_Param.Set(Bogus_Param.AsDouble()); break; }
    case ParameterType.Integer: { Correct_Param.Set(Bogus_Param.AsInteger()); break; }
    case ParameterType.Text: { Correct_Param.Set(Bogus_Param.AsString()); break; }
    case ParameterType.YesNo: { Correct_Param.Set(Bogus_Param.AsInteger()); break; }
}

NOte that there are several other ParameterType available, including Volume. This sort of structure allows access to the "actual" storage type, and as long as you provide a valid value inside the .Set, this works well. So you still provide an integer to both the YesNo and Integer ParameterType.

Upvotes: 1

Views: 883

Answers (1)

KeachyPeenReturns
KeachyPeenReturns

Reputation: 71

FYI (with indirect suggestion via Spiderinnet): The method is to use parameter.Definition.ParameterType.ToString(), which will return "Length", "Text", "YesNo", "Volume", "Integer", etc....Since I am only seeking the "YesNo", it is easy to get Boolean parameters, but this can also be used to compare other values. This method also (nicely) returns a string "Invalid" for some other parameter types (not null).

Upvotes: 2

Related Questions