Skip to content

Commit 2ad9983

Browse files
Roof.Points bug fix integration in Revit 2025.3 (#3081)
* add wrapper over Revit RoofBase class to D4R Roof class * cast value data type to parameter value data type in order to avoid blind pointer cast in revit later on * cast value data type to parameter value data type, get parameter value data type from Storage type where value is null
1 parent ce5f184 commit 2ad9983

8 files changed

Lines changed: 83 additions & 9 deletions

File tree

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.41
1+
0.5.42

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.5.42
2+
* Fix Roof.Points raising an invalid argument exception by adding a wrapper over RoofBase Revit class to Roof D4R class
3+
* Add extra protection in FilterRule.ByRuleType node to prevent invalid data type casting in Revit
4+
* Improved FilterRule.ByRuleType node to use the same data type for the value and the parameter value that it takes as input
5+
16
## 0.5.41
27
* change D4R content publishing
38

src/Libraries/RevitNodes/Elements/InternalUtilities/ElementUtils.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,44 @@ public static object GetParameterValue(Autodesk.Revit.DB.Parameter param)
106106
return result;
107107
}
108108

109+
/// <summary>
110+
/// Get data type of parameter value, or based on its StorageType if value is null
111+
/// </summary>
112+
/// <param name="parameter"></param>
113+
/// <returns></returns>
114+
/// <exception cref="ApplicationException"></exception>
115+
[SupressImportIntoVM]
116+
public static Type GetParameterType(Elements.Parameter parameter)
117+
{
118+
Type parameterType;
119+
if (!parameter.HasValue)
120+
{
121+
switch (parameter.InternalParameter.StorageType)
122+
{
123+
case StorageType.String:
124+
parameterType = typeof(string);
125+
break;
126+
case Autodesk.Revit.DB.StorageType.Integer:
127+
parameterType = typeof(int);
128+
break;
129+
case Autodesk.Revit.DB.StorageType.Double:
130+
parameterType = typeof(double);
131+
break;
132+
case Autodesk.Revit.DB.StorageType.ElementId:
133+
parameterType = typeof(ElementId);
134+
break;
135+
default:
136+
throw new ApplicationException(Properties.Resources.InputValueParameterValueTypeMismatch);
137+
}
138+
}
139+
else
140+
{
141+
parameterType = parameter.Value.GetType();
142+
}
143+
144+
return parameterType;
145+
}
146+
109147
#region dynamic parameter setting methods
110148

111149
[SupressImportIntoVM]

src/Libraries/RevitNodes/Elements/InternalUtilities/ElementWrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ public static RoofType Wrap(Autodesk.Revit.DB.RoofType ele, bool isRevitOwned)
390390
return RoofType.FromExisting(ele, isRevitOwned);
391391
}
392392

393+
public static Roof Wrap(Autodesk.Revit.DB.RoofBase ele, bool isRevitOwned)
394+
{
395+
return Roof.FromExisting(ele, isRevitOwned);
396+
}
397+
393398
public static ScheduleOnSheet Wrap(Autodesk.Revit.DB.ScheduleSheetInstance ele, bool isRevitOwned)
394399
{
395400
return ScheduleOnSheet.FromExisting(ele, isRevitOwned);

src/Libraries/RevitNodes/Filter/FilterRule.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ public static FilterRule ByRuleType(string type, object value, Elements.Paramete
8585

8686
ElementId parameterId = parameter.InternalParameter.Id;
8787

88+
object convertedValue = null;
89+
try
90+
{
91+
Type parameterType = Revit.Elements.InternalUtilities.ElementUtils.GetParameterType(parameter);
92+
convertedValue = Convert.ChangeType(value, parameterType);
93+
}
94+
catch (Exception ex)
95+
{
96+
throw new ApplicationException(Properties.Resources.InputValueParameterValueTypeMismatch);
97+
}
98+
8899
// assemble the method name to construct a new filter using the FilterType
89100
string methodname = string.Format("{0}{1}{2}", new object[] { CreatePrefix , type, RuleSuffix});
90101

@@ -98,39 +109,39 @@ public static FilterRule ByRuleType(string type, object value, Elements.Paramete
98109
ruletype == RuleType.LessOrEqual
99110
)
100111
{
101-
if (value.GetType() == typeof(int))
112+
if (convertedValue.GetType() == typeof(int))
102113
{
103114
System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(int) });
104115
if (methodInfo != null)
105116
{
106-
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (int)value }));
117+
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (int)convertedValue }));
107118
}
108119
}
109-
else if (value.GetType() == typeof(double))
120+
else if (convertedValue.GetType() == typeof(double))
110121
{
111122
System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(double), typeof(double) });
112123
if (methodInfo != null)
113124
{
114-
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (double)value, 0 }));
125+
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (double)convertedValue, 0 }));
115126
}
116127
}
117-
else if (value.GetType() == typeof(string))
128+
else if (convertedValue.GetType() == typeof(string))
118129
{
119130
System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(string), typeof(bool) });
120131
if (methodInfo != null)
121132
{
122-
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (string)value, true }));
133+
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (string)convertedValue, true }));
123134
}
124135
}
125136
}
126137
else
127138
{
128-
if (value.GetType() == typeof(string))
139+
if (convertedValue.GetType() == typeof(string))
129140
{
130141
System.Reflection.MethodInfo methodInfo = typeof(ParameterFilterRuleFactory).GetMethod(methodname, new[] { typeof(ElementId), typeof(string), typeof(bool) });
131142
if (methodInfo != null)
132143
{
133-
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (string)value, true }));
144+
return new FilterRule((Autodesk.Revit.DB.FilterRule)methodInfo.Invoke(null, new object[] { parameterId, (string)convertedValue, true }));
134145
}
135146
}
136147
}

src/Libraries/RevitNodes/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Libraries/RevitNodes/Properties/Resources.en-US.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@
318318
<data name="InvalidFilterType" xml:space="preserve">
319319
<value>FilterType is not valid.</value>
320320
</data>
321+
<data name="InputValueParameterValueTypeMismatch" xml:space="preserve">
322+
<value>The value and the parameter values' data types are incompatible.</value>
323+
</data>
321324
<data name="InvalidFace" xml:space="preserve">
322325
<value>The selected face cannot be used to create a wall. Please use a mass face instead.</value>
323326
</data>

src/Libraries/RevitNodes/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@
312312
<data name="InvalidFilterType" xml:space="preserve">
313313
<value>FilterType is not valid.</value>
314314
</data>
315+
<data name="InputValueParameterValueTypeMismatch" xml:space="preserve">
316+
<value>The value and the parameter values' data types are incompatible.</value>
317+
</data>
315318
<data name="InvalidGroupType" xml:space="preserve">
316319
<value>{0} is not a valid GroupType.</value>
317320
</data>

0 commit comments

Comments
 (0)