data type handling from Revit 2022 to 2023

data type handling from Revit 2022 to 2023

jagadeesh116
Contributor Contributor
404 Views
3 Replies
Message 1 of 4

data type handling from Revit 2022 to 2023

jagadeesh116
Contributor
Contributor

def PBE(_Doc, _PN, _PT):
    _Bindg = _Doc.ParameterBindings
    _i = _Bindg.ForwardIterator()
    _i.Reset()
    while _i.MoveNext():
        if _i.Key != None and _i.Key.Name == _PN and _i.Key.GetDataType == _PT:
           return True
    return False

_PN = "Sampel"
_PT = ForgeTypeId.GetType(SpecTypeId.String.Text)


OUT = PBE(_Doc, _PN, _PT)

Revit 2022:
_Txt = System.Enum.GetValues(ParameterType)[1]
_Area = System.Enum.GetValues(ParameterType)[5]
_Nmbr = System.Enum.GetValues(ParameterType)[3]
_Bool = System.Enum.GetValues(ParameterType)[10]
_Int = System.Enum.GetValues(ParameterType)[2]
_Lngth = System.Enum.GetValues(ParameterType)[4]

Revit 2023:
_Txt = ForgeTypeId.GetType(SpecTypeId.String.Text)
_Area = ForgeTypeId.GetType(SpecTypeId.Area)
_Nmbr = ForgeTypeId.GetType(SpecTypeId.Number)
_Bool = ForgeTypeId.GetType(SpecTypeId.Boolean.YesNo)
_Int = ForgeTypeId.GetType(SpecTypeId.Int.Integer)
_Lngth = ForgeTypeId.GetType(SpecTypeId.Length)

 How can I update the data type handling in my PBE method from Revit 2022 to Revit 2023

Thanks in advance

 

 

0 Likes
405 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor

ForgeTypeId implements equality function and each class property of the SpecTypeId class  returns a ForgeTypeId therefore isn't it just:

 

_PT = SpecTypeId.String.Text

 

etc.

 

Not sure why you was returning all the values from an enum just to pick just one of them in the first place i.e. you could have just used the integer representation in your pre ForgeTypeId code.

 

Message 3 of 4

nice3point
Advocate
Advocate

You can use reflection in C# to get all values

 

 

var searchFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly;

var dataTypes = new List<PropertyInfo>();
dataTypes.AddRange(typeof(SpecTypeId).GetProperties(searchFlags));
dataTypes.AddRange(typeof(SpecTypeId.Boolean).GetProperties(searchFlags));
dataTypes.AddRange(typeof(SpecTypeId.String).GetProperties(searchFlags));
dataTypes.AddRange(typeof(SpecTypeId.Int).GetProperties(searchFlags));
dataTypes.AddRange(typeof(SpecTypeId.Reference).GetProperties(searchFlags));

foreach (var type in dataTypes)
{
    var dataType = (ForgeTypeId)type.GetValue(null);
}

 

 

 

Message 4 of 4

Jagadeesh_reddi
Observer
Observer

 

_i.Key.GetDataType() works for "data type of a parameter" in revit 2023

0 Likes