From 6525ab701deb0f62401386571c46cf2e2599ae60 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Mon, 29 Jan 2024 19:04:11 +0100 Subject: [PATCH 001/131] draft oM classes added --- Revit_oM/Elements/View.cs | 14 ++++++++++++++ Revit_oM/Elements/ViewFilter.cs | 16 ++++++++++++++++ Revit_oM/Views/FilterWithOverrides.cs | 17 +++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 Revit_oM/Elements/View.cs create mode 100644 Revit_oM/Elements/ViewFilter.cs create mode 100644 Revit_oM/Views/FilterWithOverrides.cs diff --git a/Revit_oM/Elements/View.cs b/Revit_oM/Elements/View.cs new file mode 100644 index 000000000..5ce73c656 --- /dev/null +++ b/Revit_oM/Elements/View.cs @@ -0,0 +1,14 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Views +{ + public class View : BHoMObject + { + public virtual List FiltersWithOverrides { get; set; } + } +} diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs new file mode 100644 index 000000000..44400a0d3 --- /dev/null +++ b/Revit_oM/Elements/ViewFilter.cs @@ -0,0 +1,16 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Elements +{ + public class ViewFilter : BHoMObject + { + public virtual List Categories { get; set; } + + //public List Rules { get; set; } + } +} diff --git a/Revit_oM/Views/FilterWithOverrides.cs b/Revit_oM/Views/FilterWithOverrides.cs new file mode 100644 index 000000000..c5325f31e --- /dev/null +++ b/Revit_oM/Views/FilterWithOverrides.cs @@ -0,0 +1,17 @@ +using BH.oM.Adapters.Revit.Elements; +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit +{ + public class FilterWithOverrides + { + public virtual ViewFilter Filter { get; set; } + + //public virtual List Overrides { get; set; } + } +} From 495685a4fcca9fd01cd227f4b70862aa67723c43 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Mon, 29 Jan 2024 19:04:30 +0100 Subject: [PATCH 002/131] draft support for pull of views and view filters added --- .../Convert/Revit/FromRevit/View.cs | 71 +++++++++++++++++++ .../Convert/Revit/FromRevit/ViewFilter.cs | 71 +++++++++++++++++++ Revit_Core_Engine/Query/BHoMType.cs | 32 +++++++++ 3 files changed, 174 insertions(+) create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/View.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs new file mode 100644 index 000000000..a1f58357d --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -0,0 +1,71 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base; +using BH.oM.Base.Attributes; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.Revit.Engine.Core +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] + //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] + public static oM.Adapters.Revit.Views.View ViewFromRevit(this View revitView, RevitSettings settings = null, Dictionary> refObjects = null) + { + settings = settings.DefaultIfNull(); + + oM.Adapters.Revit.Views.View view = refObjects.GetValue(revitView.Id.IntegerValue); + if (view != null) + return view; + + view = new oM.Adapters.Revit.Views.View { Name = revitView.Name }; + //TODO: here goes the convertion method + + //Set identifiers, parameters & custom data + view.SetIdentifiers(revitView); + view.CopyParameters(revitView, settings.MappingSettings); + view.SetProperties(revitView, settings.MappingSettings); + + refObjects.AddOrReplace(revitView.Id, view); + return view; + } + + /***************************************************/ + } +} + + + + + diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs new file mode 100644 index 000000000..f763ce32b --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -0,0 +1,71 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base; +using BH.oM.Base.Attributes; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.Revit.Engine.Core +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] + //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] + public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this ParameterFilterElement revitViewFilter, RevitSettings settings = null, Dictionary> refObjects = null) + { + settings = settings.DefaultIfNull(); + + oM.Adapters.Revit.Elements.ViewFilter viewFilter = refObjects.GetValue(revitViewFilter.Id.IntegerValue); + if (viewFilter != null) + return viewFilter; + + viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; + //TODO: here goes the convertion method + + //Set identifiers, parameters & custom data + viewFilter.SetIdentifiers(revitViewFilter); + viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); + viewFilter.SetProperties(revitViewFilter, settings.MappingSettings); + + refObjects.AddOrReplace(revitViewFilter.Id, viewFilter); + return viewFilter; + } + + /***************************************************/ + } +} + + + + + diff --git a/Revit_Core_Engine/Query/BHoMType.cs b/Revit_Core_Engine/Query/BHoMType.cs index 0dd6547b1..4faaad9c2 100644 --- a/Revit_Core_Engine/Query/BHoMType.cs +++ b/Revit_Core_Engine/Query/BHoMType.cs @@ -53,6 +53,38 @@ public static Type IBHoMType(this Element element, Discipline discipline, RevitS /**** Public Methods ****/ /***************************************************/ + //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] + //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] + //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + public static Type BHoMType(this View view, Discipline discipline, RevitSettings settings = null) + { + switch (discipline) + { + default: + return typeof(BH.oM.Adapters.Revit.Views.View); + } + } + + /***************************************************/ + + //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] + //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] + //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + public static Type BHoMType(this ParameterFilterElement viewFilter, Discipline discipline, RevitSettings settings = null) + { + switch (discipline) + { + default: + return typeof(BH.oM.Adapters.Revit.Elements.ViewFilter); + } + } + + /***************************************************/ + [Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] [Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] From 48d61ff7690d4bae4e405fda2f5af0c1472a3e5d Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Mon, 29 Jan 2024 19:04:42 +0100 Subject: [PATCH 003/131] draft support for views and view filters added --- .../Revit/ToRevit/ParameterFilterElement.cs | 66 +++++++++++++++++++ Revit_Core_Engine/Convert/ToRevit.cs | 13 ++++ Revit_Core_Engine/Modify/Update.cs | 39 +++++++++++ 3 files changed, 118 insertions(+) create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs new file mode 100644 index 000000000..7bf653286 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -0,0 +1,66 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base; +using BH.oM.Base.Attributes; +using BH.oM.Physical.Elements; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; + +namespace BH.Revit.Engine.Core +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + //[Description("Converts BH.oM.Adapters.Revit.Elements.Assembly to a Revit AssemblyInstance." + + // "\nOnly the assembly instance itself is created, while any updates of name or parameters need to happen in a separate transaction, which is caused by Revit API limitations.")] + //[Input("assembly", "BH.oM.Adapters.Revit.Elements.Assembly to be converted.")] + //[Input("document", "Revit document, in which the output of the convert will be created.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("assemblyInstance", "Revit AssemblyInstance resulting from converting the input BH.oM.Adapters.Revit.Elements.Assembly.")] + public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) + { + ParameterFilterElement revitFilter = refObjects.GetValue(document, filter.BHoM_Guid); + if (revitFilter != null) + return revitFilter; + + //TODO: fill this in with the logic + List categories = new List(); + revitFilter = ParameterFilterElement.Create(document, filter.Name, categories); + + revitFilter.CopyParameters(filter, settings); + refObjects.AddOrReplace(filter, revitFilter); + return revitFilter; + } + + /***************************************************/ + } +} + diff --git a/Revit_Core_Engine/Convert/ToRevit.cs b/Revit_Core_Engine/Convert/ToRevit.cs index dca092351..9eb95122c 100644 --- a/Revit_Core_Engine/Convert/ToRevit.cs +++ b/Revit_Core_Engine/Convert/ToRevit.cs @@ -40,6 +40,19 @@ public static partial class Convert /**** Public methods ****/ /***************************************************/ + //[Description("Converts BH.oM.Spatial.SettingOut.Grid to a Revit Grid or MultiSegmentGrid.")] + //[Input("grid", "BH.oM.Spatial.SettingOut.Grid to be converted.")] + //[Input("document", "Revit document, in which the output of the convert will be created.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("grid", "Revit Grid or MultiSegmentGrid resulting from converting the input BH.oM.Spatial.SettingOut.Grid.")] + public static Element ToRevit(this BH.oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) + { + return filter.ToRevitParameterFilterElement(document, settings, refObjects); + } + + /***************************************************/ + [Description("Converts BH.oM.Spatial.SettingOut.Grid to a Revit Grid or MultiSegmentGrid.")] [Input("grid", "BH.oM.Spatial.SettingOut.Grid to be converted.")] [Input("document", "Revit document, in which the output of the convert will be created.")] diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 22ce82abf..cd22bdb7d 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -243,6 +243,45 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re return true; } + /***************************************************/ + + //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] + //[Input("element", "Revit Assembly instance to be updated.")] + //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] + //[Input("settings", "Revit adapter settings to be used while performing the action.")] + //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] + //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] + public static bool Update(this View element, BH.oM.Adapters.Revit.Views.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + { + //TODO: fill in with logic + // update the filter overrides based on the BHoM view + // update name + // update parameteres (done below) + // otherhers as the class grows + + element.CopyParameters(bHoMObject, settings); + return true; + } + + /***************************************************/ + + //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] + //[Input("element", "Revit Assembly instance to be updated.")] + //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] + //[Input("settings", "Revit adapter settings to be used while performing the action.")] + //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] + //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] + public static bool Update(this ParameterFilterElement element, BH.oM.Adapters.Revit.Elements.ViewFilter bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + { + //TODO: fill in with logic + // update categories + // update parameteres (done below) + // maybe name? + + element.CopyParameters(bHoMObject, settings); + return true; + } + /***************************************************/ /**** Disallowed Types ****/ From 917cf9f101e0dba9dd96cfb04908db3f7f5a6a53 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Feb 2024 07:27:10 +0000 Subject: [PATCH 004/131] Add bespoke classes defining graphics settings for new view filters - Enum LinePattern - Enum SolidPattern - Class OverrideGraphicSettings - Class FilterRule --- Revit_oM/Elements/FillPattern.cs | 20 +++++++++++++++++++ Revit_oM/Elements/FilterRule.cs | 15 ++++++++++++++ Revit_oM/Elements/LinePattern.cs | 16 +++++++++++++++ Revit_oM/Elements/OverrideGraphicSettings.cs | 21 ++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 Revit_oM/Elements/FillPattern.cs create mode 100644 Revit_oM/Elements/FilterRule.cs create mode 100644 Revit_oM/Elements/LinePattern.cs create mode 100644 Revit_oM/Elements/OverrideGraphicSettings.cs diff --git a/Revit_oM/Elements/FillPattern.cs b/Revit_oM/Elements/FillPattern.cs new file mode 100644 index 000000000..ab3c94ee6 --- /dev/null +++ b/Revit_oM/Elements/FillPattern.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public enum FillPattern + { + CROSSHATCH, + DIAGONAL_CROSSHATCH, + DIAGONAL_DOWN, + DIAGONAL_UP, + HORIZONTAL, + STEEL, + SOLID, + VERTICAL + } +} diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Elements/FilterRule.cs new file mode 100644 index 000000000..5993b6993 --- /dev/null +++ b/Revit_oM/Elements/FilterRule.cs @@ -0,0 +1,15 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Elements +{ + public abstract class FilterRule : BHoMObject + { + public virtual String ElementId { get; set; } + } + +} diff --git a/Revit_oM/Elements/LinePattern.cs b/Revit_oM/Elements/LinePattern.cs new file mode 100644 index 000000000..f75938f8a --- /dev/null +++ b/Revit_oM/Elements/LinePattern.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public enum LinePattern + { + DASH, + DOT, + HIDDEN, + SOLID + } +} diff --git a/Revit_oM/Elements/OverrideGraphicSettings.cs b/Revit_oM/Elements/OverrideGraphicSettings.cs new file mode 100644 index 000000000..c3922bd80 --- /dev/null +++ b/Revit_oM/Elements/OverrideGraphicSettings.cs @@ -0,0 +1,21 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public class OverrideGraphicSettings : BHoMObject + { + public virtual Color LineColor { get; set; } + public virtual Color CutColor { get; set; } + public virtual Color SurfaceColor { get; set; } + public virtual LinePattern LinePattern { get; set; } + public virtual FillPattern CutPattern { get; set; } + public virtual FillPattern SurfacePattern { get; set; } + + } +} From fcb57c0a5a011aef1ae0a736a71d2ee431ef5310 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Feb 2024 07:30:00 +0000 Subject: [PATCH 005/131] Rename Class FilterWithOverrides to ViewFilterWithOverrides --- .../{FilterWithOverrides.cs => ViewFilterWithOverrides.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename Revit_oM/Views/{FilterWithOverrides.cs => ViewFilterWithOverrides.cs} (65%) diff --git a/Revit_oM/Views/FilterWithOverrides.cs b/Revit_oM/Views/ViewFilterWithOverrides.cs similarity index 65% rename from Revit_oM/Views/FilterWithOverrides.cs rename to Revit_oM/Views/ViewFilterWithOverrides.cs index c5325f31e..4b73e0b39 100644 --- a/Revit_oM/Views/FilterWithOverrides.cs +++ b/Revit_oM/Views/ViewFilterWithOverrides.cs @@ -1,5 +1,6 @@ using BH.oM.Adapters.Revit.Elements; using BH.oM.Base; +using BH.oM.Revit.Elements; using System; using System.Collections.Generic; using System.Linq; @@ -8,10 +9,9 @@ namespace BH.oM.Adapters.Revit { - public class FilterWithOverrides + public class ViewFilterWithOverrides { public virtual ViewFilter Filter { get; set; } - - //public virtual List Overrides { get; set; } + public virtual List Overrides { get; set; } } } From 1b9d28d0108f0235328455ed8533fcdfc074a6db Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Feb 2024 08:53:49 +0000 Subject: [PATCH 006/131] Add FilterRuleType Enumeration - Enumeration Class that works as an attribute of the FilterRule Class, allowing to avoid the use of several abstract and concrete classes for each type of rule type. --- Revit_oM/Elements/ViewFilter.cs | 3 +-- Revit_oM/Views/FilterRuleType.cs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Revit_oM/Views/FilterRuleType.cs diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 44400a0d3..802bd2803 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -10,7 +10,6 @@ namespace BH.oM.Adapters.Revit.Elements public class ViewFilter : BHoMObject { public virtual List Categories { get; set; } - - //public List Rules { get; set; } + public List Rules { get; set; } } } diff --git a/Revit_oM/Views/FilterRuleType.cs b/Revit_oM/Views/FilterRuleType.cs new file mode 100644 index 000000000..01119a1a0 --- /dev/null +++ b/Revit_oM/Views/FilterRuleType.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public enum FilterRuleType + { + EQUALS, + GREATER, + GREATER_OR_EQUAL, + LESS, + LESS_OR_EQUAL, + CONTAINS, + NOT_CONTAINS, + BEGINSWITH, + NOT_BEGINSWITH, + ENDSWITH, + NOT_ENDSWITH + } +} From e70ed5666f75975565c5bda2347883e6c5bc6382 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 12:13:15 +0000 Subject: [PATCH 007/131] Move classes FillPattern, FilterRule and LinePattern from Elements to Views namespace --- Revit_oM/{Elements => Views}/FillPattern.cs | 2 +- Revit_oM/{Elements => Views}/FilterRule.cs | 7 +++++-- Revit_oM/{Elements => Views}/LinePattern.cs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) rename Revit_oM/{Elements => Views}/FillPattern.cs (91%) rename Revit_oM/{Elements => Views}/FilterRule.cs (50%) rename Revit_oM/{Elements => Views}/LinePattern.cs (87%) diff --git a/Revit_oM/Elements/FillPattern.cs b/Revit_oM/Views/FillPattern.cs similarity index 91% rename from Revit_oM/Elements/FillPattern.cs rename to Revit_oM/Views/FillPattern.cs index ab3c94ee6..1e9451739 100644 --- a/Revit_oM/Elements/FillPattern.cs +++ b/Revit_oM/Views/FillPattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Revit.Views { public enum FillPattern { diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Views/FilterRule.cs similarity index 50% rename from Revit_oM/Elements/FilterRule.cs rename to Revit_oM/Views/FilterRule.cs index 5993b6993..a6a1fc79b 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/Views/FilterRule.cs @@ -5,11 +5,14 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.Views { public abstract class FilterRule : BHoMObject { - public virtual String ElementId { get; set; } + public virtual FilterRuleType RuleType { get; set; } + public virtual string ParameterName { get; set; } + public virtual object Value { get; set; } + } } diff --git a/Revit_oM/Elements/LinePattern.cs b/Revit_oM/Views/LinePattern.cs similarity index 87% rename from Revit_oM/Elements/LinePattern.cs rename to Revit_oM/Views/LinePattern.cs index f75938f8a..6e1292999 100644 --- a/Revit_oM/Elements/LinePattern.cs +++ b/Revit_oM/Views/LinePattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Revit.Views { public enum LinePattern { From 0ed3572392623c16f11272a833a4740da85645c5 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:05:54 +0000 Subject: [PATCH 008/131] Implement Update of View based on filters and overrides --- Revit_Core_Engine/Modify/Update.cs | 102 ++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index cd22bdb7d..465b2439f 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -20,16 +20,23 @@ * along with this code. If not, see . */ +using Autodesk.Revit.Creation; using Autodesk.Revit.DB; using BH.Engine.Adapters.Revit; using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Settings; +using BH.oM.Adapters.Revit.Views; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.MEP.Equipment.Parts; using System; using System.Collections.Generic; using System.ComponentModel; +using System.Drawing; using System.Linq; +using Color = Autodesk.Revit.DB.Color; +using OverrideGraphicSettings = Autodesk.Revit.DB.OverrideGraphicSettings; +using View = Autodesk.Revit.DB.View; namespace BH.Revit.Engine.Core { @@ -245,19 +252,52 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re /***************************************************/ - //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] - //[Input("element", "Revit Assembly instance to be updated.")] - //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] - //[Input("settings", "Revit adapter settings to be used while performing the action.")] - //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] - //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] - public static bool Update(this View element, BH.oM.Adapters.Revit.Views.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + [Description("Updates the existing Revit View based on the given BHoM View.")] + [Input("element", "Revit View instance to be updated.")] + [Input("bHoMObject", "BHoM View, based on which the Revit View will be updated.")] + [Input("settings", "Revit adapter settings to be used while performing the action.")] + [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] + [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] + public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) { - //TODO: fill in with logic - // update the filter overrides based on the BHoM view - // update name - // update parameteres (done below) - // otherhers as the class grows + /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ + + // Via Streams... + bHoMObject.FiltersWithOverrides + // 1. Turn Filters and Overrides into Keys and Values of a Dictionary + .ToDictionary(x => x.Filter, x => x.Overrides) + // 2. Turn the Dictionary into a List of KeyValue Pairs (to allow use of ForEach() + .ToList>() + // 3. Assign Filters to View and Set their Overrides + .ForEach(kvp => { ParameterFilterElement pfe = kvp.Key.ToRevitParameterFilterElement(element.Document, settings); + // 3.1 Add ViewFilter to the View + element.AddFilter(pfe.Id); + // 3.2 Get the Revit FillPatternElement Objects for CutPattern and SurfacePattern + FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); + FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); + // 3.3 Create the OverrideGraphics by Properties + OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); + Color revitCutColor = new Color(kvp.Value.CutColor.R, kvp.Value.CutColor.G, kvp.Value.CutColor.B); + Color revitSurfaceColor = new Color(kvp.Value.SurfaceColor.R, kvp.Value.SurfaceColor.G, kvp.Value.SurfaceColor.B); + overrideGraphicsSettings.SetCutLineColor(revitLineColor); + overrideGraphicsSettings.SetProjectionLineColor(revitLineColor); + overrideGraphicsSettings.SetCutBackgroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutBackgroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetCutForegroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutForegroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetSurfaceBackgroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceBackgroundPatternColor(revitSurfaceColor); + overrideGraphicsSettings.SetSurfaceForegroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceForegroundPatternColor(revitSurfaceColor); + // 3.4 Assign Overrides to the ViewFilter + element.SetFilterOverrides(pfe.Id, overrideGraphicsSettings); }); element.CopyParameters(bHoMObject, settings); return true; @@ -265,19 +305,32 @@ public static bool Update(this View element, BH.oM.Adapters.Revit.Views.View bHo /***************************************************/ - //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] - //[Input("element", "Revit Assembly instance to be updated.")] - //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] - //[Input("settings", "Revit adapter settings to be used while performing the action.")] - //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] - //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] + [Description("Updates the existing Revit ParameterFilterElement based on the given BHoM ViewFilter.")] + [Input("element", "Revit ParameterFilterElement to be updated.")] + [Input("bHoMObject", "BHoM ViewFilter, based on which the Revit element will be updated.")] + [Input("settings", "Revit adapter settings to be used while performing the action.")] + [Input("setLocationOnUpdate", "Revit ParameterFilterElement instance does not have location property, therefore this parameter is irrelevant.")] + [Output("success", "True if the Revit ParameterFilterElement instance has been updated successfully based on the input BHoM ViewFilter.")] public static bool Update(this ParameterFilterElement element, BH.oM.Adapters.Revit.Elements.ViewFilter bHoMObject, RevitSettings settings, bool setLocationOnUpdate) { - //TODO: fill in with logic - // update categories - // update parameteres (done below) - // maybe name? - + // 1. Collect the ElementIds of the filter's categories - via Streams + List builtInCategoryIds= bHoMObject.Categories.Select(catName => { BuiltInCategory builtInCat; + Enum.TryParse(catName, out builtInCat); + return builtInCat; }) + .Select(builtInCat=> new ElementId(builtInCat)) + .ToList(); + // 2. Assign Categories' Ids to the ParameterFilterElement + element.SetCategories(builtInCategoryIds); + // 3. Assign Name to the ParameterFilterElement + element.Name = bHoMObject.Name; + // 4. Assign Filter Rules to the ParameterFilterElement - via Streams + element.SetElementFilter(new LogicalAndFilter(bHoMObject.Rules + .Select(filterRule => Convert.filterRuleToRevit(element.Document, filterRule)) + .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) + .Cast() + .ToList())); + + // 5. Copy parameters to ParameterElementFilter element.CopyParameters(bHoMObject, settings); return true; } @@ -362,6 +415,9 @@ private static void ErrorOnCategoryChange(this FamilyInstance element, IInstance } /***************************************************/ + + + } } From 561839a3ef406ab058c18273e622184e0e2cb410 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:09:15 +0000 Subject: [PATCH 009/131] Add minor updates to main classes in Elements namespace --- Revit_oM/Elements/OverrideGraphicSettings.cs | 5 +++-- Revit_oM/Elements/View.cs | 2 +- Revit_oM/Elements/ViewFilter.cs | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Revit_oM/Elements/OverrideGraphicSettings.cs b/Revit_oM/Elements/OverrideGraphicSettings.cs index c3922bd80..b2e205d57 100644 --- a/Revit_oM/Elements/OverrideGraphicSettings.cs +++ b/Revit_oM/Elements/OverrideGraphicSettings.cs @@ -1,4 +1,5 @@ using BH.oM.Base; +using BH.oM.Revit.Views; using System; using System.Collections.Generic; using System.Drawing; @@ -6,7 +7,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class OverrideGraphicSettings : BHoMObject { @@ -16,6 +17,6 @@ public class OverrideGraphicSettings : BHoMObject public virtual LinePattern LinePattern { get; set; } public virtual FillPattern CutPattern { get; set; } public virtual FillPattern SurfacePattern { get; set; } - + } } diff --git a/Revit_oM/Elements/View.cs b/Revit_oM/Elements/View.cs index 5ce73c656..ae7d48c58 100644 --- a/Revit_oM/Elements/View.cs +++ b/Revit_oM/Elements/View.cs @@ -9,6 +9,6 @@ namespace BH.oM.Adapters.Revit.Views { public class View : BHoMObject { - public virtual List FiltersWithOverrides { get; set; } + public virtual List FiltersWithOverrides { get; set; } } } diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 802bd2803..943746066 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,4 +1,5 @@ using BH.oM.Base; +using BH.oM.Revit.Views; using System; using System.Collections.Generic; using System.Linq; @@ -10,6 +11,6 @@ namespace BH.oM.Adapters.Revit.Elements public class ViewFilter : BHoMObject { public virtual List Categories { get; set; } - public List Rules { get; set; } + public virtual List Rules { get; set; } } } From ae53ef63a19eaa71a32ea5b1e0f46177d778615f Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:11:25 +0000 Subject: [PATCH 010/131] Implement Conversion of BHoM classes to Revit --- .../Revit/ToRevit/ParameterFilterElement.cs | 121 ++++++++++++++++-- Revit_Core_Engine/Convert/ToRevit.cs | 12 +- 2 files changed, 117 insertions(+), 16 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 7bf653286..dc5d78549 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -20,15 +20,21 @@ * along with this code. If not, see . */ +using Autodesk.Revit.Creation; using Autodesk.Revit.DB; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; +using BH.oM.Revit.Views; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Runtime.CompilerServices; +using Document = Autodesk.Revit.DB.Document; +using FilterRule = BH.oM.Revit.Views.FilterRule; namespace BH.Revit.Engine.Core { @@ -38,22 +44,48 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - //[Description("Converts BH.oM.Adapters.Revit.Elements.Assembly to a Revit AssemblyInstance." + - // "\nOnly the assembly instance itself is created, while any updates of name or parameters need to happen in a separate transaction, which is caused by Revit API limitations.")] - //[Input("assembly", "BH.oM.Adapters.Revit.Elements.Assembly to be converted.")] - //[Input("document", "Revit document, in which the output of the convert will be created.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("assemblyInstance", "Revit AssemblyInstance resulting from converting the input BH.oM.Adapters.Revit.Elements.Assembly.")] + [Description("Converts BH.oM.Adapters.Revit.Elements.ViewFilter to a Revit ParameterFilterElement." + + "\nThe Filter Rules are assigned after its creation due to Revit API limitations.")] + [Input("filter", "BH.oM.Adapters.Revit.Elements.ViewFilter to be converted.")] + [Input("document", "Revit document, in which the output of the convert will be created.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("filter", "Revit ParameterFilterElement resulting from converting the input BH.oM.Adapters.Revit.Elements.ViewFilter.")] public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) { ParameterFilterElement revitFilter = refObjects.GetValue(document, filter.BHoM_Guid); if (revitFilter != null) return revitFilter; - //TODO: fill this in with the logic - List categories = new List(); - revitFilter = ParameterFilterElement.Create(document, filter.Name, categories); + // 1. CREATE PARAMETERFILTERELEMENT with ASSIGNED CATEGORIES LIST + + /* 1.1 Turn list of Category Names into List of Category ElementIds via use of Streams */ + + List categoryIdsList = filter.Categories + // Format the string name of the categories + .Select(catName => catName.ToUpper().Replace(" ", "")) + // Get the corresponding BuiltInCategories + .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) + .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("ost_", "")) + .ToList(); + return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]);}) + // Get the ElementIds of the BuiltInCategories + .Select(builtInCat => new ElementId(builtInCat)) + // Turn the Stream into a List of ElementIds + .ToList(); + + /* 1.2 Create the ParameterFilterElement in the current Revit Document */ + revitFilter = ParameterFilterElement.Create(document, filter.Name, categoryIdsList); + + + // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT + + /* Via use of Streams*/ + revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules + .Select(filterRule => filterRuleToRevit(document, filterRule)) + .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) + .Cast() + .ToList())); revitFilter.CopyParameters(filter, settings); refObjects.AddOrReplace(filter, revitFilter); @@ -61,6 +93,75 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt } /***************************************************/ + + private static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { + + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + + ElementClassFilter paramFilter = new ElementClassFilter(typeof(Parameter)); + ElementClassFilter builtInParamFilter = new ElementClassFilter(typeof(BuiltInParameter)); + LogicalOrFilter logicalOrFilter = new LogicalOrFilter(paramFilter, builtInParamFilter); + + + ElementId parameterId = new FilteredElementCollector(document) + .WherePasses(logicalOrFilter) + .Where(par => par.Name.Equals(filterRule.ParameterName)) + .First() + .Id; + + switch (filterRule.RuleType) { + case FilterRuleType.BEGINSWITH: + revitFilterRule=ParameterFilterRuleFactory + .CreateBeginsWithRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.CONTAINS: + revitFilterRule = ParameterFilterRuleFactory + .CreateContainsRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.ENDSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateEndsWithRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.EQUALS: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, (int) filterRule.Value); + break; + case FilterRuleType.GREATER: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.GREATER_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.LESS: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.LESS_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.NOT_BEGINSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.NOT_CONTAINS: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.NOT_ENDSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEndsWithRule(parameterId, (string) filterRule.Value, false); + break; + default: + break;} + + return revitFilterRule; + } } + + + } diff --git a/Revit_Core_Engine/Convert/ToRevit.cs b/Revit_Core_Engine/Convert/ToRevit.cs index 9eb95122c..e97f6164d 100644 --- a/Revit_Core_Engine/Convert/ToRevit.cs +++ b/Revit_Core_Engine/Convert/ToRevit.cs @@ -40,12 +40,12 @@ public static partial class Convert /**** Public methods ****/ /***************************************************/ - //[Description("Converts BH.oM.Spatial.SettingOut.Grid to a Revit Grid or MultiSegmentGrid.")] - //[Input("grid", "BH.oM.Spatial.SettingOut.Grid to be converted.")] - //[Input("document", "Revit document, in which the output of the convert will be created.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("grid", "Revit Grid or MultiSegmentGrid resulting from converting the input BH.oM.Spatial.SettingOut.Grid.")] + [Description("Converts BH.oM.Adapters.Revit.Elements.ViewFilter to a Revit ParameterFilterElement.")] + [Input("filter", "BH.oM.Adapters.Revit.Elements.ViewFilter to be converted.")] + [Input("document", "Revit document, in which the output of the convert will be created.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("parameterFilterElement", "Revit ParameterFilterElement resulting from converting the input BH.oM.Adapters.Revit.Elements.ViewFilter.")] public static Element ToRevit(this BH.oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) { return filter.ToRevitParameterFilterElement(document, settings, refObjects); From b38eab0535a35ad44da66ea0106d84991c24c4cb Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:14:29 +0000 Subject: [PATCH 011/131] Add minor updates to BHoM ViewFilterOverrides Class --- Revit_oM/Views/ViewFilterWithOverrides.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Revit_oM/Views/ViewFilterWithOverrides.cs b/Revit_oM/Views/ViewFilterWithOverrides.cs index 4b73e0b39..8e9cd7162 100644 --- a/Revit_oM/Views/ViewFilterWithOverrides.cs +++ b/Revit_oM/Views/ViewFilterWithOverrides.cs @@ -1,17 +1,16 @@ using BH.oM.Adapters.Revit.Elements; using BH.oM.Base; -using BH.oM.Revit.Elements; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit +namespace BH.oM.Revit.Views { - public class ViewFilterWithOverrides + public class ViewFilterWithOverrides: BHoMObject { public virtual ViewFilter Filter { get; set; } - public virtual List Overrides { get; set; } + public virtual OverrideGraphicSettings Overrides { get; set; } } } From 54a014356d03b072fad3a5e8cac65a5defd51bd9 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:15:19 +0000 Subject: [PATCH 012/131] Update Query/BHoMType.cs class for View and ParameterFilterElement --- Revit_Core_Engine/Query/BHoMType.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Revit_Core_Engine/Query/BHoMType.cs b/Revit_Core_Engine/Query/BHoMType.cs index 4faaad9c2..4d68623e3 100644 --- a/Revit_Core_Engine/Query/BHoMType.cs +++ b/Revit_Core_Engine/Query/BHoMType.cs @@ -53,27 +53,27 @@ public static Type IBHoMType(this Element element, Discipline discipline, RevitS /**** Public Methods ****/ /***************************************************/ - //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] - //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] - //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] - //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] - //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + [Description("Finds a suitable BHoM type to convert the given Revit View to, based on the requested engineering discipline and adapter settings.")] + [Input("view", "Revit View to find a correspondent BHoM type.")] + [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + [Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + [Output("bHoMType", "A suitable BHoM type to convert the given Revit View to.")] public static Type BHoMType(this View view, Discipline discipline, RevitSettings settings = null) { switch (discipline) { default: - return typeof(BH.oM.Adapters.Revit.Views.View); + return typeof(BH.oM.Adapters.Revit.Elements.View); } } /***************************************************/ - //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] - //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] - //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] - //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] - //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + [Description("Finds a suitable BHoM type to convert the given Revit ParameterFilterElement to, based on the requested engineering discipline and adapter settings.")] + [Input("viewFilter", "Revit ParameterFilterElement to find a correspondent BHoM type.")] + [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + [Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + [Output("bHoMType", "A suitable BHoM type to convert the given Revit ParameterFilterElement to.")] public static Type BHoMType(this ParameterFilterElement viewFilter, Discipline discipline, RevitSettings settings = null) { switch (discipline) From 07b0fa183db19ce1fe001e114e8326a41582e8d9 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 12 Mar 2024 13:13:26 +0000 Subject: [PATCH 013/131] Minor updates to main new classes for View and filtering --- .../Convert/Revit/FromRevit/View.cs | 56 ++++++++++++++++--- .../Convert/Revit/FromRevit/ViewFilter.cs | 26 ++++++--- .../Revit/ToRevit/ParameterFilterElement.cs | 2 +- Revit_oM/Elements/View.cs | 3 +- Revit_oM/Views/FilterRule.cs | 2 +- 5 files changed, 70 insertions(+), 19 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index a1f58357d..84254b325 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -22,11 +22,19 @@ using Autodesk.Revit.DB; using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.Revit.Views; +using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Xml.Linq; +using FilterRule = BH.oM.Revit.Views.FilterRule; +using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; +using View = Autodesk.Revit.DB.View; namespace BH.Revit.Engine.Core { @@ -36,20 +44,52 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] - //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] - public static oM.Adapters.Revit.Views.View ViewFromRevit(this View revitView, RevitSettings settings = null, Dictionary> refObjects = null) + [Description("Converts a Revit View to BH.oM.Adapters.Revit.Elements.View.")] + [Input("revitView", "Revit View to be converted.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("view", "BH.oM.Adapters.Revit.Elements.View resulting from converting the input Revit View.")] + public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, RevitSettings settings = null, Dictionary> refObjects = null) { settings = settings.DefaultIfNull(); - oM.Adapters.Revit.Views.View view = refObjects.GetValue(revitView.Id.IntegerValue); + oM.Adapters.Revit.Elements.View view = refObjects.GetValue(revitView.Id.IntegerValue); if (view != null) return view; - view = new oM.Adapters.Revit.Views.View { Name = revitView.Name }; + /* 1. Transfer NAME */ + view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name }; + + List filtersWithOverrides; + List viewFilters; + List overrides; + + List> categoriesNames=revitView.GetFilters() + .Select(elId => revitView.Document.GetElement(elId)) + .Cast() + .Select(pfe => pfe.GetCategories().ToList()) + .Select(catIdsList => catIdsList.Select(catId => revitView.Document.GetElement(catId).Name).ToList()) + .ToList>(); + + List filterRules = revitView.GetFilters() + .Select(elId => revitView.Document.GetElement(elId)) + .Cast() + .Select(epf => epf.GetRules()) + .ToDictionary(fvr => fvr.GetType(), + fvr => + { + Element param = revitView.Document.GetElement(fvr.GetRuleParameter()); + string paramName = param.Name; + string value = fvr.ToString(); + return new Array { paramName, value }; + }) + .ToList>() + .Select(kvp => new FilterRule { RuleType = FilterRuleType.BEGINSWITH, + ParameterName = kvp.Value[0], + Value = kvp.Value[1] }) + . + + //TODO: here goes the convertion method //Set identifiers, parameters & custom data diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index f763ce32b..35b8e78f7 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -27,6 +27,7 @@ using BH.oM.Base.Attributes; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; namespace BH.Revit.Engine.Core { @@ -36,11 +37,11 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] - //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] + [Description("Converts a Revit ParameterFilterElement to BH.oM.Adapters.Revit.Elements.ViewFilter.")] + [Input("revitViewFilter", "Revit ParameterFilterElement to be converted.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("viewFilter", "BH.oM.Adapters.Revit.Elements.ViewFilter resulting from converting the input Revit ParameterFilterElement.")] public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this ParameterFilterElement revitViewFilter, RevitSettings settings = null, Dictionary> refObjects = null) { settings = settings.DefaultIfNull(); @@ -49,11 +50,20 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par if (viewFilter != null) return viewFilter; + /* 1. Transfer Filter NAME */ viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; - //TODO: here goes the convertion method + /* 2. Transfer List of CATEGORY NAMES */ + viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); + /* 3. Transfer List of FILTER RULES */ + ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => { string parameterName = revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString(); + ) + .ToList(); + - //Set identifiers, parameters & custom data - viewFilter.SetIdentifiers(revitViewFilter); + + //Set identifiers, parameters & custom data + viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); viewFilter.SetProperties(revitViewFilter, settings.MappingSettings); diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index dc5d78549..17405656c 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -94,7 +94,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - private static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { + public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { Autodesk.Revit.DB.FilterRule revitFilterRule = null; diff --git a/Revit_oM/Elements/View.cs b/Revit_oM/Elements/View.cs index ae7d48c58..a251c1811 100644 --- a/Revit_oM/Elements/View.cs +++ b/Revit_oM/Elements/View.cs @@ -4,8 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using BH.oM.Revit.Views; -namespace BH.oM.Adapters.Revit.Views +namespace BH.oM.Adapters.Revit.Elements { public class View : BHoMObject { diff --git a/Revit_oM/Views/FilterRule.cs b/Revit_oM/Views/FilterRule.cs index a6a1fc79b..a1b6b9c19 100644 --- a/Revit_oM/Views/FilterRule.cs +++ b/Revit_oM/Views/FilterRule.cs @@ -7,7 +7,7 @@ namespace BH.oM.Revit.Views { - public abstract class FilterRule : BHoMObject + public class FilterRule : BHoMObject { public virtual FilterRuleType RuleType { get; set; } public virtual string ParameterName { get; set; } From 4620c1bbf38607ed201152038e96037b3c8e53ce Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sat, 20 Apr 2024 16:01:42 +0100 Subject: [PATCH 014/131] Add FilterRuleEvaluatorType Enumeration --- .../Convert/Revit/FromRevit/ViewFilter.cs | 17 ++++++++++------- Revit_oM/Views/FilterRuleEvaluatorType.cs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 Revit_oM/Views/FilterRuleEvaluatorType.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 35b8e78f7..352e6e211 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -25,6 +25,7 @@ using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.Revit.Views; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -55,18 +56,20 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 2. Transfer List of CATEGORY NAMES */ viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); /* 3. Transfer List of FILTER RULES */ - ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => { string parameterName = revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString(); - ) + //viewFilter.Rules + List parameterNames= ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); - + List ruleTypeNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => rule.GetType().ToString()) + .ToList(); + - //Set identifiers, parameters & custom data - viewFilter.SetIdentifiers(revitViewFilter); + //Set identifiers, parameters & custom data + viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); viewFilter.SetProperties(revitViewFilter, settings.MappingSettings); - refObjects.AddOrReplace(revitViewFilter.Id, viewFilter); return viewFilter; } diff --git a/Revit_oM/Views/FilterRuleEvaluatorType.cs b/Revit_oM/Views/FilterRuleEvaluatorType.cs new file mode 100644 index 000000000..68469da7d --- /dev/null +++ b/Revit_oM/Views/FilterRuleEvaluatorType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + internal class RuleEvaluatorType + { + } +} From 3f2a258bab270ebc047e00ea6c5cd7981b82d386 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sat, 20 Apr 2024 16:27:50 +0100 Subject: [PATCH 015/131] Add FilterValueRule and modify FilterRuleType To simplify the mirroring representation of the Revit API classes within the BHoM, it's necessary to add a concrete classe, subclass of FilterRule, that corresponds to the FilterValueRule from Revit API. Whatever sub-class type as well as Evaluator class type will be represented in BHoM via enumeration classes assigned to the RevitFilterRule and RevitFilterValueRule as attributes. --- Revit_oM/Views/FilterRuleType.cs | 21 ++++++++++----------- Revit_oM/Views/FilterValueRule.cs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 Revit_oM/Views/FilterValueRule.cs diff --git a/Revit_oM/Views/FilterRuleType.cs b/Revit_oM/Views/FilterRuleType.cs index 01119a1a0..565731a07 100644 --- a/Revit_oM/Views/FilterRuleType.cs +++ b/Revit_oM/Views/FilterRuleType.cs @@ -8,16 +8,15 @@ namespace BH.oM.Revit.Views { public enum FilterRuleType { - EQUALS, - GREATER, - GREATER_OR_EQUAL, - LESS, - LESS_OR_EQUAL, - CONTAINS, - NOT_CONTAINS, - BEGINSWITH, - NOT_BEGINSWITH, - ENDSWITH, - NOT_ENDSWITH + VALUE_STRINGRULE, + VALUE_NUMERICRULE_DOUBLE, + VALUE_NUMERICRULE_ELEMENTID, + VALUE_NUMERICRULE_INTEGER, + VALUE_GLOBALPARAMASSOCIATION, + INVERSE, + CATEGORY, + PARAMVALUEPRESENCE_NOVALUE, + PARAMVALUEPRESENCE_VALUE, + SHAREDPARAM_APPLICABLE } } diff --git a/Revit_oM/Views/FilterValueRule.cs b/Revit_oM/Views/FilterValueRule.cs new file mode 100644 index 000000000..f3005b663 --- /dev/null +++ b/Revit_oM/Views/FilterValueRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + internal class FilterValueRule + { + } +} From 93b92c9e6d7042ca50547b617389383ea27b4d4d Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Thu, 25 Apr 2024 16:52:10 +0100 Subject: [PATCH 016/131] Delete FilterRuleType Enum Instead of using a single class FilterRule with an Enumeration encapsulated to represent all the different Revit API Filter Rules, we go for creating multiple classes and sub-classes in BHoM as well, thus trying to match as much as possible the classes structure that is present in the API. --- Revit_oM/Views/FilterRuleType.cs | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 Revit_oM/Views/FilterRuleType.cs diff --git a/Revit_oM/Views/FilterRuleType.cs b/Revit_oM/Views/FilterRuleType.cs deleted file mode 100644 index 565731a07..000000000 --- a/Revit_oM/Views/FilterRuleType.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.oM.Revit.Views -{ - public enum FilterRuleType - { - VALUE_STRINGRULE, - VALUE_NUMERICRULE_DOUBLE, - VALUE_NUMERICRULE_ELEMENTID, - VALUE_NUMERICRULE_INTEGER, - VALUE_GLOBALPARAMASSOCIATION, - INVERSE, - CATEGORY, - PARAMVALUEPRESENCE_NOVALUE, - PARAMVALUEPRESENCE_VALUE, - SHAREDPARAM_APPLICABLE - } -} From 17763421dc2f13c214b38fa0d59b22b9b664c0f3 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:27:43 +0100 Subject: [PATCH 017/131] Create FilterRule classes mirroring Revit API classes --- .../Revit/ToRevit/ParameterFilterElement.cs | 133 +++++++++++------- Revit_oM/Elements/FilterCategoryRule.cs | 13 ++ .../FilterDoubleRule.cs} | 5 +- Revit_oM/Elements/FilterIntegerRule.cs | 13 ++ Revit_oM/Elements/FilterLevelRule.cs | 16 +++ Revit_oM/Elements/FilterMaterialRule.cs | 13 ++ Revit_oM/Elements/FilterNumericValueRule.cs | 16 +++ .../FilterRule.cs} | 7 +- Revit_oM/Elements/FilterStringRule.cs | 14 ++ Revit_oM/Elements/FilterValueRule.cs | 15 ++ Revit_oM/Views/FilterRule.cs | 18 --- 11 files changed, 189 insertions(+), 74 deletions(-) create mode 100644 Revit_oM/Elements/FilterCategoryRule.cs rename Revit_oM/{Views/FilterValueRule.cs => Elements/FilterDoubleRule.cs} (59%) create mode 100644 Revit_oM/Elements/FilterIntegerRule.cs create mode 100644 Revit_oM/Elements/FilterLevelRule.cs create mode 100644 Revit_oM/Elements/FilterMaterialRule.cs create mode 100644 Revit_oM/Elements/FilterNumericValueRule.cs rename Revit_oM/{Views/FilterRuleEvaluatorType.cs => Elements/FilterRule.cs} (62%) create mode 100644 Revit_oM/Elements/FilterStringRule.cs create mode 100644 Revit_oM/Elements/FilterValueRule.cs delete mode 100644 Revit_oM/Views/FilterRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 17405656c..d2b0f5cac 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -22,19 +22,21 @@ using Autodesk.Revit.Creation; using Autodesk.Revit.DB; +using BH.oM.Adapters.Revit.Enums; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; -using BH.oM.Revit.Views; +using BH.oM.Revit.Elements; +using BH.oM.Revit.Enums; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; -using FilterRule = BH.oM.Revit.Views.FilterRule; +using FilterRule = BH.oM.Revit.Elements.FilterRule; namespace BH.Revit.Engine.Core { @@ -82,7 +84,9 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /* Via use of Streams*/ revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules - .Select(filterRule => filterRuleToRevit(document, filterRule)) + .Where(filterRule=> filterRule.GetType().IsSubclassOf(typeof(FilterValueRule))) + .Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) .Cast() .ToList())); @@ -94,7 +98,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { + public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -105,57 +109,82 @@ public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,F ElementId parameterId = new FilteredElementCollector(document) .WherePasses(logicalOrFilter) - .Where(par => par.Name.Equals(filterRule.ParameterName)) + .Where(par => par.Name.Equals(filterValueRule.ParameterName)) .First() .Id; + + + try + { + BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Revit.Elements.FilterStringRule)filterValueRule; + + switch (filterStringValueRule.Evaluator) + { + case TextComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + + case TextComparisonType.Contains: + revitFilterRule = ParameterFilterRuleFactory + .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.ContainsNot: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.StartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.EndsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case FilterRuleType.GREATER: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.GREATER_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.LESS: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.LESS_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.NOT_BEGINSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string)filterRule.Value, false); + break; + case FilterRuleType.NOT_CONTAINS: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string)filterRule.Value, false); + break; + case FilterRuleType.NOT_ENDSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEndsWithRule(parameterId, (string)filterRule.Value, false); + break; + default: + break; + } + + } catch (Exception ex) + { + + } + + + - switch (filterRule.RuleType) { - case FilterRuleType.BEGINSWITH: - revitFilterRule=ParameterFilterRuleFactory - .CreateBeginsWithRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.CONTAINS: - revitFilterRule = ParameterFilterRuleFactory - .CreateContainsRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.ENDSWITH: - revitFilterRule = ParameterFilterRuleFactory - .CreateEndsWithRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.EQUALS: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, (int) filterRule.Value); - break; - case FilterRuleType.GREATER: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.GREATER_OR_EQUAL: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.LESS: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.LESS_OR_EQUAL: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.NOT_BEGINSWITH: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotBeginsWithRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.NOT_CONTAINS: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotContainsRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.NOT_ENDSWITH: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEndsWithRule(parameterId, (string) filterRule.Value, false); - break; - default: - break;} return revitFilterRule; } diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/Elements/FilterCategoryRule.cs new file mode 100644 index 000000000..d5628fd5c --- /dev/null +++ b/Revit_oM/Elements/FilterCategoryRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public class FilterCategoryRule : FilterRule + { + public virtual List categoryNames { get; set; } + } +} diff --git a/Revit_oM/Views/FilterValueRule.cs b/Revit_oM/Elements/FilterDoubleRule.cs similarity index 59% rename from Revit_oM/Views/FilterValueRule.cs rename to Revit_oM/Elements/FilterDoubleRule.cs index f3005b663..3fcf2c561 100644 --- a/Revit_oM/Views/FilterValueRule.cs +++ b/Revit_oM/Elements/FilterDoubleRule.cs @@ -4,9 +4,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { - internal class FilterValueRule + public class FilterDoubleRule : FilterNumericValueRule { + } } diff --git a/Revit_oM/Elements/FilterIntegerRule.cs b/Revit_oM/Elements/FilterIntegerRule.cs new file mode 100644 index 000000000..a2c8bcb76 --- /dev/null +++ b/Revit_oM/Elements/FilterIntegerRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public class FilterIntegerRule : FilterNumericValueRule + { + + } +} diff --git a/Revit_oM/Elements/FilterLevelRule.cs b/Revit_oM/Elements/FilterLevelRule.cs new file mode 100644 index 000000000..4ef03af4e --- /dev/null +++ b/Revit_oM/Elements/FilterLevelRule.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BH.oM.Revit.Enums; + +namespace BH.oM.Revit.Elements +{ + public class FilterLevelRule : FilterRule + { + public virtual string LevelName { get; set; } + public virtual LevelComparisonType Evaluator { get; set; } + + } +} diff --git a/Revit_oM/Elements/FilterMaterialRule.cs b/Revit_oM/Elements/FilterMaterialRule.cs new file mode 100644 index 000000000..b6313e469 --- /dev/null +++ b/Revit_oM/Elements/FilterMaterialRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public class FilterMaterialRule : FilterRule + { + public virtual string MaterialName { get; set; } + } +} diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/Elements/FilterNumericValueRule.cs new file mode 100644 index 000000000..6615732bb --- /dev/null +++ b/Revit_oM/Elements/FilterNumericValueRule.cs @@ -0,0 +1,16 @@ +using BH.oM.Adapters.Revit.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public class FilterNumericValueRule: FilterValueRule + { + public virtual NumberComparisonType evaluator { get; set; } + + + } +} diff --git a/Revit_oM/Views/FilterRuleEvaluatorType.cs b/Revit_oM/Elements/FilterRule.cs similarity index 62% rename from Revit_oM/Views/FilterRuleEvaluatorType.cs rename to Revit_oM/Elements/FilterRule.cs index 68469da7d..b2f4ffd9d 100644 --- a/Revit_oM/Views/FilterRuleEvaluatorType.cs +++ b/Revit_oM/Elements/FilterRule.cs @@ -1,4 +1,5 @@ -using System; +using BH.oM.Base; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,9 @@ namespace BH.oM.Revit.Views { - internal class RuleEvaluatorType + public abstract class FilterRule : BHoMObject { + } + } diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/Elements/FilterStringRule.cs new file mode 100644 index 000000000..5950dd5ff --- /dev/null +++ b/Revit_oM/Elements/FilterStringRule.cs @@ -0,0 +1,14 @@ +using BH.oM.Adapters.Revit.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public class FilterStringRule :FilterValueRule + { + public virtual TextComparisonType evaluator { get; set; } + } +} diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/Elements/FilterValueRule.cs new file mode 100644 index 000000000..17e53a916 --- /dev/null +++ b/Revit_oM/Elements/FilterValueRule.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public abstract class FilterValueRule : FilterRule + { + public virtual String parameterName { get; set; } + public virtual String value { get; set; } + + } +} diff --git a/Revit_oM/Views/FilterRule.cs b/Revit_oM/Views/FilterRule.cs deleted file mode 100644 index a1b6b9c19..000000000 --- a/Revit_oM/Views/FilterRule.cs +++ /dev/null @@ -1,18 +0,0 @@ -using BH.oM.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.oM.Revit.Views -{ - public class FilterRule : BHoMObject - { - public virtual FilterRuleType RuleType { get; set; } - public virtual string ParameterName { get; set; } - public virtual object Value { get; set; } - - } - -} From 54d1526c6f0fc51126a1c3e42c68395657beba35 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:29:25 +0100 Subject: [PATCH 018/131] Move FillPattern and LinePattern to the Enums Namespace --- Revit_oM/{Views => Enums}/FillPattern.cs | 0 Revit_oM/{Views => Enums}/LinePattern.cs | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Revit_oM/{Views => Enums}/FillPattern.cs (100%) rename Revit_oM/{Views => Enums}/LinePattern.cs (100%) diff --git a/Revit_oM/Views/FillPattern.cs b/Revit_oM/Enums/FillPattern.cs similarity index 100% rename from Revit_oM/Views/FillPattern.cs rename to Revit_oM/Enums/FillPattern.cs diff --git a/Revit_oM/Views/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs similarity index 100% rename from Revit_oM/Views/LinePattern.cs rename to Revit_oM/Enums/LinePattern.cs From fa497119cecca301e0f6ccfe61efe7f5287bd324 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:31:26 +0100 Subject: [PATCH 019/131] Modify BHoM Enum TextComparisonType Add NOT_START_WITH and NOT_ENDS_WITH enum values to the enumeration. These are required to implement the View Filtering in BHoM. --- Revit_oM/Enums/TextComparisonType.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Revit_oM/Enums/TextComparisonType.cs b/Revit_oM/Enums/TextComparisonType.cs index d0623cea4..c11575ca0 100644 --- a/Revit_oM/Enums/TextComparisonType.cs +++ b/Revit_oM/Enums/TextComparisonType.cs @@ -33,14 +33,18 @@ public enum TextComparisonType Equal, [Description("Check if input string and reference string are different.")] NotEqual, - [Description("Check if the input input string contains reference string.")] + [Description("Check if the input string contains the reference string.")] Contains, - [Description("Check if the input input string does not contain reference string.")] + [Description("Check if the input string does not contain the reference string.")] ContainsNot, - [Description("Check if the input input string starts with reference string.")] + [Description("Check if the input string starts with the reference string.")] StartsWith, - [Description("Check if the input input string ends with reference string.")] + [Description("Check if the input string does not start with the reference string ")] + NotStartsWith, + [Description("Check if the input string ends with the reference string.")] EndsWith, + [Description("Check if the input string does not end with the reference string")] + NotEndsWith } /***************************************************/ From 87e275c4faddf85c942d0935c53b4d5c299725ab Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:36:38 +0100 Subject: [PATCH 020/131] Add LevelComparisonType Enumeration Useful to create LevelFilterRule objects --- Revit_oM/Enums/LevelComparisonType.cs | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Revit_oM/Enums/LevelComparisonType.cs diff --git a/Revit_oM/Enums/LevelComparisonType.cs b/Revit_oM/Enums/LevelComparisonType.cs new file mode 100644 index 000000000..48c61c8ae --- /dev/null +++ b/Revit_oM/Enums/LevelComparisonType.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Enums +{ + /***************************************************/ + + [Description("Enumerator defining the way in which two levels are compared.")] + public enum LevelComparisonType + { + [Description("Check if input and reference level are at the same elevation.")] + Equal, + [Description("Check if input and reference level are at different elevations.")] + NotEqual, + [Description("Check if the input level is above the reference level.")] + Above, + [Description("Check if the input level is above or at the same elevation of the reference level.")] + AtOrAbove, + [Description("Check if the input level is below the reference level.")] + Below, + [Description("Check if the input level is below or at the same elevation of the reference level.")] + AtOrBelow, + } + + /***************************************************/ +} From 4b1fa4f4ce7344aa78388ca149a4708868f86444 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 17:29:09 +0100 Subject: [PATCH 021/131] Add conversion methods for FilterMaterialRule and FilterLevelRule in Convert.ToRevit Namespace --- .../Convert/Revit/FromRevit/View.cs | 2 +- .../Revit/ToRevit/ParameterFilterElement.cs | 132 ++++++++++++++---- Revit_oM/Elements/FilterCategoryRule.cs | 4 +- Revit_oM/Elements/FilterNumericValueRule.cs | 6 +- Revit_oM/Elements/FilterRule.cs | 2 +- Revit_oM/Elements/FilterStringRule.cs | 6 +- Revit_oM/Elements/FilterValueRule.cs | 6 +- Revit_oM/Elements/OverrideGraphicSettings.cs | 2 +- Revit_oM/Elements/ViewFilter.cs | 2 +- Revit_oM/Enums/FillPattern.cs | 2 +- Revit_oM/Enums/LinePattern.cs | 2 +- 11 files changed, 123 insertions(+), 43 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 84254b325..a34dae5eb 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -32,7 +32,7 @@ using System.ComponentModel; using System.Linq; using System.Xml.Linq; -using FilterRule = BH.oM.Revit.Views.FilterRule; +using FilterRule = BH.oM.Revit.Elements.FilterRule; using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; using View = Autodesk.Revit.DB.View; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index d2b0f5cac..b9f0c79e3 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -37,6 +37,7 @@ using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; using FilterRule = BH.oM.Revit.Elements.FilterRule; +using FilterStringRule = BH.oM.Revit.Elements.FilterStringRule; namespace BH.Revit.Engine.Core { @@ -98,23 +99,94 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + BuiltInParameter parameter = BuiltInParameter.MATERIAL_NAME; + + + //ParameterValueProvider provider = new ParameterValueProvider(new ElementId(parameter)); + revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); + + return revitFilterRule; + } + + + public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Revit.Elements.FilterLevelRule filterLevelRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; + BuiltInParameter elevationParam = BuiltInParameter.LEVEL_ELEV; + ElementId elevParamId=new ElementId(elevationParam); + Double levelElevation; + + try { + levelElevation=new FilteredElementCollector(document) + .OfCategory(BuiltInCategory.OST_Levels) + .Where(level => level.Name.ToUpper() == filterLevelRule.LevelName.ToUpper()) + .Cast() + .Select(level => level.Elevation) + .First(); + } catch (Exception ex){ + return null;} + + switch (filterLevelRule.Evaluator) + { + case LevelComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(elevParamId,(double)levelElevation, 0.001); + break; + case LevelComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.Above: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.AtOrAbove: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.Below: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.AtOrBelow: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(elevParamId, (double)levelElevation, 0.001); + break; + default: + break; + } + + return revitFilterRule; + + + } + + public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { + + /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; ElementClassFilter paramFilter = new ElementClassFilter(typeof(Parameter)); ElementClassFilter builtInParamFilter = new ElementClassFilter(typeof(BuiltInParameter)); LogicalOrFilter logicalOrFilter = new LogicalOrFilter(paramFilter, builtInParamFilter); - + /* 2. GET THE ELEMENT ID OF THE PARAMETER OBJECT */ ElementId parameterId = new FilteredElementCollector(document) .WherePasses(logicalOrFilter) .Where(par => par.Name.Equals(filterValueRule.ParameterName)) .First() .Id; - - try + /* 3. CREATE FILTER-RULES */ + + // Based on FilterStringRule... + if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Revit.Elements.FilterStringRule)filterValueRule; @@ -128,7 +200,6 @@ public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document revitFilterRule = ParameterFilterRuleFactory .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); break; - case TextComparisonType.Contains: revitFilterRule = ParameterFilterRuleFactory .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); @@ -141,49 +212,58 @@ public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document revitFilterRule = ParameterFilterRuleFactory .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); break; + case TextComparisonType.NotStartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; case TextComparisonType.EndsWith: revitFilterRule = ParameterFilterRuleFactory .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); break; - case FilterRuleType.GREATER: + case TextComparisonType.NotEndsWith: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (ElementId)filterRule.Value); + .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + default: break; - case FilterRuleType.GREATER_OR_EQUAL: + } + + // Based on FilterNumericValueRule... + } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.Elements.FilterNumericValueRule))) + { + BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Revit.Elements.FilterNumericValueRule)filterValueRule; + + switch (filterNumericValueRule.Evaluator) + { + case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (ElementId)filterRule.Value); + .CreateEqualsRule(parameterId,(string)filterNumericValueRule.Value, false); break; - case FilterRuleType.LESS: + case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, (ElementId)filterRule.Value); + .CreateNotEqualsRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.LESS_OR_EQUAL: + case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (ElementId)filterRule.Value); + .CreateGreaterRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.NOT_BEGINSWITH: + case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotBeginsWithRule(parameterId, (string)filterRule.Value, false); + .CreateGreaterOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.NOT_CONTAINS: + case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateNotContainsRule(parameterId, (string)filterRule.Value, false); + .CreateLessRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.NOT_ENDSWITH: + case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEndsWithRule(parameterId, (string)filterRule.Value, false); + .CreateLessOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); break; default: break; } - } catch (Exception ex) - { - - } - - - + } else { return null; } return revitFilterRule; diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/Elements/FilterCategoryRule.cs index d5628fd5c..6839e5326 100644 --- a/Revit_oM/Elements/FilterCategoryRule.cs +++ b/Revit_oM/Elements/FilterCategoryRule.cs @@ -4,10 +4,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { public class FilterCategoryRule : FilterRule { - public virtual List categoryNames { get; set; } + public virtual List CategoryNames { get; set; } } } diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/Elements/FilterNumericValueRule.cs index 6615732bb..14aa34daf 100644 --- a/Revit_oM/Elements/FilterNumericValueRule.cs +++ b/Revit_oM/Elements/FilterNumericValueRule.cs @@ -5,11 +5,11 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { - public class FilterNumericValueRule: FilterValueRule + public class FilterNumericValueRule : FilterValueRule { - public virtual NumberComparisonType evaluator { get; set; } + public virtual NumberComparisonType Evaluator { get; set; } } diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Elements/FilterRule.cs index b2f4ffd9d..567d22e54 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/Elements/FilterRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { public abstract class FilterRule : BHoMObject { diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/Elements/FilterStringRule.cs index 5950dd5ff..5ffb5c8ee 100644 --- a/Revit_oM/Elements/FilterStringRule.cs +++ b/Revit_oM/Elements/FilterStringRule.cs @@ -5,10 +5,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { - public class FilterStringRule :FilterValueRule + public class FilterStringRule : FilterValueRule { - public virtual TextComparisonType evaluator { get; set; } + public virtual TextComparisonType Evaluator { get; set; } } } diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/Elements/FilterValueRule.cs index 17e53a916..e47c16ad3 100644 --- a/Revit_oM/Elements/FilterValueRule.cs +++ b/Revit_oM/Elements/FilterValueRule.cs @@ -4,12 +4,12 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { public abstract class FilterValueRule : FilterRule { - public virtual String parameterName { get; set; } - public virtual String value { get; set; } + public virtual string ParameterName { get; set; } + public virtual string Value { get; set; } } } diff --git a/Revit_oM/Elements/OverrideGraphicSettings.cs b/Revit_oM/Elements/OverrideGraphicSettings.cs index b2e205d57..99085dc18 100644 --- a/Revit_oM/Elements/OverrideGraphicSettings.cs +++ b/Revit_oM/Elements/OverrideGraphicSettings.cs @@ -1,5 +1,5 @@ using BH.oM.Base; -using BH.oM.Revit.Views; +using BH.oM.Revit.Enums; using System; using System.Collections.Generic; using System.Drawing; diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 943746066..9eb89989a 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,5 +1,5 @@ using BH.oM.Base; -using BH.oM.Revit.Views; +using BH.oM.Revit.Elements; using System; using System.Collections.Generic; using System.Linq; diff --git a/Revit_oM/Enums/FillPattern.cs b/Revit_oM/Enums/FillPattern.cs index 1e9451739..17efeff82 100644 --- a/Revit_oM/Enums/FillPattern.cs +++ b/Revit_oM/Enums/FillPattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Enums { public enum FillPattern { diff --git a/Revit_oM/Enums/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs index 6e1292999..1da829a39 100644 --- a/Revit_oM/Enums/LinePattern.cs +++ b/Revit_oM/Enums/LinePattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Enums { public enum LinePattern { From afd0b491d1536a9fa119aad7b940d6625820d41d Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 18:54:27 +0100 Subject: [PATCH 022/131] Update conversion of BHoM ViewFilters to Revit Parameter Filter Elements --- .../Revit/ToRevit/ParameterFilterElement.cs | 70 ++++++++++++++++--- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index b9f0c79e3..9fc43cdf5 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -22,6 +22,8 @@ using Autodesk.Revit.Creation; using Autodesk.Revit.DB; +using BH.Engine.Base; +using BH.Engine.Data; using BH.oM.Adapters.Revit.Enums; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; @@ -80,26 +82,70 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /* 1.2 Create the ParameterFilterElement in the current Revit Document */ revitFilter = ParameterFilterElement.Create(document, filter.Name, categoryIdsList); - // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules - .Where(filterRule=> filterRule.GetType().IsSubclassOf(typeof(FilterValueRule))) - .Cast() - .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) - .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) + .GroupBy(rule => rule.GetType()) + .ToDictionary(grp => grp.Key, grp => grp.ToList()) + .ToList() + .Select(kvp =>{ + + List filterRules = new List(); + + if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterCategoryRule))){ + filterRules = kvp.Value.Cast() + .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) + .ToList();} + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterValueRule))){ + filterRules = kvp.Value.Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) + .ToList();} + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterMaterialRule))){ + filterRules = kvp.Value.Cast() + .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) + .ToList();} + return filterRules; }) + .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) .Cast() .ToList())); + revitFilter.CopyParameters(filter, settings); refObjects.AddOrReplace(filter, revitFilter); return revitFilter; } + /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) + public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Revit.Elements.FilterCategoryRule filterCategoryRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ + List categoryIds = new FilteredElementCollector(document) + // Get all the Categories (INTERMEDIATE OPERATION) + .OfClass(typeof(Autodesk.Revit.DB.Category)) + // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) + .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) + // Cast down to Category Class Instances (INTERMEDIATE OPERATION) + .Cast() + // Get the ids of the retain categories (INTERMEDIATE OPERATION) + .Select(cat => cat.Id) + // Turn the Stream into a List (TERMINAL OPERATION) + .ToList(); + + /* 3. CREATE THE FILTER RULE */ + revitFilterRule = new Autodesk.Revit.DB.FilterCategoryRule(categoryIds); + + return revitFilterRule; + } + + /***************************************************/ + + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -113,6 +159,7 @@ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document do return revitFilterRule; } + /***************************************************/ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Revit.Elements.FilterLevelRule filterLevelRule) { @@ -122,6 +169,9 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum ElementId elevParamId=new ElementId(elevationParam); Double levelElevation; + /* 2. GET ELEVATION OF LEVEL CORRESPONDING TO INPUT LEVEL NAME */ + // Via Streams and withing a Try-Catch statement to make sure the code is compact and if the level is not found, we prevent any error + // being thrown when executing .First() while returning null instead. try { levelElevation=new FilteredElementCollector(document) .OfCategory(BuiltInCategory.OST_Levels) @@ -132,6 +182,9 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum } catch (Exception ex){ return null;} + /* 3. CREATE FILTERS RULE */ + + // Based on level's elevation and LevelComparisonType... switch (filterLevelRule.Evaluator) { case LevelComparisonType.Equal: @@ -163,9 +216,10 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum } return revitFilterRule; + } - } + /***************************************************/ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { @@ -183,7 +237,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum .First() .Id; - /* 3. CREATE FILTER-RULES */ + /* 3. CREATE FILTER-RULE */ // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) From 4bbea090f4ce0545aa291c92bc75e06405b43886 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 21:36:09 +0100 Subject: [PATCH 023/131] Add enum values to TextComparisonType Enumeration Greater, GreaterOrEqual, Less, LessOrEqual are added to reflect the types and names of the subclasses of the Revit API class FilterStringRuleEvaluator --- Revit_oM/Enums/TextComparisonType.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Revit_oM/Enums/TextComparisonType.cs b/Revit_oM/Enums/TextComparisonType.cs index c11575ca0..90ba8da6c 100644 --- a/Revit_oM/Enums/TextComparisonType.cs +++ b/Revit_oM/Enums/TextComparisonType.cs @@ -44,7 +44,15 @@ public enum TextComparisonType [Description("Check if the input string ends with the reference string.")] EndsWith, [Description("Check if the input string does not end with the reference string")] - NotEndsWith + NotEndsWith, + [Description("Check if the input string is greater than the reference string.")] + Greater, + [Description("Check if the input string is greater or equal to the reference string")] + GreaterOrEqual, + [Description("Check if the input string is smaller to the reference string")] + Less, + [Description("Check if the input string is smaller or equal to the reference string")] + LessOrEqual } /***************************************************/ From 5cbef88cd7d30a070d48ee89fd1a92983ead9ed0 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 21:49:58 +0100 Subject: [PATCH 024/131] Update ToRevit ParameterFilterElement with additional TextComparisonType Enum Values Greater, GreaterOrEqual, Less, LessOrEqual --- .../Revit/ToRevit/ParameterFilterElement.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 9fc43cdf5..e03e9003c 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -278,6 +278,22 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum revitFilterRule = ParameterFilterRuleFactory .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); break; + case TextComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Less: + revitFilterRule=ParameterFilterRuleFactory + .CreateLessRule(parameterId,(string)filterStringValueRule.Value, false); + break; + case TextComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; default: break; } From 5c832b179c715626992d0bf214bbf942b6ed8b0d Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sat, 27 Apr 2024 19:17:50 +0100 Subject: [PATCH 025/131] Add adapter code for FilterRules in ViewFilterFromRevit Method in FromRevit Namespace --- .../Convert/Revit/FromRevit/View.cs | 10 +- .../Convert/Revit/FromRevit/ViewFilter.cs | 184 +++++++++++++++++- 2 files changed, 187 insertions(+), 7 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index a34dae5eb..0f14b9dfd 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -60,10 +60,7 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, /* 1. Transfer NAME */ view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name }; - List filtersWithOverrides; - List viewFilters; - List overrides; - + /* 2. Collect FILTER CATEGORY NAMES */ List> categoriesNames=revitView.GetFilters() .Select(elId => revitView.Document.GetElement(elId)) .Cast() @@ -71,6 +68,11 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, .Select(catIdsList => catIdsList.Select(catId => revitView.Document.GetElement(catId).Name).ToList()) .ToList>(); + + List filtersWithOverrides; + List viewFilters; + List overrides; + List filterRules = revitView.GetFilters() .Select(elId => revitView.Document.GetElement(elId)) .Cast() diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 352e6e211..03091f40c 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,9 +26,14 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; +using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using FilterRule = Autodesk.Revit.DB.FilterRule; +using System.CodeDom; +using System; +using Autodesk.Revit.DB.Architecture; namespace BH.Revit.Engine.Core { @@ -60,12 +65,185 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par List parameterNames= ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); - List ruleTypeNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => rule.GetType().ToString()) - .ToList(); + List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); + List bhomFilterRules = revitFilterRules.Select(revitRule => + { + // FILTER STRING RULE + if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + { + Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramValue = revitFilterStringRule.RuleString; + FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); + + TextComparisonType bhomEvaluator; + + switch (stringEvaluator.GetType()) + { + case typeof(Autodesk.Revit.DB.FilterStringBeginsWith): + bhomEvaluator = TextComparisonType.StartsWith; + break; + case typeof(Autodesk.Revit.DB.FilterStringEndsWith): + bhomEvaluator = TextComparisonType.EndsWith; + break; + case typeof(Autodesk.Revit.DB.FilterStringEquals): + bhomEvaluator = TextComparisonType.Equal; + break; + case typeof(Autodesk.Revit.DB.FilterStringContains): + bhomEvaluator = TextComparisonType.Contains; + break; + case typeof(Autodesk.Revit.DB.FilterStringGreater): + bhomEvaluator = TextComparisonType.Greater; + break; + case typeof(Autodesk.Revit.DB.FilterStringGreaterOrEqual): + bhomEvaluator = TextComparisonType.GreaterOrEqual; + break; + case typeof(Autodesk.Revit.DB.FilterStringLess): + bhomEvaluator = TextComparisonType.Less; + break; + case typeof(Autodesk.Revit.DB.FilterStringLessOrEqual): + bhomEvaluator = TextComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = paramName; + bhomFilterStringRule.Value = paramValue; + bhomFilterStringRule.Evaluator = bhomEvaluator; + + return bhomFilterStringRule; + } + + // FILTER DOUBLE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + { + Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); + + NumberComparisonType bhomEvaluator; + + switch (numericEvaluator.GetType()) + { + case typeof(Autodesk.Revit.DB.FilterNumericEquals): + bhomEvaluator = NumberComparisonType.Equal; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreater): + bhomEvaluator = NumberComparisonType.Greater; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): + bhomEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLess): + bhomEvaluator = NumberComparisonType.Less; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): + bhomEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = paramName; + bhomFilterDoubleRule.Value = paramValue; + bhomFilterDoubleRule.Evaluator = bhomEvaluator; + + return bhomFilterDoubleRule; + } + + // FILTER INTEGER RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + { + Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); + + NumberComparisonType bhomEvaluator; + + switch (numericEvaluator.GetType()) + { + case typeof(Autodesk.Revit.DB.FilterNumericEquals): + bhomEvaluator = NumberComparisonType.Equal; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreater): + bhomEvaluator = NumberComparisonType.Greater; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): + bhomEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLess): + bhomEvaluator = NumberComparisonType.Less; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): + bhomEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = paramName; + bhomFilterIntegerRule.Value = paramValue; + bhomFilterIntegerRule.Evaluator = bhomEvaluator; + + return bhomFilterIntegerRule; + } + + // FILTER CATEGORY RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + { + Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; + List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); + + BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); + bhomFilterCategoryRule.CategoryNames = categoryNames; + + return bhomFilterCategoryRule; + } + + // FILTER INVERSE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + { + Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; + Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); + TextComparisonType bhomTextEvaluator; + NumberComparisonType bhomNumberEvaluator; + + switch (innerRule.GetType()) + { + case (typeof(Autodesk.Revit.DB.FilterStringRule)): + switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType()) { + case (typeof(FilterStringEquals)): + bhomTextEvaluator = TextComparisonType.NotEqual; + break; + case (typeof(FilterStringBeginsWith)): + bhomTextEvaluator = TextComparisonType.NotStartsWith; + break; + case (typeof(FilterStringEndsWith)): + bhomTextEvaluator = TextComparisonType.NotEndsWith; + break; + case (typeof(FilterStringContains)): + bhomTextEvaluator = TextComparisonType.ContainsNot; + break; + default: + break;} + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule; + } + return ; + } + }); //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); From c329c72b7f85f42e4d5c8166bb41fbd10680130e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 17:06:12 +0100 Subject: [PATCH 026/131] Add FilterElementIdRule to the Revit BHoM Objects --- Revit_oM/Elements/FilterElementIdRule.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Revit_oM/Elements/FilterElementIdRule.cs diff --git a/Revit_oM/Elements/FilterElementIdRule.cs b/Revit_oM/Elements/FilterElementIdRule.cs new file mode 100644 index 000000000..6012f2b70 --- /dev/null +++ b/Revit_oM/Elements/FilterElementIdRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + internal class FilterElementIdRule + { + } +} From 6685f06847bdb09fa776bce6866761104e554b7e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 17:15:17 +0100 Subject: [PATCH 027/131] Add handling of FilterElementIdRule in conversion of ViewFilter From Revit --- .../Convert/Revit/FromRevit/ViewFilter.cs | 352 ++++++++++-------- 1 file changed, 195 insertions(+), 157 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 03091f40c..446b45d2c 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,11 +26,11 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; +using BH.oM.Revit.Elements; using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using FilterRule = Autodesk.Revit.DB.FilterRule; using System.CodeDom; using System; using Autodesk.Revit.DB.Architecture; @@ -62,186 +62,224 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); /* 3. Transfer List of FILTER RULES */ //viewFilter.Rules - List parameterNames= ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); List bhomFilterRules = revitFilterRules.Select(revitRule => { - // FILTER STRING RULE - if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) - { - Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; - string paramValue = revitFilterStringRule.RuleString; - FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); - - TextComparisonType bhomEvaluator; - - switch (stringEvaluator.GetType()) - { - case typeof(Autodesk.Revit.DB.FilterStringBeginsWith): - bhomEvaluator = TextComparisonType.StartsWith; - break; - case typeof(Autodesk.Revit.DB.FilterStringEndsWith): - bhomEvaluator = TextComparisonType.EndsWith; - break; - case typeof(Autodesk.Revit.DB.FilterStringEquals): - bhomEvaluator = TextComparisonType.Equal; - break; - case typeof(Autodesk.Revit.DB.FilterStringContains): - bhomEvaluator = TextComparisonType.Contains; - break; - case typeof(Autodesk.Revit.DB.FilterStringGreater): - bhomEvaluator = TextComparisonType.Greater; - break; - case typeof(Autodesk.Revit.DB.FilterStringGreaterOrEqual): - bhomEvaluator = TextComparisonType.GreaterOrEqual; - break; - case typeof(Autodesk.Revit.DB.FilterStringLess): - bhomEvaluator = TextComparisonType.Less; - break; - case typeof(Autodesk.Revit.DB.FilterStringLessOrEqual): - bhomEvaluator = TextComparisonType.LessOrEqual; - break; - default: - break; - } + TextComparisonType bhomTextEvaluator = 0; + NumberComparisonType bhomNumericEvaluator = 0; - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; - bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = paramName; - bhomFilterStringRule.Value = paramValue; - bhomFilterStringRule.Evaluator = bhomEvaluator; - - return bhomFilterStringRule; - } + // FILTER STRING RULE + if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + { + Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramValue = revitFilterStringRule.RuleString; + FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); - // FILTER DOUBLE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + switch (stringEvaluator.GetType().ToString()) { - Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; - string paramValue = revitFilterDoubleRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); - - NumberComparisonType bhomEvaluator; + case "Autodesk.Revit.DB.FilterStringBeginsWith": + bhomTextEvaluator = TextComparisonType.StartsWith; + break; + case "Autodesk.Revit.DB.FilterStringEndsWith": + bhomTextEvaluator = TextComparisonType.EndsWith; + break; + case "Autodesk.Revit.DB.FilterStringEquals": + bhomTextEvaluator = TextComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterStringContains": + bhomTextEvaluator = TextComparisonType.Contains; + break; + case "Autodesk.Revit.DB.FilterStringGreater": + bhomTextEvaluator = TextComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": + bhomTextEvaluator = TextComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterStringLess": + bhomTextEvaluator = TextComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterStringLessOrEqual": + bhomTextEvaluator = TextComparisonType.LessOrEqual; + break; + default: + break; + } - switch (numericEvaluator.GetType()) - { - case typeof(Autodesk.Revit.DB.FilterNumericEquals): - bhomEvaluator = NumberComparisonType.Equal; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreater): - bhomEvaluator = NumberComparisonType.Greater; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): - bhomEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLess): - bhomEvaluator = NumberComparisonType.Less; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): - bhomEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = paramName; + bhomFilterStringRule.Value = paramValue; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; - BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; - bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = paramName; - bhomFilterDoubleRule.Value = paramValue; - bhomFilterDoubleRule.Evaluator = bhomEvaluator; + return bhomFilterStringRule; + } - return bhomFilterDoubleRule; - } + // FILTER DOUBLE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + { + Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); - // FILTER INTEGER RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + switch (numericEvaluator.GetType().ToString()) { - Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; - string paramValue = revitFilterIntegerRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } - NumberComparisonType bhomEvaluator; + BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = paramName; + bhomFilterDoubleRule.Value = paramValue; + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; - switch (numericEvaluator.GetType()) - { - case typeof(Autodesk.Revit.DB.FilterNumericEquals): - bhomEvaluator = NumberComparisonType.Equal; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreater): - bhomEvaluator = NumberComparisonType.Greater; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): - bhomEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLess): - bhomEvaluator = NumberComparisonType.Less; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): - bhomEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + return bhomFilterDoubleRule; + } - BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; - bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = paramName; - bhomFilterIntegerRule.Value = paramValue; - bhomFilterIntegerRule.Evaluator = bhomEvaluator; + // FILTER INTEGER RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + { + Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); - return bhomFilterIntegerRule; + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; } - // FILTER CATEGORY RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) - { - Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; - List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); + BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = paramName; + bhomFilterIntegerRule.Value = paramValue; + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; - BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; - bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); - bhomFilterCategoryRule.CategoryNames = categoryNames; + return bhomFilterIntegerRule; + } - return bhomFilterCategoryRule; - } + // FILTER CATEGORY RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + { + Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; + List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); - // FILTER INVERSE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) - { - Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; - Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); - TextComparisonType bhomTextEvaluator; - NumberComparisonType bhomNumberEvaluator; - - switch (innerRule.GetType()) - { - case (typeof(Autodesk.Revit.DB.FilterStringRule)): - switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType()) { - case (typeof(FilterStringEquals)): - bhomTextEvaluator = TextComparisonType.NotEqual; - break; - case (typeof(FilterStringBeginsWith)): - bhomTextEvaluator = TextComparisonType.NotStartsWith; - break; - case (typeof(FilterStringEndsWith)): - bhomTextEvaluator = TextComparisonType.NotEndsWith; - break; - case (typeof(FilterStringContains)): - bhomTextEvaluator = TextComparisonType.ContainsNot; - break; - default: - break;} - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule; + BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); + bhomFilterCategoryRule.CategoryNames = categoryNames; - } + return bhomFilterCategoryRule; + } - return ; - } + // FILTER INVERSE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + { + Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; + Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); + + switch (innerRule.GetType().ToString()) + { + case ("Autodesk.Revit.DB.FilterStringRule"): { + switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) { + case ("FilterStringEquals"): + bhomTextEvaluator = TextComparisonType.NotEqual; + break; + case ("FilterStringBeginsWith"): + bhomTextEvaluator = TextComparisonType.NotStartsWith; + break; + case ("FilterStringEndsWith"): + bhomTextEvaluator = TextComparisonType.NotEndsWith; + break; + case ("FilterStringContains"): + bhomTextEvaluator = TextComparisonType.ContainsNot; + break; + default: + break; } + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + return bhomFilterStringRule; } + case ("Autodesk.Revit.DB.FilterDoubleRule"): { + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator= NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break;} + BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + return bhomFilterDoubleRule;} + case ("Autodesk.Revit.DB.FilterIntegerRule"):{ + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()){ + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break;} + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + return bhomFilterStringRule;} }); //Set identifiers, parameters & custom data From 764157aa713a9a1aec972546989fef5d173f2a7a Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 17:30:26 +0100 Subject: [PATCH 028/131] Initialize FilterRule Classes in FromRevit and ToRevit Namespaces Instead of keeping the conversion of FilterRule objects from/to Revit/BHoM within the ParameterFilter/ViewFilter conversion classes only, we split the code in each different FilterRule Class keeping the code more modular and reusable. --- .../Convert/Revit/FromRevit/FilterCategoryRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterDoubleRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterElementIdRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterIntegerRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterInverseRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterStringRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterCategoryRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterDoubleRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterElementIdRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterIntegerRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterInverseRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterStringRule.cs | 12 ++++++++++++ 12 files changed, 144 insertions(+) create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs new file mode 100644 index 000000000..5f673d9f0 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterCategoryRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs new file mode 100644 index 000000000..92e03930f --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterDoubleRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs new file mode 100644 index 000000000..4941f781c --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterElementIdRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs new file mode 100644 index 000000000..a2dfb88db --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterIntegerRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs new file mode 100644 index 000000000..6562f897d --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterInverseRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs new file mode 100644 index 000000000..f2efab1e1 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterStringRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs new file mode 100644 index 000000000..820ee9b17 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterCategoryRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs new file mode 100644 index 000000000..a629d739e --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterDoubleRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs new file mode 100644 index 000000000..a9d6ee96d --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterElementIdRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs new file mode 100644 index 000000000..9b5a1e1da --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterIntegerRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs new file mode 100644 index 000000000..00aea9676 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterInverseRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs new file mode 100644 index 000000000..e4b2c8aa0 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterStringRule + { + } +} From 5338ba9bf8223408ed2ac3424bf056dd5bb5e610 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:04:08 +0100 Subject: [PATCH 029/131] Delete all FilterRule classes created in the Convert.FromRevit/ToRevit namespaces. Any class that can be stored in the Convert.FromRevit/ToRevit namespace, has to be convertible into Revit.DB.Element Class. Since FilterRule classes are not convertible into Revit.DB.Elements, they cannot be present in the Convert.FromRevit/ToRevit. --- .../Revit/FromRevit/FilterCategoryRule.cs | 12 --- .../Revit/FromRevit/FilterDoubleRule.cs | 12 --- .../Revit/FromRevit/FilterElementIdRule.cs | 12 --- .../Revit/FromRevit/FilterIntegerRule.cs | 12 --- .../Revit/FromRevit/FilterInverseRule.cs | 12 --- .../Revit/FromRevit/FilterStringRule.cs | 12 --- .../Convert/Revit/FromRevit/ViewFilter.cs | 78 +++++++++++++++++-- .../Revit/ToRevit/FilterCategoryRule.cs | 12 --- .../Convert/Revit/ToRevit/FilterDoubleRule.cs | 12 --- .../Revit/ToRevit/FilterElementIdRule.cs | 12 --- .../Revit/ToRevit/FilterIntegerRule.cs | 12 --- .../Revit/ToRevit/FilterInverseRule.cs | 12 --- .../Convert/Revit/ToRevit/FilterStringRule.cs | 12 --- .../Revit/ToRevit/ParameterFilterElement.cs | 24 ------ Revit_oM/Elements/FilterCategoryRule.cs | 2 +- Revit_oM/Elements/FilterDoubleRule.cs | 2 +- Revit_oM/Elements/FilterElementIdRule.cs | 4 +- Revit_oM/Elements/FilterIntegerRule.cs | 2 +- Revit_oM/Elements/FilterLevelRule.cs | 2 +- Revit_oM/Elements/FilterMaterialRule.cs | 2 +- Revit_oM/Elements/FilterNumericValueRule.cs | 2 +- Revit_oM/Elements/FilterRule.cs | 2 +- Revit_oM/Elements/FilterStringRule.cs | 2 +- Revit_oM/Elements/FilterValueRule.cs | 2 +- 24 files changed, 83 insertions(+), 185 deletions(-) delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs deleted file mode 100644 index 5f673d9f0..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterCategoryRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs deleted file mode 100644 index 92e03930f..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterDoubleRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs deleted file mode 100644 index 4941f781c..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterElementIdRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs deleted file mode 100644 index a2dfb88db..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterIntegerRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs deleted file mode 100644 index 6562f897d..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterInverseRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs deleted file mode 100644 index f2efab1e1..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterStringRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 446b45d2c..f32aa1f52 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -194,6 +194,44 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par return bhomFilterIntegerRule; } + // FILTER ELEMENTID RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) + { + Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; + string paramValue = revitFilterElemIdRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); + + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; + bhomFilterElemIdRule = new oM.Revit.Elements.FilterElementIdRule(); + bhomFilterElemIdRule.ParameterName = paramName; + bhomFilterElemIdRule.Value = paramValue; + bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterElemIdRule; + } + // FILTER CATEGORY RULE else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) { @@ -275,13 +313,41 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par case ("FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break;} - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; - return bhomFilterStringRule;} + BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + return bhomFilterIntegerRule;} + case ("Autodesk.Revit.DB.FilterElementIdRule"): + { + switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new oM.Revit.Elements.FilterElementIdRule(); + bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); + bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; + return bhomFilterElementIdRule; + } + + - }); + }); //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs deleted file mode 100644 index 820ee9b17..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterCategoryRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs deleted file mode 100644 index a629d739e..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterDoubleRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs deleted file mode 100644 index a9d6ee96d..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterElementIdRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs deleted file mode 100644 index 9b5a1e1da..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterIntegerRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs deleted file mode 100644 index 00aea9676..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterInverseRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs deleted file mode 100644 index e4b2c8aa0..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterStringRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index e03e9003c..a905e0945 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -119,30 +119,6 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Revit.Elements.FilterCategoryRule filterCategoryRule) - { - /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ - Autodesk.Revit.DB.FilterRule revitFilterRule = null; - - /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ - List categoryIds = new FilteredElementCollector(document) - // Get all the Categories (INTERMEDIATE OPERATION) - .OfClass(typeof(Autodesk.Revit.DB.Category)) - // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) - .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) - // Cast down to Category Class Instances (INTERMEDIATE OPERATION) - .Cast() - // Get the ids of the retain categories (INTERMEDIATE OPERATION) - .Select(cat => cat.Id) - // Turn the Stream into a List (TERMINAL OPERATION) - .ToList(); - - /* 3. CREATE THE FILTER RULE */ - revitFilterRule = new Autodesk.Revit.DB.FilterCategoryRule(categoryIds); - - return revitFilterRule; - } - /***************************************************/ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/Elements/FilterCategoryRule.cs index 6839e5326..8e5bdf13d 100644 --- a/Revit_oM/Elements/FilterCategoryRule.cs +++ b/Revit_oM/Elements/FilterCategoryRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterCategoryRule : FilterRule { diff --git a/Revit_oM/Elements/FilterDoubleRule.cs b/Revit_oM/Elements/FilterDoubleRule.cs index 3fcf2c561..8b4b59a35 100644 --- a/Revit_oM/Elements/FilterDoubleRule.cs +++ b/Revit_oM/Elements/FilterDoubleRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterDoubleRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterElementIdRule.cs b/Revit_oM/Elements/FilterElementIdRule.cs index 6012f2b70..6d1ff5b18 100644 --- a/Revit_oM/Elements/FilterElementIdRule.cs +++ b/Revit_oM/Elements/FilterElementIdRule.cs @@ -4,9 +4,9 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { - internal class FilterElementIdRule + public class FilterElementIdRule : FilterNumericValueRule { } } diff --git a/Revit_oM/Elements/FilterIntegerRule.cs b/Revit_oM/Elements/FilterIntegerRule.cs index a2c8bcb76..dbcf8313d 100644 --- a/Revit_oM/Elements/FilterIntegerRule.cs +++ b/Revit_oM/Elements/FilterIntegerRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterIntegerRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterLevelRule.cs b/Revit_oM/Elements/FilterLevelRule.cs index 4ef03af4e..4e244aec9 100644 --- a/Revit_oM/Elements/FilterLevelRule.cs +++ b/Revit_oM/Elements/FilterLevelRule.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using BH.oM.Revit.Enums; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterLevelRule : FilterRule { diff --git a/Revit_oM/Elements/FilterMaterialRule.cs b/Revit_oM/Elements/FilterMaterialRule.cs index b6313e469..3c86f85c0 100644 --- a/Revit_oM/Elements/FilterMaterialRule.cs +++ b/Revit_oM/Elements/FilterMaterialRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterMaterialRule : FilterRule { diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/Elements/FilterNumericValueRule.cs index 14aa34daf..4a07b6e98 100644 --- a/Revit_oM/Elements/FilterNumericValueRule.cs +++ b/Revit_oM/Elements/FilterNumericValueRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterNumericValueRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Elements/FilterRule.cs index 567d22e54..187db502a 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/Elements/FilterRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public abstract class FilterRule : BHoMObject { diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/Elements/FilterStringRule.cs index 5ffb5c8ee..9189bfc94 100644 --- a/Revit_oM/Elements/FilterStringRule.cs +++ b/Revit_oM/Elements/FilterStringRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterStringRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/Elements/FilterValueRule.cs index e47c16ad3..684616ba8 100644 --- a/Revit_oM/Elements/FilterValueRule.cs +++ b/Revit_oM/Elements/FilterValueRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public abstract class FilterValueRule : FilterRule { From 29c3c1b2315c0ecb1bd72b42fdc37485a4f6f0da Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:33:31 +0100 Subject: [PATCH 030/131] Reinstate the method filterCategoryRuleToRevit in the Convert.ToRevit.ParameterFilterElement Class. Deleted previously by mistake. --- .../Revit/ToRevit/ParameterFilterElement.cs | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a905e0945..a0f28fefc 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -93,16 +93,16 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterCategoryRule))){ - filterRules = kvp.Value.Cast() + if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterCategoryRule))){ + filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterValueRule))){ - filterRules = kvp.Value.Cast() + else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterValueRule))){ + filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterMaterialRule))){ - filterRules = kvp.Value.Cast() + else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterMaterialRule))){ + filterRules = kvp.Value.Cast< BH.oM.Adapters.Revit.Elements.FilterMaterialRule >() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList();} return filterRules; }) @@ -119,9 +119,34 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) + public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterCategoryRule filterCategoryRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ + List categoryIds = new FilteredElementCollector(document) + // Get all the Categories (INTERMEDIATE OPERATION) + .OfClass(typeof(Autodesk.Revit.DB.Category)) + // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) + .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) + // Cast down to Category Class Instances (INTERMEDIATE OPERATION) + .Cast() + // Get the ids of the retain categories (INTERMEDIATE OPERATION) + .Select(cat => cat.Id) + // Turn the Stream into a List (TERMINAL OPERATION) + .ToList(); + + /* 3. CREATE THE FILTER RULE */ + revitFilterRule = new Autodesk.Revit.DB.FilterCategoryRule(categoryIds); + + return revitFilterRule; + } + + /***************************************************/ + + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -137,7 +162,7 @@ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Revit.Elements.FilterLevelRule filterLevelRule) + public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterLevelRule filterLevelRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -198,7 +223,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { + public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Adapters.Revit.Elements.FilterValueRule filterValueRule) { /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -218,7 +243,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { - BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Revit.Elements.FilterStringRule)filterValueRule; + BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; switch (filterStringValueRule.Evaluator) { @@ -275,9 +300,9 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum } // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.Elements.FilterNumericValueRule))) + } else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterNumericValueRule))) { - BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Revit.Elements.FilterNumericValueRule)filterValueRule; + BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; switch (filterNumericValueRule.Evaluator) { From 41d425e37ce5e4024262203bf5e674e9593833b5 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:54:41 +0100 Subject: [PATCH 031/131] Add method to convert a Revit ParameterFilterElement into a BHoM ViewFilter. --- Revit_Core_Engine/Convert/FromRevit.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Revit_Core_Engine/Convert/FromRevit.cs b/Revit_Core_Engine/Convert/FromRevit.cs index a33531928..ece4d62d5 100644 --- a/Revit_Core_Engine/Convert/FromRevit.cs +++ b/Revit_Core_Engine/Convert/FromRevit.cs @@ -71,6 +71,28 @@ public static IGeometry IFromRevit(this Location location) /**** Convert Revit elements to BHoM ****/ /***************************************************/ + [Description("Converts a Revit ParameterFilterElement to a BHoM object based on the requested engineering discipline.")] + [Input("parameterFilterElement", "Revit ParameterFilterElement to be converted.")] + [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + [Input("transform", "Optional, a transform to apply to the converted object.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("fromRevit", "Resulted BHoM object converted from a Revit ParameterFilterElement.")] + public static List FromRevit(this ParameterFilterElement parameterFilterElement, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary> refObjects = null) + { + if (parameterFilterElement == null) + { + BH.Engine.Base.Compute.RecordWarning("BHoM object could not be read because Revit Parameter Filter Element is null."); + return null; + } + else + { + return new List { ViewFilterFromRevit(parameterFilterElement, settings, refObjects) }; + } + } + + /***************************************************/ + [Description("Converts a Revit EnergyAnalysisDetailModel to a BHoM object based on the requested engineering discipline.")] [Input("energyAnalysisModel", "Revit EnergyAnalysisDetailModel to be converted.")] [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] From 0186d7f37e22901f27cbb519bc30817647ebb5b0 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:56:10 +0100 Subject: [PATCH 032/131] Incorporate minor fixes to references between classes --- .../Convert/Revit/FromRevit/ViewFilter.cs | 32 +++++++++---------- .../Revit/ToRevit/ParameterFilterElement.cs | 10 +++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index f32aa1f52..bf9478cf1 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,7 +26,7 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; -using BH.oM.Revit.Elements; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; @@ -66,7 +66,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); - List bhomFilterRules = revitFilterRules.Select(revitRule => + List bhomFilterRules = revitFilterRules.Select(revitRule => { TextComparisonType bhomTextEvaluator = 0; NumberComparisonType bhomNumericEvaluator = 0; @@ -109,8 +109,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; - bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); bhomFilterStringRule.ParameterName = paramName; bhomFilterStringRule.Value = paramValue; bhomFilterStringRule.Evaluator = bhomTextEvaluator; @@ -147,8 +147,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; - bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = paramName; bhomFilterDoubleRule.Value = paramValue; bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; @@ -185,8 +185,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; - bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = paramName; bhomFilterIntegerRule.Value = paramValue; bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; @@ -223,8 +223,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; - bhomFilterElemIdRule = new oM.Revit.Elements.FilterElementIdRule(); + BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; + bhomFilterElemIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); bhomFilterElemIdRule.ParameterName = paramName; bhomFilterElemIdRule.Value = paramValue; bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; @@ -238,8 +238,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); - BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; - bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); + BH.oM.Adapters.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new BH.oM.Adapters.Revit.Elements.FilterCategoryRule(); bhomFilterCategoryRule.CategoryNames = categoryNames; return bhomFilterCategoryRule; @@ -269,7 +269,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; default: break; } - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; bhomFilterStringRule.Evaluator = bhomTextEvaluator; @@ -291,7 +291,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par case ("FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break;} - BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; @@ -313,7 +313,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par case ("FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break;} - BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; @@ -338,7 +338,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } - BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new oM.Revit.Elements.FilterElementIdRule(); + BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a0f28fefc..836a8b59d 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -30,7 +30,7 @@ using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; -using BH.oM.Revit.Elements; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Revit.Enums; using System; using System.Collections.Generic; @@ -38,8 +38,8 @@ using System.Linq; using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; -using FilterRule = BH.oM.Revit.Elements.FilterRule; -using FilterStringRule = BH.oM.Revit.Elements.FilterStringRule; +using FilterRule = BH.oM.Adapters.Revit.Elements.FilterRule; +using FilterStringRule = BH.oM.Adapters.Revit.Elements.FilterStringRule; namespace BH.Revit.Engine.Core { @@ -243,7 +243,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { - BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; + BH.oM.Adapters.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; switch (filterStringValueRule.Evaluator) { @@ -302,7 +302,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterNumericValueRule... } else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterNumericValueRule))) { - BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; + BH.oM.Adapters.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; switch (filterNumericValueRule.Evaluator) { From e0e27b2a6fda47ba1cae7880527fedd732cc30ee Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 19:29:58 +0100 Subject: [PATCH 033/131] Add ParameterValuePresenceRule Add it as BHoM Class and implement code for conversion to/from Revit --- .../Convert/Revit/FromRevit/ViewFilter.cs | 12 ++++++++++++ .../Revit/ToRevit/ParameterFilterElement.cs | 12 ++++++++++++ Revit_oM/Elements/ParameterValuePresenceRule.cs | 14 ++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 Revit_oM/Elements/ParameterValuePresenceRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index bf9478cf1..baa3ec31e 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -245,6 +245,18 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par return bhomFilterCategoryRule; } + // FILTER PARAMETER VALUE PRESENCE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) + { + BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule bhomParamValuePresenceRule; + bhomParamValuePresenceRule = new BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule(); + + bhomParamValuePresenceRule.ParameterName= revitViewFilter.Document.GetElement(((Autodesk.Revit.DB.ParameterValuePresenceRule)revitRule).Parameter).Name; + bhomParamValuePresenceRule.IsPresent = (revitRule.GetType() == typeof(HasValueFilterRule)) ? true : false; + + return bhomParamValuePresenceRule; + } + // FILTER INVERSE RULE else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) { diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 836a8b59d..2e2624a8d 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -333,6 +333,18 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum default: break; } + } + + // Based on ParameterValuePresenceRule... + else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule))) + { + BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule parameterValuePresenceRule = (BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule)filterValueRule; + + if (parameterValuePresenceRule.IsPresent) { + revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId);} + else { + revitFilterRule = ParameterFilterRuleFactory.CreateHasNoValueParameterRule(parameterId);} + } else { return null; } diff --git a/Revit_oM/Elements/ParameterValuePresenceRule.cs b/Revit_oM/Elements/ParameterValuePresenceRule.cs new file mode 100644 index 000000000..ffdc94241 --- /dev/null +++ b/Revit_oM/Elements/ParameterValuePresenceRule.cs @@ -0,0 +1,14 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Elements +{ + public class ParameterValuePresenceRule : FilterValueRule + { + public virtual bool IsPresent { get; set; } + } +} From 78306b0f36a105c030221c5e72c3253002aebcfc Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 15:45:21 +0100 Subject: [PATCH 034/131] Move all BHoM Filter Rules from oM.Elements to oM.FilterRules namespace. In the oM.Elements namespace we can store only the BHoM object that have a direct corresponding object in Revit. --- .../Revit/ToRevit/ParameterFilterElement.cs | 36 +++++++++---------- Revit_oM/Elements/ViewFilter.cs | 1 + .../FilterCategoryRule.cs | 2 +- .../FilterDoubleRule.cs | 2 +- .../FilterElementIdRule.cs | 2 +- .../FilterIntegerRule.cs | 2 +- .../FilterLevelRule.cs | 2 +- .../FilterMaterialRule.cs | 2 +- .../FilterNumericValueRule.cs | 2 +- .../{Elements => FilterRules}/FilterRule.cs | 2 +- .../FilterStringRule.cs | 2 +- .../FilterValueRule.cs | 2 +- .../ParameterValuePresenceRule.cs | 4 +-- 13 files changed, 31 insertions(+), 30 deletions(-) rename Revit_oM/{Elements => FilterRules}/FilterCategoryRule.cs (86%) rename Revit_oM/{Elements => FilterRules}/FilterDoubleRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterElementIdRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterIntegerRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterLevelRule.cs (89%) rename Revit_oM/{Elements => FilterRules}/FilterMaterialRule.cs (85%) rename Revit_oM/{Elements => FilterRules}/FilterNumericValueRule.cs (88%) rename Revit_oM/{Elements => FilterRules}/FilterRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterStringRule.cs (87%) rename Revit_oM/{Elements => FilterRules}/FilterValueRule.cs (88%) rename Revit_oM/{Elements => FilterRules}/ParameterValuePresenceRule.cs (69%) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 2e2624a8d..7bb739841 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -30,16 +30,16 @@ using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; -using BH.oM.Adapters.Revit.Elements; using BH.oM.Revit.Enums; +using BH.oM.Revit.FilterRules; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; -using FilterRule = BH.oM.Adapters.Revit.Elements.FilterRule; -using FilterStringRule = BH.oM.Adapters.Revit.Elements.FilterStringRule; +using FilterRule = BH.oM.Revit.FilterRules.FilterRule; +using FilterStringRule = BH.oM.Revit.FilterRules.FilterStringRule; namespace BH.Revit.Engine.Core { @@ -93,16 +93,16 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterCategoryRule))){ - filterRules = kvp.Value.Cast() + if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))){ + filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterValueRule))){ - filterRules = kvp.Value.Cast() + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))){ + filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterMaterialRule))){ - filterRules = kvp.Value.Cast< BH.oM.Adapters.Revit.Elements.FilterMaterialRule >() + else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))){ + filterRules = kvp.Value.Cast() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList();} return filterRules; }) @@ -120,7 +120,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterCategoryRule filterCategoryRule) + public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, oM.Revit.FilterRules.FilterCategoryRule filterCategoryRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -146,7 +146,7 @@ public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterMaterialRule filterMaterialRule) + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -162,7 +162,7 @@ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterLevelRule filterLevelRule) + public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, FilterLevelRule filterLevelRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -223,7 +223,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Adapters.Revit.Elements.FilterValueRule filterValueRule) { + public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -243,7 +243,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { - BH.oM.Adapters.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; + FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; switch (filterStringValueRule.Evaluator) { @@ -300,9 +300,9 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum } // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterNumericValueRule))) + } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { - BH.oM.Adapters.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; + oM.Revit.FilterRules.FilterNumericValueRule filterNumericValueRule = (oM.Revit.FilterRules.FilterNumericValueRule)filterValueRule; switch (filterNumericValueRule.Evaluator) { @@ -336,9 +336,9 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum } // Based on ParameterValuePresenceRule... - else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule))) + else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) { - BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule parameterValuePresenceRule = (BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule)filterValueRule; + oM.Revit.FilterRules.ParameterValuePresenceRule parameterValuePresenceRule = (oM.Revit.FilterRules.ParameterValuePresenceRule)filterValueRule; if (parameterValuePresenceRule.IsPresent) { revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId);} diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 9eb89989a..a33b5bb16 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,5 +1,6 @@ using BH.oM.Base; using BH.oM.Revit.Elements; +using BH.oM.Revit.FilterRules; using System; using System.Collections.Generic; using System.Linq; diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/FilterRules/FilterCategoryRule.cs similarity index 86% rename from Revit_oM/Elements/FilterCategoryRule.cs rename to Revit_oM/FilterRules/FilterCategoryRule.cs index 8e5bdf13d..6e96aa1e7 100644 --- a/Revit_oM/Elements/FilterCategoryRule.cs +++ b/Revit_oM/FilterRules/FilterCategoryRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterCategoryRule : FilterRule { diff --git a/Revit_oM/Elements/FilterDoubleRule.cs b/Revit_oM/FilterRules/FilterDoubleRule.cs similarity index 83% rename from Revit_oM/Elements/FilterDoubleRule.cs rename to Revit_oM/FilterRules/FilterDoubleRule.cs index 8b4b59a35..5a1b38436 100644 --- a/Revit_oM/Elements/FilterDoubleRule.cs +++ b/Revit_oM/FilterRules/FilterDoubleRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterDoubleRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterElementIdRule.cs b/Revit_oM/FilterRules/FilterElementIdRule.cs similarity index 83% rename from Revit_oM/Elements/FilterElementIdRule.cs rename to Revit_oM/FilterRules/FilterElementIdRule.cs index 6d1ff5b18..4aff13a04 100644 --- a/Revit_oM/Elements/FilterElementIdRule.cs +++ b/Revit_oM/FilterRules/FilterElementIdRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterElementIdRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterIntegerRule.cs b/Revit_oM/FilterRules/FilterIntegerRule.cs similarity index 83% rename from Revit_oM/Elements/FilterIntegerRule.cs rename to Revit_oM/FilterRules/FilterIntegerRule.cs index dbcf8313d..7de43b6ec 100644 --- a/Revit_oM/Elements/FilterIntegerRule.cs +++ b/Revit_oM/FilterRules/FilterIntegerRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterIntegerRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterLevelRule.cs b/Revit_oM/FilterRules/FilterLevelRule.cs similarity index 89% rename from Revit_oM/Elements/FilterLevelRule.cs rename to Revit_oM/FilterRules/FilterLevelRule.cs index 4e244aec9..5745b4b1d 100644 --- a/Revit_oM/Elements/FilterLevelRule.cs +++ b/Revit_oM/FilterRules/FilterLevelRule.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using BH.oM.Revit.Enums; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterLevelRule : FilterRule { diff --git a/Revit_oM/Elements/FilterMaterialRule.cs b/Revit_oM/FilterRules/FilterMaterialRule.cs similarity index 85% rename from Revit_oM/Elements/FilterMaterialRule.cs rename to Revit_oM/FilterRules/FilterMaterialRule.cs index 3c86f85c0..2214b22c7 100644 --- a/Revit_oM/Elements/FilterMaterialRule.cs +++ b/Revit_oM/FilterRules/FilterMaterialRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterMaterialRule : FilterRule { diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/FilterRules/FilterNumericValueRule.cs similarity index 88% rename from Revit_oM/Elements/FilterNumericValueRule.cs rename to Revit_oM/FilterRules/FilterNumericValueRule.cs index 4a07b6e98..416e19b62 100644 --- a/Revit_oM/Elements/FilterNumericValueRule.cs +++ b/Revit_oM/FilterRules/FilterNumericValueRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterNumericValueRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/FilterRules/FilterRule.cs similarity index 83% rename from Revit_oM/Elements/FilterRule.cs rename to Revit_oM/FilterRules/FilterRule.cs index 187db502a..52b0f5fba 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/FilterRules/FilterRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public abstract class FilterRule : BHoMObject { diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/FilterRules/FilterStringRule.cs similarity index 87% rename from Revit_oM/Elements/FilterStringRule.cs rename to Revit_oM/FilterRules/FilterStringRule.cs index 9189bfc94..39116a35c 100644 --- a/Revit_oM/Elements/FilterStringRule.cs +++ b/Revit_oM/FilterRules/FilterStringRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterStringRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/FilterRules/FilterValueRule.cs similarity index 88% rename from Revit_oM/Elements/FilterValueRule.cs rename to Revit_oM/FilterRules/FilterValueRule.cs index 684616ba8..46a80d90a 100644 --- a/Revit_oM/Elements/FilterValueRule.cs +++ b/Revit_oM/FilterRules/FilterValueRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public abstract class FilterValueRule : FilterRule { diff --git a/Revit_oM/Elements/ParameterValuePresenceRule.cs b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs similarity index 69% rename from Revit_oM/Elements/ParameterValuePresenceRule.cs rename to Revit_oM/FilterRules/ParameterValuePresenceRule.cs index ffdc94241..7089a6bf2 100644 --- a/Revit_oM/Elements/ParameterValuePresenceRule.cs +++ b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs @@ -5,10 +5,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class ParameterValuePresenceRule : FilterValueRule { - public virtual bool IsPresent { get; set; } + public virtual bool IsPresent { get; set; } } } From 4d56096215088b1ee2f57d1f8af487670fdcfea8 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 17:00:29 +0100 Subject: [PATCH 035/131] Refactor the partial class FromRevit.ViewFilter --- .../Convert/Revit/FromRevit/ViewFilter.cs | 703 ++++++++++-------- 1 file changed, 406 insertions(+), 297 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index baa3ec31e..58e37f9d1 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,7 +26,6 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; -using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; @@ -58,308 +57,20 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 1. Transfer Filter NAME */ viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; + /* 2. Transfer List of CATEGORY NAMES */ viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); + /* 3. Transfer List of FILTER RULES */ - //viewFilter.Rules + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); + //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); - List bhomFilterRules = revitFilterRules.Select(revitRule => - { - TextComparisonType bhomTextEvaluator = 0; - NumberComparisonType bhomNumericEvaluator = 0; - - // FILTER STRING RULE - if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) - { - Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; - string paramValue = revitFilterStringRule.RuleString; - FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); - - switch (stringEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterStringBeginsWith": - bhomTextEvaluator = TextComparisonType.StartsWith; - break; - case "Autodesk.Revit.DB.FilterStringEndsWith": - bhomTextEvaluator = TextComparisonType.EndsWith; - break; - case "Autodesk.Revit.DB.FilterStringEquals": - bhomTextEvaluator = TextComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterStringContains": - bhomTextEvaluator = TextComparisonType.Contains; - break; - case "Autodesk.Revit.DB.FilterStringGreater": - bhomTextEvaluator = TextComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": - bhomTextEvaluator = TextComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterStringLess": - bhomTextEvaluator = TextComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterStringLessOrEqual": - bhomTextEvaluator = TextComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule; - bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = paramName; - bhomFilterStringRule.Value = paramValue; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; - - return bhomFilterStringRule; - } - - // FILTER DOUBLE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) - { - Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; - string paramValue = revitFilterDoubleRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); - - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; - bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = paramName; - bhomFilterDoubleRule.Value = paramValue; - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; - - return bhomFilterDoubleRule; - } - - // FILTER INTEGER RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) - { - Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; - string paramValue = revitFilterIntegerRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); - - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; - bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = paramName; - bhomFilterIntegerRule.Value = paramValue; - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; - - return bhomFilterIntegerRule; - } - - // FILTER ELEMENTID RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) - { - Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; - string paramValue = revitFilterElemIdRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); - - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; - bhomFilterElemIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); - bhomFilterElemIdRule.ParameterName = paramName; - bhomFilterElemIdRule.Value = paramValue; - bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; - - return bhomFilterElemIdRule; - } - - // FILTER CATEGORY RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) - { - Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; - List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); - - BH.oM.Adapters.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; - bhomFilterCategoryRule = new BH.oM.Adapters.Revit.Elements.FilterCategoryRule(); - bhomFilterCategoryRule.CategoryNames = categoryNames; - - return bhomFilterCategoryRule; - } - - // FILTER PARAMETER VALUE PRESENCE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) - { - BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule bhomParamValuePresenceRule; - bhomParamValuePresenceRule = new BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule(); - - bhomParamValuePresenceRule.ParameterName= revitViewFilter.Document.GetElement(((Autodesk.Revit.DB.ParameterValuePresenceRule)revitRule).Parameter).Name; - bhomParamValuePresenceRule.IsPresent = (revitRule.GetType() == typeof(HasValueFilterRule)) ? true : false; - - return bhomParamValuePresenceRule; - } - - // FILTER INVERSE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) - { - Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; - Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); - - switch (innerRule.GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterStringRule"): { - switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterStringEquals"): - bhomTextEvaluator = TextComparisonType.NotEqual; - break; - case ("FilterStringBeginsWith"): - bhomTextEvaluator = TextComparisonType.NotStartsWith; - break; - case ("FilterStringEndsWith"): - bhomTextEvaluator = TextComparisonType.NotEndsWith; - break; - case ("FilterStringContains"): - bhomTextEvaluator = TextComparisonType.ContainsNot; - break; - default: - break; } - BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; - return bhomFilterStringRule; } - case ("Autodesk.Revit.DB.FilterDoubleRule"): { - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericGreater"): - bhomNumericEvaluator= NumberComparisonType.Less; - break; - case ("FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break;} - BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; - return bhomFilterDoubleRule;} - case ("Autodesk.Revit.DB.FilterIntegerRule"):{ - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()){ - case ("FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break;} - BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; - return bhomFilterIntegerRule;} - case ("Autodesk.Revit.DB.FilterElementIdRule"): - { - switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } - BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); - bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); - bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; - return bhomFilterElementIdRule; - } - - - - }); + //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects + viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); + //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); @@ -369,7 +80,405 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par } /***************************************************/ - } + + //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and store them in a List - via STREAMS + private static List FilterRulesFromRevit(this ParameterFilterElement revitViewFilter, List revitFilterRules) + { + List bhomFilterRules = revitFilterRules.Select(revitRule => + { + TextComparisonType bhomTextEvaluator = 0; + NumberComparisonType bhomNumericEvaluator = 0; + + // FILTER STRING RULE + if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator); } + // FILTER DOUBLE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + // FILTER INTEGER RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + // FILTER ELEMENTID RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + // FILTER CATEGORY RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterCategoryRuleFromRevit(revitViewFilter, revitRule); } + // FILTER PARAMETER VALUE PRESENCE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) + { return (oM.Revit.FilterRules.FilterRule)ParameterValuePresenceRuleFromRevit(revitViewFilter, revitRule); } + // FILTER INVERSE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + { return FilterInverseRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator, bhomNumericEvaluator); } + return null; + }).ToList(); + + return bhomFilterRules; + } + + + private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterStringRule obj + Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; + // Extract name and value assigned to the parameter of the FilterStringRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramValue = revitFilterStringRule.RuleString; + // Get the RuleEvaluator of the FilterStringRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); + + // Convert the REVIT FilterStringEvaluator type into the BHOM TextComparisonType Enum + switch (stringEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterStringBeginsWith": + bhomTextEvaluator = TextComparisonType.StartsWith; + break; + case "Autodesk.Revit.DB.FilterStringEndsWith": + bhomTextEvaluator = TextComparisonType.EndsWith; + break; + case "Autodesk.Revit.DB.FilterStringEquals": + bhomTextEvaluator = TextComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterStringContains": + bhomTextEvaluator = TextComparisonType.Contains; + break; + case "Autodesk.Revit.DB.FilterStringGreater": + bhomTextEvaluator = TextComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": + bhomTextEvaluator = TextComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterStringLess": + bhomTextEvaluator = TextComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterStringLessOrEqual": + bhomTextEvaluator = TextComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new oM.Revit.FilterRules.FilterStringRule(); + bhomFilterStringRule.ParameterName = paramName; + bhomFilterStringRule.Value = paramValue; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + + return bhomFilterStringRule; + } + + + private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterDoubleRule obj + Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; + // Extract name and value assigned to the parameter of the FilterDoubleRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + // Get the RuleEvaluator of the FilterDoubleRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); + + // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = paramName; + bhomFilterDoubleRule.Value = paramValue; + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterDoubleRule; + } + + + private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterIntegerRule obj + Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; + // Extract name and value assigned to the parameter of the FilterIntegerRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + // Get the RuleEvaluator of the FilterIntegerRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); + + // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = paramName; + bhomFilterIntegerRule.Value = paramValue; + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterIntegerRule; + } + + + private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterElementIdRule obj + Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; + // Extract name and value assigned to the parameter of the FilterElementIdRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; + string paramValue = revitFilterElemIdRule.RuleValue.ToString(); + // Get the RuleEvaluator of the FilterElementIdRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); + + // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterElementIdRule bhomFilterElemIdRule; + bhomFilterElemIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); + bhomFilterElemIdRule.ParameterName = paramName; + bhomFilterElemIdRule.Value = paramValue; + bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterElemIdRule; + } + + + private static oM.Revit.FilterRules.FilterCategoryRule FilterCategoryRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterCategoryRule obj + Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; + // Extract name and value assigned to the parameter of the FilterElementIdRule obj + List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new BH.oM.Revit.FilterRules.FilterCategoryRule(); + bhomFilterCategoryRule.CategoryNames = categoryNames; + + return bhomFilterCategoryRule; + } + + + private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePresenceRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + oM.Revit.FilterRules.ParameterValuePresenceRule bhomParamValuePresenceRule; + bhomParamValuePresenceRule = new BH.oM.Revit.FilterRules.ParameterValuePresenceRule(); + + // 2. BUILD the BHOM FILTERRULE object + + bhomParamValuePresenceRule.ParameterName = revitViewFilter.Document.GetElement(((Autodesk.Revit.DB.ParameterValuePresenceRule)revitRule).Parameter).Name; + bhomParamValuePresenceRule.IsPresent = (revitRule.GetType() == typeof(HasValueFilterRule)) ? true : false; + + return bhomParamValuePresenceRule; + } + + + private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterInverseRule obj + Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; + // Extract innerRule assigned to the Revit FilterInverseRule obj + Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); + + // Convert the REVIT InnerRule into the corresponding BHOM FilterRule obj + switch (innerRule.GetType().ToString()) + { + //FilterStringRule + case ("Autodesk.Revit.DB.FilterStringRule"): + { + switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterStringEquals"): + bhomTextEvaluator = TextComparisonType.NotEqual; + break; + case ("FilterStringBeginsWith"): + bhomTextEvaluator = TextComparisonType.NotStartsWith; + break; + case ("FilterStringEndsWith"): + bhomTextEvaluator = TextComparisonType.NotEndsWith; + break; + case ("FilterStringContains"): + bhomTextEvaluator = TextComparisonType.ContainsNot; + break; + default: + break; + } + oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); + bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; + } + // FilterDoubleRule + case ("Autodesk.Revit.DB.FilterDoubleRule"): + { + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; + } + // FilterIntegerRule + case ("Autodesk.Revit.DB.FilterIntegerRule"): + { + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; + } + // FilterElementIdRule + case ("Autodesk.Revit.DB.FilterElementIdRule"): + { + switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); + bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); + bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterElementIdRule; + } + default: + { return null; } + + } + } + +} } From 09840377838f1a833fcd24f4cc225d9246c3733b Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 20:43:11 +0100 Subject: [PATCH 036/131] Fix code for conversion of Revit Views into BHoM Views --- .../Convert/Revit/FromRevit/View.cs | 104 +++++++++++------- 1 file changed, 63 insertions(+), 41 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 0f14b9dfd..6f054e518 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -26,11 +26,15 @@ using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.Revit.Enums; using BH.oM.Revit.Views; +using BH.Revit.Engine.Core; using System; using System.Collections.Generic; using System.ComponentModel; +using System.Drawing; using System.Linq; +using System.Security.Policy; using System.Xml.Linq; using FilterRule = BH.oM.Revit.Elements.FilterRule; using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; @@ -57,42 +61,14 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, if (view != null) return view; - /* 1. Transfer NAME */ - view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name }; - - /* 2. Collect FILTER CATEGORY NAMES */ - List> categoriesNames=revitView.GetFilters() - .Select(elId => revitView.Document.GetElement(elId)) - .Cast() - .Select(pfe => pfe.GetCategories().ToList()) - .Select(catIdsList => catIdsList.Select(catId => revitView.Document.GetElement(catId).Name).ToList()) - .ToList>(); - - - List filtersWithOverrides; - List viewFilters; - List overrides; - - List filterRules = revitView.GetFilters() - .Select(elId => revitView.Document.GetElement(elId)) - .Cast() - .Select(epf => epf.GetRules()) - .ToDictionary(fvr => fvr.GetType(), - fvr => - { - Element param = revitView.Document.GetElement(fvr.GetRuleParameter()); - string paramName = param.Name; - string value = fvr.ToString(); - return new Array { paramName, value }; - }) - .ToList>() - .Select(kvp => new FilterRule { RuleType = FilterRuleType.BEGINSWITH, - ParameterName = kvp.Value[0], - Value = kvp.Value[1] }) - . - - - //TODO: here goes the convertion method + /*1. Transfer ViewFilters and corresponding OverrideGraphicSettings into ViewFilterWithOverrides Objects - via STREAMS */ + List filtersWithOverrides = revitView.GetFilters().ToDictionary + (elId => Convert.ViewFilterFromRevit((ParameterFilterElement)revitView.Document.GetElement(elId)), + elId => overrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() + .Select(kvp => new ViewFilterWithOverrides { Filter = kvp.Key, Overrides = kvp.Value }).ToList(); + + /*2. Create BHoM View Object with Name and FilterWithOverrides objects */ + view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name, FiltersWithOverrides = filtersWithOverrides }; //Set identifiers, parameters & custom data view.SetIdentifiers(revitView); @@ -104,10 +80,56 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, } /***************************************************/ - } -} - - - + private static OverrideGraphicSettings overrideGraphicSettingsFromRevit(this View element, Autodesk.Revit.DB.OverrideGraphicSettings revitOverrides) + { + // Initialize BHoM OverrideGraphicsSettings object + OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + + // Convert COLORS + overrideGraphicsSettings.LineColor = System.Drawing.Color.FromArgb(revitOverrides.CutLineColor.Red, revitOverrides.CutLineColor.Green, revitOverrides.CutLineColor.Blue); + overrideGraphicsSettings.CutColor = System.Drawing.Color.FromArgb(revitOverrides.CutBackgroundPatternColor.Red, revitOverrides.CutBackgroundPatternColor.Green, revitOverrides.CutBackgroundPatternColor.Blue); + overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); + + // Convert LINE PATTERNS + String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; + + if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DASH; } + else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DOT; } + else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.HIDDEN; } + else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.SOLID; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } + + + // Convert CUT PATTERNS + String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; + + if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } + else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } + else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } + else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.STEEL; } + else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.SOLID; } + else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.VERTICAL; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } + + + // Convert SURFACE PATTERNS + String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; + + if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } + else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } + else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } + else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.STEEL; } + else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.SOLID; } + else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.VERTICAL; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } + + return overrideGraphicsSettings; + } + } +} \ No newline at end of file From 69841b2c194d043cfc61f8a0c5eec0169c9ba39c Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 21:03:35 +0100 Subject: [PATCH 037/131] Make explicit distinction between Revit and BHoM View Class instances --- .../Convert/Revit/FromRevit/DraftingInstance.cs | 2 +- Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs | 2 +- Revit_Core_Engine/Convert/Revit/FromRevit/View.cs | 2 +- .../Convert/Revit/ToRevit/CurveElement.cs | 2 +- Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs | 10 +++++----- Revit_Core_Engine/Modify/SetLocation.cs | 2 +- Revit_Core_Engine/Modify/Update.cs | 1 - Revit_Core_Engine/Query/View.cs | 8 ++++---- Revit_oM/Elements/ViewFilter.cs | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs index 48dc7599a..94b46db32 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs @@ -53,7 +53,7 @@ public static DraftingInstance DraftingInstanceFromRevit(this FilledRegion fille if (draftingInstance != null) return draftingInstance; - View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View; + Autodesk.Revit.DB.View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as Autodesk.Revit.DB.View; if (view == null) return null; diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs index b9d53b2f7..7627a5388 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs @@ -55,7 +55,7 @@ public static IInstance InstanceFromRevit(this CurveElement curveElement, RevitS if (curveElement.ViewSpecific) { - View view = curveElement.Document.GetElement(curveElement.OwnerViewId) as View; + Autodesk.Revit.DB.View view = curveElement.Document.GetElement(curveElement.OwnerViewId) as Autodesk.Revit.DB.View; if (view == null) return null; diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 6f054e518..09a7a94f8 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -36,7 +36,7 @@ using System.Linq; using System.Security.Policy; using System.Xml.Linq; -using FilterRule = BH.oM.Revit.Elements.FilterRule; +using FilterRule = BH.oM.Revit.FilterRules.FilterRule; using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; using View = Autodesk.Revit.DB.View; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs index 11b0c63b8..8a36b24ab 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs @@ -128,7 +128,7 @@ public static CurveElement ToCurveElement(this DraftingInstance draftingInstance if (!BH.Engine.Geometry.Query.IsPlanar(curve as dynamic)) return null; - View view = Query.View(draftingInstance, document); + Autodesk.Revit.DB.View view = Query.View(draftingInstance, document); if (view == null) return null; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs index 7b5a7db83..27b467068 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs @@ -119,7 +119,7 @@ public static Element ToRevitElement(this DraftingInstance draftingInstance, Doc settings = settings.DefaultIfNull(); - View view = draftingInstance.View(document); + Autodesk.Revit.DB.View view = draftingInstance.View(document); if (view == null) return null; @@ -256,7 +256,7 @@ private static Element ToRevitElement(this ModelInstance modelInstance, FamilySy /**** Private Methods - Drafting Instances ****/ /***************************************************/ - private static Element IToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, View view, RevitSettings settings) + private static Element IToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, Autodesk.Revit.DB.View view, RevitSettings settings) { if (elementType == null) { @@ -269,7 +269,7 @@ private static Element IToRevitElement(this DraftingInstance draftingInstance, E /***************************************************/ - private static Element ToRevitElement(this DraftingInstance draftingInstance, FilledRegionType regionType, View view, RevitSettings settings) + private static Element ToRevitElement(this DraftingInstance draftingInstance, FilledRegionType regionType, Autodesk.Revit.DB.View view, RevitSettings settings) { ISurface location = draftingInstance.Location as ISurface; @@ -310,7 +310,7 @@ private static Element ToRevitElement(this DraftingInstance draftingInstance, Fi /***************************************************/ - private static Element ToRevitElement(this DraftingInstance draftingInstance, FamilySymbol familySymbol, View view, RevitSettings settings) + private static Element ToRevitElement(this DraftingInstance draftingInstance, FamilySymbol familySymbol, Autodesk.Revit.DB.View view, RevitSettings settings) { if (draftingInstance?.Location == null) return null; @@ -328,7 +328,7 @@ private static Element ToRevitElement(this DraftingInstance draftingInstance, Fa /**** Fallback Methods ****/ /***************************************************/ - private static Element ToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, View view, RevitSettings settings) + private static Element ToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, Autodesk.Revit.DB.View view, RevitSettings settings) { return null; } diff --git a/Revit_Core_Engine/Modify/SetLocation.cs b/Revit_Core_Engine/Modify/SetLocation.cs index 5684d07a4..b8e628eaa 100644 --- a/Revit_Core_Engine/Modify/SetLocation.cs +++ b/Revit_Core_Engine/Modify/SetLocation.cs @@ -546,7 +546,7 @@ private static bool SetLocation(this FamilyInstance element, BH.oM.Geometry.Poin typeof(Autodesk.Revit.DB.Family), typeof(ElementType), typeof(Material), - typeof(View) + typeof(Autodesk.Revit.DB.View) }; /***************************************************/ diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 465b2439f..01f290d5e 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -25,7 +25,6 @@ using BH.Engine.Adapters.Revit; using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Settings; -using BH.oM.Adapters.Revit.Views; using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; diff --git a/Revit_Core_Engine/Query/View.cs b/Revit_Core_Engine/Query/View.cs index d4eba8641..62e4a3d1d 100644 --- a/Revit_Core_Engine/Query/View.cs +++ b/Revit_Core_Engine/Query/View.cs @@ -39,15 +39,15 @@ public static partial class Query [Input("draftingInstance", "BHoM drafting instance to find owner Revit view for.")] [Input("document", "Revit document to parse in view search.")] [Output("view", "Revit view owning the input BHoM drafting instance.")] - public static View View(this DraftingInstance draftingInstance, Document document) + public static Autodesk.Revit.DB.View View(this DraftingInstance draftingInstance, Document document) { if (string.IsNullOrWhiteSpace(draftingInstance.ViewName)) return null; - List views = new FilteredElementCollector(document).OfClass(typeof(View)).Cast().ToList(); + List views = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.View)).Cast().ToList(); views.RemoveAll(x => x.IsTemplate || x is ViewSchedule || x is View3D || x is ViewSheet); - View view = null; + Autodesk.Revit.DB.View view = null; if (views != null && views.Count > 0) view = views.Find(x => x.Name == draftingInstance.ViewName); @@ -55,7 +55,7 @@ public static View View(this DraftingInstance draftingInstance, Document documen if (view != null) return view; - views = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast().ToList(); + views = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast().ToList(); string title = draftingInstance.ViewName; if (!title.StartsWith("Sheet: ")) title = string.Format("Sheet: {0}", title); diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index a33b5bb16..19d833939 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,5 +1,5 @@ using BH.oM.Base; -using BH.oM.Revit.Elements; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Revit.FilterRules; using System; using System.Collections.Generic; From 5fefeeda9d4790f52d1b33cd79fadcef41743e77 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Aug 2024 11:17:27 +0100 Subject: [PATCH 038/131] Add conversion of BHoM FilterRule to Revit FilterRule --- .../Revit/ToRevit/ParameterFilterElement.cs | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 7bb739841..c7e6096c8 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -33,6 +33,7 @@ using BH.oM.Revit.Enums; using BH.oM.Revit.FilterRules; using System; +using System.CodeDom; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -120,9 +121,32 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, oM.Revit.FilterRules.FilterCategoryRule filterCategoryRule) + public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document, oM.Revit.FilterRules.FilterRule filterRule) { - /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + + /* 1. CONVERT BHOM FILTERRULE INTO REVIT FILTERRULE */ + + // FilterCategoryRule + if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterCategoryRule)) + { return filterCategoryRuleToRevit(document, (oM.Revit.FilterRules.FilterCategoryRule)filterRule); } + // FilterMaterialRule + else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterMaterialRule)) + { return filterMaterialRuleToRevit(document, (oM.Revit.FilterRules.FilterMaterialRule)filterRule); } + // FilterLevelRule + else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterLevelRule)) + { return filterLevelRuleToRevit(document, (oM.Revit.FilterRules.FilterLevelRule)filterRule); } + // FilterValueRule + else if (filterRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) + { return filterValueRuleToRevit(document, (oM.Revit.FilterRules.FilterValueRule)filterRule); } + + return null; + + } + + + private static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, oM.Revit.FilterRules.FilterCategoryRule filterCategoryRule) + { + /* 1. INITIALIZE FILTERRULE */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ @@ -146,23 +170,22 @@ public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, FilterMaterialRule filterMaterialRule) + private static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; BuiltInParameter parameter = BuiltInParameter.MATERIAL_NAME; - + /* 2. CREATE THE FILTER RULE */ //ParameterValueProvider provider = new ParameterValueProvider(new ElementId(parameter)); revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); - return revitFilterRule; } /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, FilterLevelRule filterLevelRule) + private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, FilterLevelRule filterLevelRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -183,6 +206,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum } catch (Exception ex){ return null;} + /* 3. CREATE FILTERS RULE */ // Based on level's elevation and LevelComparisonType... @@ -223,7 +247,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { + private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; From 0c033a88cce3fca9a8f43fb444838c730f83e12a Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Aug 2024 16:58:49 +0100 Subject: [PATCH 039/131] Fix bug with extraction of revit Id of selected parameter --- .../Revit/ToRevit/ParameterFilterElement.cs | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index c7e6096c8..c667e8f50 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -72,7 +72,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(catName => catName.ToUpper().Replace(" ", "")) // Get the corresponding BuiltInCategories .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) - .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("ost_", "")) + .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_","")) .ToList(); return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]);}) // Get the ElementIds of the BuiltInCategories @@ -251,16 +251,9 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - ElementClassFilter paramFilter = new ElementClassFilter(typeof(Parameter)); - ElementClassFilter builtInParamFilter = new ElementClassFilter(typeof(BuiltInParameter)); - LogicalOrFilter logicalOrFilter = new LogicalOrFilter(paramFilter, builtInParamFilter); /* 2. GET THE ELEMENT ID OF THE PARAMETER OBJECT */ - ElementId parameterId = new FilteredElementCollector(document) - .WherePasses(logicalOrFilter) - .Where(par => par.Name.Equals(filterValueRule.ParameterName)) - .First() - .Id; + ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); /* 3. CREATE FILTER-RULE */ @@ -326,8 +319,10 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu // Based on FilterNumericValueRule... } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { + /* 1. Downcast to subclass */ oM.Revit.FilterRules.FilterNumericValueRule filterNumericValueRule = (oM.Revit.FilterRules.FilterNumericValueRule)filterValueRule; + /* 2. Convert Evaluator from Revit to BHoM */ switch (filterNumericValueRule.Evaluator) { case NumberComparisonType.Equal: @@ -375,9 +370,30 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu return revitFilterRule; } - } + private static ElementId GetParameterIdByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) + { + // Return the ElementId of the parameter + return param.Id; + } + } + + // If the parameter is not found, return InvalidElementId + return ElementId.InvalidElementId; + } + + } } From 23f5cae6f356e790e4f4d0753ee2fd73f7fbbe70 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 14:20:00 +0100 Subject: [PATCH 040/131] Fix code for conversion of filterRules from BHoM to Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement Adapt code to work better with the restraints of the Revit API Rule Factory Classes --- .../Revit/ToRevit/ParameterFilterElement.cs | 165 ++++++++++++++---- 1 file changed, 134 insertions(+), 31 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index c667e8f50..f295b142e 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -319,41 +319,144 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu // Based on FilterNumericValueRule... } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterNumericValueRule filterNumericValueRule = (oM.Revit.FilterRules.FilterNumericValueRule)filterValueRule; - /* 2. Convert Evaluator from Revit to BHoM */ - switch (filterNumericValueRule.Evaluator) + if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule)) { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId,(string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - default: - break; + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; + + /* 2. Convert input value to target data type */ + Double doubleValue=0.0; + Boolean boolParam=Double.TryParse(filterDoubleRule.Value,out doubleValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); + } + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterDoubleRule.Evaluator) + { + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, doubleValue, 0.01); + break; + default: + break; + } + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterIntegerRule)) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterIntegerRule filterIntegerRule = (oM.Revit.FilterRules.FilterIntegerRule)filterValueRule; + + /* 2. Convert input value to target data type */ + int intValue = 0; + Boolean boolParam = int.TryParse(filterIntegerRule.Value, out intValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); + } + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterIntegerRule.Evaluator) + { + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, intValue); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, intValue); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, intValue); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, intValue); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, intValue); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, intValue); + break; + default: + break; + } + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterElementIdRule)) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterElementIdRule filterElementIdRule = (oM.Revit.FilterRules.FilterElementIdRule)filterValueRule; + + /* 2. Convert input value to target data type */ + Boolean boolParam = int.TryParse(filterElementIdRule.Value, out int intValue); + ElementId elId = new ElementId(intValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); + } + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterElementIdRule.Evaluator) + { + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, elId); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, elId); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, elId); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, elId); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, elId); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, elId); + break; + default: + break; + } } - } + } // Based on ParameterValuePresenceRule... else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) { From d60bfe5405764323008096ddd9397bba781fa4f8 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 14:23:16 +0100 Subject: [PATCH 041/131] Add call to method for convertion of FilterLevelRule to Revit. --- .../Revit/ToRevit/ParameterFilterElement.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index f295b142e..c18fcfc26 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -94,18 +94,25 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))){ + if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))) + { filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) - .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))){ - filterRules = kvp.Value.Cast() - .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) - .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))){ + .ToList(); + } + + else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))) + { filterRules = kvp.Value.Cast() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) - .ToList();} + .ToList(); + } + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) + { + filterRules = kvp.Value.Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) + .ToList(); + } return filterRules; }) .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) .Cast() @@ -334,6 +341,9 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); } + ForgeTypeId units = new ForgeTypeId(); + Convert.ToSI(doubleValue,) + /* 3. Convert Evaluator from Revit to BHoM */ switch (filterDoubleRule.Evaluator) { From bedbda847119b7f6a8fd363894826007e3909325 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 17:28:32 +0100 Subject: [PATCH 042/131] Fix bug in creation of Revit Element Filter from BHoM FilterRules --- Revit_Adapter/Revit_Adapter.csproj | 2 +- .../Revit/ToRevit/ParameterFilterElement.cs | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Revit_Adapter/Revit_Adapter.csproj b/Revit_Adapter/Revit_Adapter.csproj index ff319b619..8e5c9555f 100644 --- a/Revit_Adapter/Revit_Adapter.csproj +++ b/Revit_Adapter/Revit_Adapter.csproj @@ -17,7 +17,7 @@ - + diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index c18fcfc26..a890b2e0e 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -86,37 +86,48 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules + ElementFilter elFilter=new LogicalAndFilter(filter.Rules .GroupBy(rule => rule.GetType()) .ToDictionary(grp => grp.Key, grp => grp.ToList()) .ToList() - .Select(kvp =>{ + .Select(kvp => + { List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))) + if (kvp.Key.Name == "FilterCategoryRule") { filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) .ToList(); } - - else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))) + else if (kvp.Key.Name == "FilterLevelRule") + { + filterRules = kvp.Value.Cast() + .Select(filterLevelRule => filterLevelRuleToRevit(document, filterLevelRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterMaterialRule") { filterRules = kvp.Value.Cast() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList(); } - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || + kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") { filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .ToList(); } - return filterRules; }) + return filterRules; + }) .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) .Cast() - .ToList())); + .ToList()); + + + revitFilter.SetElementFilter(elFilter); revitFilter.CopyParameters(filter, settings); @@ -341,9 +352,6 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); } - ForgeTypeId units = new ForgeTypeId(); - Convert.ToSI(doubleValue,) - /* 3. Convert Evaluator from Revit to BHoM */ switch (filterDoubleRule.Evaluator) { From a87ea3fda180277cf30af2e2ba7a34cbd8c6e890 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 18:54:54 +0100 Subject: [PATCH 043/131] Add changes to Level and Material FilterRule Conversion --- Revit_Adapter/Revit_Adapter.csproj | 2 +- .../Revit/ToRevit/ParameterFilterElement.cs | 42 ++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Revit_Adapter/Revit_Adapter.csproj b/Revit_Adapter/Revit_Adapter.csproj index 8e5c9555f..a49186511 100644 --- a/Revit_Adapter/Revit_Adapter.csproj +++ b/Revit_Adapter/Revit_Adapter.csproj @@ -17,7 +17,7 @@ - + diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a890b2e0e..4272ca201 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -192,11 +192,16 @@ private static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document d { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - BuiltInParameter parameter = BuiltInParameter.MATERIAL_NAME; + BuiltInParameter parameter = BuiltInParameter.STRUCTURAL_MATERIAL_PARAM; /* 2. CREATE THE FILTER RULE */ + //ParameterValueProvider provider = new ParameterValueProvider(new ElementId(parameter)); - revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); + //revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); + + FilteredElementCollector collector = new FilteredElementCollector(document); + Element mat=collector.OfClass(typeof(Material)).Where(material => material.Name == filterMaterialRule.MaterialName).First(); + revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), mat.Id); return revitFilterRule; } @@ -207,22 +212,27 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - BuiltInParameter elevationParam = BuiltInParameter.LEVEL_ELEV; - ElementId elevParamId=new ElementId(elevationParam); - Double levelElevation; + BuiltInParameter levParam = BuiltInParameter.LEVEL_PARAM; + ElementId levParamId=new ElementId(levParam); + ElementId levelId; /* 2. GET ELEVATION OF LEVEL CORRESPONDING TO INPUT LEVEL NAME */ // Via Streams and withing a Try-Catch statement to make sure the code is compact and if the level is not found, we prevent any error // being thrown when executing .First() while returning null instead. - try { - levelElevation=new FilteredElementCollector(document) + try + { + levelId = new FilteredElementCollector(document) .OfCategory(BuiltInCategory.OST_Levels) .Where(level => level.Name.ToUpper() == filterLevelRule.LevelName.ToUpper()) .Cast() - .Select(level => level.Elevation) + .Select(level => level.Id) .First(); - } catch (Exception ex){ - return null;} + } + catch (Exception ex) + { + return null; + } + /* 3. CREATE FILTERS RULE */ @@ -232,27 +242,27 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { case LevelComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(elevParamId,(double)levelElevation, 0.001); + .CreateEqualsRule(levParamId, filterLevelRule.LevelName,false); break; case LevelComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(elevParamId, (double)levelElevation, 0.001); + .CreateNotEqualsRule(levParamId, levelId); break; case LevelComparisonType.Above: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(elevParamId, (double)levelElevation, 0.001); + .CreateGreaterRule(levParamId, levelId); break; case LevelComparisonType.AtOrAbove: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(elevParamId, (double)levelElevation, 0.001); + .CreateGreaterOrEqualRule(levParamId, levelId); break; case LevelComparisonType.Below: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(elevParamId, (double)levelElevation, 0.001); + .CreateLessRule(levParamId, levelId); break; case LevelComparisonType.AtOrBelow: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(elevParamId, (double)levelElevation, 0.001); + .CreateLessOrEqualRule(levParamId, levelId); break; default: break; From 86d35ddb4b70249d12bb685f56ae57e23e30cd09 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 22:28:55 +0100 Subject: [PATCH 044/131] Fix bug with Push of View Filters based on Levels --- Revit_Adapter/Revit_Adapter.csproj | 2 +- .../Convert/Revit/ToRevit/ParameterFilterElement.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Revit_Adapter/Revit_Adapter.csproj b/Revit_Adapter/Revit_Adapter.csproj index a49186511..ff319b619 100644 --- a/Revit_Adapter/Revit_Adapter.csproj +++ b/Revit_Adapter/Revit_Adapter.csproj @@ -17,7 +17,7 @@ - + diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 4272ca201..a0f6963e7 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -212,7 +212,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - BuiltInParameter levParam = BuiltInParameter.LEVEL_PARAM; + BuiltInParameter levParam = BuiltInParameter.SCHEDULE_LEVEL_PARAM; ElementId levParamId=new ElementId(levParam); ElementId levelId; @@ -242,7 +242,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { case LevelComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(levParamId, filterLevelRule.LevelName,false); + .CreateEqualsRule(levParamId, levelId); break; case LevelComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory From 1580cd6679120bbc16dc700510660f0f39dc26f6 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 15:08:37 +0100 Subject: [PATCH 045/131] Fix bug dispatching different types of FilterRule --- .../Revit/ToRevit/ParameterFilterElement.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a0f6963e7..0d27cc778 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -113,8 +113,8 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList(); } - else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || - kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule"|| + kvp.Key.Name=="FilterIntegerRule"||kvp.Key.Name=="FilterElementIdRule") { filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) @@ -286,7 +286,8 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu /* 3. CREATE FILTER-RULE */ // Based on FilterStringRule... - if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) + if (filterValueRule.GetType()==typeof(FilterStringRule)|| + filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; @@ -345,10 +346,11 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu } // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) + } else if (filterValueRule.GetType()==typeof(oM.Revit.FilterRules.FilterNumericValueRule)|| + filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { - if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule)) + if ((filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule))) { /* 1. Downcast to subclass */ oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; @@ -486,7 +488,8 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu } // Based on ParameterValuePresenceRule... - else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) + else if (filterValueRule.GetType()== typeof(oM.Revit.FilterRules.ParameterValuePresenceRule)|| + filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) { oM.Revit.FilterRules.ParameterValuePresenceRule parameterValuePresenceRule = (oM.Revit.FilterRules.ParameterValuePresenceRule)filterValueRule; From 07ab5b5126687e1171f3f5308e185ab1c2d1c049 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 15:08:46 +0100 Subject: [PATCH 046/131] Turn FilterNumericValueRule into an abstract class In this way its corresponding Grasshopper Component will disappear, thus forcing the user to use only its specific sub-components: DoubleRule, IntegerRule and ElementIdRule. --- Revit_oM/FilterRules/FilterNumericValueRule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Revit_oM/FilterRules/FilterNumericValueRule.cs b/Revit_oM/FilterRules/FilterNumericValueRule.cs index 416e19b62..3f9d3d27e 100644 --- a/Revit_oM/FilterRules/FilterNumericValueRule.cs +++ b/Revit_oM/FilterRules/FilterNumericValueRule.cs @@ -7,7 +7,7 @@ namespace BH.oM.Revit.FilterRules { - public class FilterNumericValueRule : FilterValueRule + public abstract class FilterNumericValueRule : FilterValueRule { public virtual NumberComparisonType Evaluator { get; set; } From 1fb229aa97176312d4edeed0beee224e3e10ed3e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 18:30:11 +0100 Subject: [PATCH 047/131] Fix bug related to incorrect extraction of Categories from the model. Rather than using a FilteredElementCollector on which to call the .OfClass() method, better to get all the Category objects getting the Categories data structure from the Revit model and then iterate on its elements to extract all the categories and transfer them into a list. --- .../Revit/ToRevit/ParameterFilterElement.cs | 75 +++++++++++++------ 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 0d27cc778..15cec5445 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -86,7 +86,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - ElementFilter elFilter=new LogicalAndFilter(filter.Rules + ElementFilter elFilter = new LogicalAndFilter(filter.Rules .GroupBy(rule => rule.GetType()) .ToDictionary(grp => grp.Key, grp => grp.ToList()) .ToList() @@ -113,8 +113,8 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList(); } - else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule"|| - kvp.Key.Name=="FilterIntegerRule"||kvp.Key.Name=="FilterElementIdRule") + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || + kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") { filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) @@ -167,10 +167,12 @@ private static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document d /* 1. INITIALIZE FILTERRULE */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; + /* 2. EXTRACT CATEGORIES */ + List categories = new List(); + foreach (Autodesk.Revit.DB.Category cat in document.Settings.Categories) { categories.Add(cat);} + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ - List categoryIds = new FilteredElementCollector(document) - // Get all the Categories (INTERMEDIATE OPERATION) - .OfClass(typeof(Autodesk.Revit.DB.Category)) + List categoryIds = categories // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) // Cast down to Category Class Instances (INTERMEDIATE OPERATION) @@ -280,8 +282,9 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - /* 2. GET THE ELEMENT ID OF THE PARAMETER OBJECT */ + /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); + Parameter parameter = GetParameterByName(document, filterValueRule.ParameterName); /* 3. CREATE FILTER-RULE */ @@ -364,32 +367,35 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); } - /* 3. Convert Evaluator from Revit to BHoM */ + /* 3. Convert units of input value to internal units */ + double convertedValue =UnitUtils.ConvertToInternalUnits(doubleValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ switch (filterDoubleRule.Evaluator) { case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, doubleValue, 0.01); + .CreateEqualsRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, doubleValue, 0.01); + .CreateNotEqualsRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, doubleValue, 0.01); + .CreateGreaterRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, doubleValue, 0.01); + .CreateGreaterOrEqualRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, doubleValue, 0.01); + .CreateLessRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, doubleValue, 0.01); + .CreateLessOrEqualRule(parameterId, convertedValue, 0.01); break; default: break; @@ -409,32 +415,35 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); } - /* 3. Convert Evaluator from Revit to BHoM */ + /* 3. Convert units of input value to internal units */ + int convertedValue = (int)UnitUtils.ConvertToInternalUnits((Double)intValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ switch (filterIntegerRule.Evaluator) { case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, intValue); + .CreateEqualsRule(parameterId, convertedValue); break; case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, intValue); + .CreateNotEqualsRule(parameterId, convertedValue); break; case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, intValue); + .CreateGreaterRule(parameterId, convertedValue); break; case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, intValue); + .CreateGreaterOrEqualRule(parameterId, convertedValue); break; case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, intValue); + .CreateLessRule(parameterId, convertedValue); break; case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, intValue); + .CreateLessOrEqualRule(parameterId, convertedValue); break; default: break; @@ -526,7 +535,29 @@ private static ElementId GetParameterIdByName(Document doc, string parameterName // If the parameter is not found, return InvalidElementId return ElementId.InvalidElementId; } - + + + private static Parameter GetParameterByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) + { + // Return the ElementId of the parameter + return param; + } + } + + // If the parameter is not found, return InvalidElementId + return null; + } } } From 06532f63fc8f9cbd581e5412934b394a47da255e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 19:33:37 +0100 Subject: [PATCH 048/131] Add feature to create ViewFilters with No Rules. --- .../Revit/ToRevit/ParameterFilterElement.cs | 86 ++++++++++--------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 15cec5445..ac7711a99 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -79,56 +79,58 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(builtInCat => new ElementId(builtInCat)) // Turn the Stream into a List of ElementIds .ToList(); - + /* 1.2 Create the ParameterFilterElement in the current Revit Document */ revitFilter = ParameterFilterElement.Create(document, filter.Name, categoryIdsList); + // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - ElementFilter elFilter = new LogicalAndFilter(filter.Rules - .GroupBy(rule => rule.GetType()) - .ToDictionary(grp => grp.Key, grp => grp.ToList()) - .ToList() - .Select(kvp => - { - - List filterRules = new List(); - - if (kvp.Key.Name == "FilterCategoryRule") - { - filterRules = kvp.Value.Cast() - .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) - .ToList(); - } - else if (kvp.Key.Name == "FilterLevelRule") - { - filterRules = kvp.Value.Cast() - .Select(filterLevelRule => filterLevelRuleToRevit(document, filterLevelRule)) - .ToList(); - } - else if (kvp.Key.Name == "FilterMaterialRule") - { - filterRules = kvp.Value.Cast() - .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) - .ToList(); - } - else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || - kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") + if (filter.Rules.Count != 0) + { + ElementFilter elFilter = new LogicalAndFilter(filter.Rules + .GroupBy(rule => rule.GetType()) + .ToDictionary(grp => grp.Key, grp => grp.ToList()) + .ToList() + .Select(kvp => { - filterRules = kvp.Value.Cast() - .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) - .ToList(); - } - return filterRules; - }) - .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) - .Cast() - .ToList()); - - - revitFilter.SetElementFilter(elFilter); + List filterRules = new List(); + + if (kvp.Key.Name == "FilterCategoryRule") + { + filterRules = kvp.Value.Cast() + .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterLevelRule") + { + filterRules = kvp.Value.Cast() + .Select(filterLevelRule => filterLevelRuleToRevit(document, filterLevelRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterMaterialRule") + { + filterRules = kvp.Value.Cast() + .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || + kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") + { + filterRules = kvp.Value.Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) + .ToList(); + } + return filterRules; + }) + .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) + .Cast() + .ToList()); + + revitFilter.SetElementFilter(elFilter); + } revitFilter.CopyParameters(filter, settings); refObjects.AddOrReplace(filter, revitFilter); From 55f414c18cc22de534be1f1cf9a6276240a58305 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 10:52:10 +0100 Subject: [PATCH 049/131] Fix code for extraction of categories and filter rules from Revit when pulling --- .../Convert/Revit/FromRevit/ViewFilter.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 58e37f9d1..4158ee488 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -33,6 +33,7 @@ using System.CodeDom; using System; using Autodesk.Revit.DB.Architecture; +using Autodesk.Revit.Creation; namespace BH.Revit.Engine.Core { @@ -59,17 +60,23 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; /* 2. Transfer List of CATEGORY NAMES */ - viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); + List categories = new List(); + foreach (Autodesk.Revit.DB.Category cat in revitViewFilter.Document.Settings.Categories) { categories.Add(cat); } + viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat=>cat.Id==catId).First().Name).ToList(); /* 3. Transfer List of FILTER RULES */ - //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS - List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) - .ToList(); - //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) - List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); - //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects - viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); + // If the Filter is assigned with any rules..... + if (((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().Count !=0) + { + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS + List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) + .ToList(); + //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) + List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); + //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects + viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); + } //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); From 13a9772bc6761e70f2cedcc4a7111ae11a2a78b7 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 16:13:39 +0100 Subject: [PATCH 050/131] Add GetParameterById Utility function and minor updates to parameter collection streams --- .../Convert/Revit/FromRevit/ViewFilter.cs | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 4158ee488..bf0bd8a0f 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -66,14 +66,17 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 3. Transfer List of FILTER RULES */ // If the Filter is assigned with any rules..... - if (((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().Count !=0) + if (revitViewFilter.GetElementFilter()!=null) { - //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS - List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) - .ToList(); + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS + //List parameterNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() + Dictionary filterAndParNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() + .Select(filter => ((ElementParameterFilter)filter).GetRules()) + .SelectMany(list => list) + .ToDictionary(rule => rule, rule => (GetParameterById(revitViewFilter.Document, rule.GetRuleParameter()).Definition.Name.ToString())); + //.ToList(); //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) - List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); + List revitFilterRules = (filterAndParNames.Keys.ToList()); //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); } @@ -97,25 +100,25 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par NumberComparisonType bhomNumericEvaluator = 0; // FILTER STRING RULE - if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + if (revitRule.GetType()== typeof(Autodesk.Revit.DB.FilterStringRule)) { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator); } // FILTER DOUBLE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + else if (revitRule.GetType()==typeof(Autodesk.Revit.DB.FilterDoubleRule)) { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } // FILTER INTEGER RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterIntegerRule)) { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } // FILTER ELEMENTID RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterElementIdRule)) { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } // FILTER CATEGORY RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterCategoryRule)) { return (oM.Revit.FilterRules.FilterRule)FilterCategoryRuleFromRevit(revitViewFilter, revitRule); } // FILTER PARAMETER VALUE PRESENCE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.ParameterValuePresenceRule)) { return (oM.Revit.FilterRules.FilterRule)ParameterValuePresenceRuleFromRevit(revitViewFilter, revitRule); } // FILTER INVERSE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterInverseRule)) { return FilterInverseRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator, bhomNumericEvaluator); } return null; }).ToList(); @@ -485,7 +488,31 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P } } -} + + /* UTILITY METHODS */ + + private static Parameter GetParameterById(Autodesk.Revit.DB.Document doc, ElementId parameterId) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by its own Id + List matchingParams=element.Parameters().Where(prm => prm.Id == parameterId).ToList(); + + if (matchingParams.Count!=0) + {return matchingParams.First();} + + } + + // If the parameter is not found, return InvalidElementId + return null; + } + + } } From f6cdfc046425df0a5915954dd06f28f92f255380 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 18:57:32 +0100 Subject: [PATCH 051/131] Add use of utility function GetParameterById where required to get parameter objects --- .../Convert/Revit/FromRevit/ViewFilter.cs | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index bf0bd8a0f..498a24fe4 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -135,7 +135,7 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t // Downcast Revit FilterRule obj to Revit FilterStringRule obj Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; // Extract name and value assigned to the parameter of the FilterStringRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document, revitFilterStringRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterStringRule.RuleString; // Get the RuleEvaluator of the FilterStringRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -192,7 +192,7 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t // Downcast Revit FilterRule obj to Revit FilterDoubleRule obj Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; // Extract name and value assigned to the parameter of the FilterDoubleRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document,revitFilterDoubleRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterDoubleRule.RuleValue.ToString(); // Get the RuleEvaluator of the FilterDoubleRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -240,7 +240,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit // Downcast Revit FilterRule obj to Revit FilterIntegerRule obj Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; // Extract name and value assigned to the parameter of the FilterIntegerRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterIntegerRule.RuleValue.ToString(); // Get the RuleEvaluator of the FilterIntegerRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -288,7 +288,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR // Downcast Revit FilterRule obj to Revit FilterElementIdRule obj Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document, revitFilterElemIdRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterElemIdRule.RuleValue.ToString(); // Get the RuleEvaluator of the FilterElementIdRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -380,23 +380,23 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterStringEquals"): + case ("Autodesk.Revit.DB.FilterStringEquals"): bhomTextEvaluator = TextComparisonType.NotEqual; break; - case ("FilterStringBeginsWith"): + case ("Autodesk.Revit.DB.FilterStringBeginsWith"): bhomTextEvaluator = TextComparisonType.NotStartsWith; break; - case ("FilterStringEndsWith"): + case ("Autodesk.Revit.DB.FilterStringEndsWith"): bhomTextEvaluator = TextComparisonType.NotEndsWith; break; - case ("FilterStringContains"): + case ("Autodesk.Revit.DB.FilterStringContains"): bhomTextEvaluator = TextComparisonType.ContainsNot; break; default: break; } oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); - bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; bhomFilterStringRule.Evaluator = bhomTextEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; @@ -406,24 +406,24 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): + case ("Autodesk.Revit.DB.FilterNumericEquals"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericGreater"): + case ("Autodesk.Revit.DB.FilterNumericGreater"): bhomNumericEvaluator = NumberComparisonType.Less; break; - case ("FilterNumericGreaterOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericLess"): + case ("Autodesk.Revit.DB.FilterNumericLess"): bhomNumericEvaluator = NumberComparisonType.Greater; break; - case ("FilterNumericLessOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterDoubleRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; @@ -433,24 +433,24 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): + case ("Autodesk.Revit.DB.FilterNumericEquals"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericGreater"): + case ("Autodesk.Revit.DB.FilterNumericGreater"): bhomNumericEvaluator = NumberComparisonType.Less; break; - case ("FilterNumericGreaterOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericLess"): + case ("Autodesk.Revit.DB.FilterNumericLess"): bhomNumericEvaluator = NumberComparisonType.Greater; break; - case ("FilterNumericLessOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterIntegerRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; @@ -460,24 +460,24 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): + case ("Autodesk.Revit.DB.FilterNumericEquals"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericGreater"): + case ("Autodesk.Revit.DB.FilterNumericGreater"): bhomNumericEvaluator = NumberComparisonType.Less; break; - case ("FilterNumericGreaterOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericLess"): + case ("Autodesk.Revit.DB.FilterNumericLess"): bhomNumericEvaluator = NumberComparisonType.Greater; break; - case ("FilterNumericLessOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); - bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterElementIdRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterElementIdRule; From fc1f66488b73a6f2921dd39b244fa63612ea06de Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 19:21:24 +0100 Subject: [PATCH 052/131] Add conversion of double internal units when pulling filter parameter values --- Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 498a24fe4..5f7b56c28 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -193,7 +193,8 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; // Extract name and value assigned to the parameter of the FilterDoubleRule obj string paramName = GetParameterById(revitViewFilter.Document,revitFilterDoubleRule.GetRuleParameter()).Definition.Name; - string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitFilterDoubleRule.GetRuleParameter()).GetUnitTypeId(); + string paramValue = UnitUtils.ConvertFromInternalUnits(revitFilterDoubleRule.RuleValue,paramTypeId).ToString(); // Get the RuleEvaluator of the FilterDoubleRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); @@ -241,7 +242,8 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; // Extract name and value assigned to the parameter of the FilterIntegerRule obj string paramName = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).Definition.Name; - string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).GetUnitTypeId(); + string paramValue = UnitUtils.ConvertFromInternalUnits(revitFilterIntegerRule.RuleValue, paramTypeId).ToString(); // Get the RuleEvaluator of the FilterIntegerRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); @@ -289,7 +291,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj string paramName = GetParameterById(revitViewFilter.Document, revitFilterElemIdRule.GetRuleParameter()).Definition.Name; - string paramValue = revitFilterElemIdRule.RuleValue.ToString(); + string paramValue = revitViewFilter.Document.GetElement(revitFilterElemIdRule.RuleValue).Name.ToString(); // Get the RuleEvaluator of the FilterElementIdRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); From 8ad280131b7bf7f55978fc1345ba368b67a1fd26 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 14:51:09 +0100 Subject: [PATCH 053/131] Add Update Method for Autodesk Revit View3D Class The View3D Class is a subclass of the View Class. To let the BHoM run the Update method on the View3D class, we need to specify an overloaded version of the Update Method taking a View3D class instance rather than a View class instance as input. --- Revit_Core_Engine/Modify/Update.cs | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 01f290d5e..0b58eaa10 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -302,6 +302,60 @@ public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View return true; } + + [Description("Updates the existing Revit View based on the given BHoM View.")] + [Input("element", "Revit View instance to be updated.")] + [Input("bHoMObject", "BHoM View, based on which the Revit View will be updated.")] + [Input("settings", "Revit adapter settings to be used while performing the action.")] + [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] + [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] + public static bool Update(this View3D element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + { + /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ + + // Via Streams... + bHoMObject.FiltersWithOverrides + // 1. Turn Filters and Overrides into Keys and Values of a Dictionary + .ToDictionary(x => x.Filter, x => x.Overrides) + // 2. Turn the Dictionary into a List of KeyValue Pairs (to allow use of ForEach() + .ToList>() + // 3. Assign Filters to View and Set their Overrides + .ForEach(kvp => { + ParameterFilterElement pfe = kvp.Key.ToRevitParameterFilterElement(element.Document, settings); + // 3.1 Add ViewFilter to the View + element.AddFilter(pfe.Id); + // 3.2 Get the Revit FillPatternElement Objects for CutPattern and SurfacePattern + FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); + FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); + // 3.3 Create the OverrideGraphics by Properties + OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); + Color revitCutColor = new Color(kvp.Value.CutColor.R, kvp.Value.CutColor.G, kvp.Value.CutColor.B); + Color revitSurfaceColor = new Color(kvp.Value.SurfaceColor.R, kvp.Value.SurfaceColor.G, kvp.Value.SurfaceColor.B); + overrideGraphicsSettings.SetCutLineColor(revitLineColor); + overrideGraphicsSettings.SetProjectionLineColor(revitLineColor); + overrideGraphicsSettings.SetCutBackgroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutBackgroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetCutForegroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutForegroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetSurfaceBackgroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceBackgroundPatternColor(revitSurfaceColor); + overrideGraphicsSettings.SetSurfaceForegroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceForegroundPatternColor(revitSurfaceColor); + // 3.4 Assign Overrides to the ViewFilter + element.SetFilterOverrides(pfe.Id, overrideGraphicsSettings); + }); + + element.CopyParameters(bHoMObject, settings); + return true; + } + /***************************************************/ [Description("Updates the existing Revit ParameterFilterElement based on the given BHoM ViewFilter.")] From 463807eee1e6db4474bd0fe2e255a1e9f6f93fa0 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 14:57:14 +0100 Subject: [PATCH 054/131] Turn Update Methods for View and View3D into a single method using Generic Type Since View3D is a subclass of View in the Revit API, we can make the Update method work on a generic type T, specifying that it must be extending the revit api superclass View. --- Revit_Core_Engine/Modify/Update.cs | 56 +----------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 0b58eaa10..62b1062ee 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -257,7 +257,7 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re [Input("settings", "Revit adapter settings to be used while performing the action.")] [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] - public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) where T:Autodesk.Revit.DB.View { /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ @@ -302,60 +302,6 @@ public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View return true; } - - [Description("Updates the existing Revit View based on the given BHoM View.")] - [Input("element", "Revit View instance to be updated.")] - [Input("bHoMObject", "BHoM View, based on which the Revit View will be updated.")] - [Input("settings", "Revit adapter settings to be used while performing the action.")] - [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] - [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] - public static bool Update(this View3D element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) - { - /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ - - // Via Streams... - bHoMObject.FiltersWithOverrides - // 1. Turn Filters and Overrides into Keys and Values of a Dictionary - .ToDictionary(x => x.Filter, x => x.Overrides) - // 2. Turn the Dictionary into a List of KeyValue Pairs (to allow use of ForEach() - .ToList>() - // 3. Assign Filters to View and Set their Overrides - .ForEach(kvp => { - ParameterFilterElement pfe = kvp.Key.ToRevitParameterFilterElement(element.Document, settings); - // 3.1 Add ViewFilter to the View - element.AddFilter(pfe.Id); - // 3.2 Get the Revit FillPatternElement Objects for CutPattern and SurfacePattern - FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) - .OfClass(typeof(FillPatternElement)) - .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); - FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) - .OfClass(typeof(FillPatternElement)) - .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); - // 3.3 Create the OverrideGraphics by Properties - OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); - Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); - Color revitCutColor = new Color(kvp.Value.CutColor.R, kvp.Value.CutColor.G, kvp.Value.CutColor.B); - Color revitSurfaceColor = new Color(kvp.Value.SurfaceColor.R, kvp.Value.SurfaceColor.G, kvp.Value.SurfaceColor.B); - overrideGraphicsSettings.SetCutLineColor(revitLineColor); - overrideGraphicsSettings.SetProjectionLineColor(revitLineColor); - overrideGraphicsSettings.SetCutBackgroundPatternId(revitCutPattern.Id); - overrideGraphicsSettings.SetCutBackgroundPatternColor(revitCutColor); - overrideGraphicsSettings.SetCutForegroundPatternId(revitCutPattern.Id); - overrideGraphicsSettings.SetCutForegroundPatternColor(revitCutColor); - overrideGraphicsSettings.SetSurfaceBackgroundPatternId(revitSurfacePattern.Id); - overrideGraphicsSettings.SetSurfaceBackgroundPatternColor(revitSurfaceColor); - overrideGraphicsSettings.SetSurfaceForegroundPatternId(revitSurfacePattern.Id); - overrideGraphicsSettings.SetSurfaceForegroundPatternColor(revitSurfaceColor); - // 3.4 Assign Overrides to the ViewFilter - element.SetFilterOverrides(pfe.Id, overrideGraphicsSettings); - }); - - element.CopyParameters(bHoMObject, settings); - return true; - } - /***************************************************/ [Description("Updates the existing Revit ParameterFilterElement based on the given BHoM ViewFilter.")] From 42cd96d69ccf7c9446e3c8bcb0771c655c17151d Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 15:25:50 +0100 Subject: [PATCH 055/131] Fix Fill and Line Pattern Name search turning letter case to Upper --- Revit_Core_Engine/Modify/Update.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 62b1062ee..6641c39d1 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -275,11 +275,11 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().ToUpper())); FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().ToUpper())); // 3.3 Create the OverrideGraphics by Properties OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); From 9d17a6efa945d7dfa4b2fa9a740ed90931e895a9 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 16:34:06 +0100 Subject: [PATCH 056/131] Fix bug text comparison between Cut and Surface Patterns --- Revit_Core_Engine/Modify/Update.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 6641c39d1..79d25de25 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -275,11 +275,11 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().ToUpper())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().Replace("_"," ").ToUpper())); FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().ToUpper())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().Replace("_", " ").ToUpper())); // 3.3 Create the OverrideGraphics by Properties OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); From f7f8cdc54ff3394c0f145ed55fcfcaca2c95fac4 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Tue, 3 Sep 2024 19:36:31 +0200 Subject: [PATCH 057/131] event suppression added --- Revit_Core_Engine/Query/SpecFromName.cs | 4 ++++ Revit_Core_Engine/Query/UnitFromName.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Revit_Core_Engine/Query/SpecFromName.cs b/Revit_Core_Engine/Query/SpecFromName.cs index c173a9ba9..c0047fcfb 100644 --- a/Revit_Core_Engine/Query/SpecFromName.cs +++ b/Revit_Core_Engine/Query/SpecFromName.cs @@ -93,6 +93,8 @@ private static void CollectSpecs() #else private static void CollectSpecs() { + BH.Engine.Base.Compute.StartSuppressRecordingEvents(true, true, true); + m_SpecsWithNames = new Dictionary(); foreach (PropertyInfo info in typeof(SpecTypeId).GetProperties()) { @@ -100,6 +102,8 @@ private static void CollectSpecs() if (unitType != null) m_SpecsWithNames.Add(info.Name, unitType); } + + BH.Engine.Base.Compute.StopSuppressRecordingEvents(); } diff --git a/Revit_Core_Engine/Query/UnitFromName.cs b/Revit_Core_Engine/Query/UnitFromName.cs index c14ba690e..b8832c33c 100644 --- a/Revit_Core_Engine/Query/UnitFromName.cs +++ b/Revit_Core_Engine/Query/UnitFromName.cs @@ -93,6 +93,8 @@ private static void CollectUnits() private static void CollectUnits() { + BH.Engine.Base.Compute.StartSuppressRecordingEvents(false, true, true); + m_UnitsWithNames = new Dictionary(); foreach (PropertyInfo info in typeof(UnitTypeId).GetProperties()) { @@ -100,6 +102,8 @@ private static void CollectUnits() if (unitType != null) m_UnitsWithNames.Add(info.Name, unitType); } + + BH.Engine.Base.Compute.StopSuppressRecordingEvents(); } From 0edce3f1ae6e8e771ab0fbf7a5064903735d9652 Mon Sep 17 00:00:00 2001 From: BHoMBot Date: Fri, 20 Sep 2024 13:25:27 +0200 Subject: [PATCH 058/131] Update assembly file version to 8.0.0.0 and AssemblyVersion to 8.0.0.0 --- Revit_Adapter/Revit_Adapter.csproj | 4 ++-- Revit_Core_Adapter/Revit_Core_Adapter.csproj | 4 ++-- Revit_Core_Engine/Revit_Core_Engine.csproj | 4 ++-- Revit_Engine/Revit_Engine.csproj | 4 ++-- Revit_oM/Revit_oM.csproj | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Revit_Adapter/Revit_Adapter.csproj b/Revit_Adapter/Revit_Adapter.csproj index b93f56501..0f801e86b 100644 --- a/Revit_Adapter/Revit_Adapter.csproj +++ b/Revit_Adapter/Revit_Adapter.csproj @@ -2,13 +2,13 @@ net472 - 7.0.0.0 + 8.0.0.0 https://github.com/BHoM/Revit_Toolkit 6.0.0 BHoM Copyright © https://github.com/BHoM BH.Adapter.Revit - 7.3.0.0 + 8.0.0.0 diff --git a/Revit_Core_Adapter/Revit_Core_Adapter.csproj b/Revit_Core_Adapter/Revit_Core_Adapter.csproj index 2aab41917..81052c5a4 100644 --- a/Revit_Core_Adapter/Revit_Core_Adapter.csproj +++ b/Revit_Core_Adapter/Revit_Core_Adapter.csproj @@ -1,13 +1,13 @@ - 7.0.0.0 + 8.0.0.0 https://github.com/BHoM/Revit_Toolkit 6.0.0 BHoM Copyright © https://github.com/BHoM BH.Revit.Adapter.Core - 7.3.0.0 + 8.0.0.0 diff --git a/Revit_Core_Engine/Revit_Core_Engine.csproj b/Revit_Core_Engine/Revit_Core_Engine.csproj index 25f0e1092..1b92b3c47 100644 --- a/Revit_Core_Engine/Revit_Core_Engine.csproj +++ b/Revit_Core_Engine/Revit_Core_Engine.csproj @@ -1,12 +1,12 @@ - 7.0.0.0 + 8.0.0.0 https://github.com/BHoM/Revit_Toolkit 6.0.0 BHoM Copyright © https://github.com/BHoM BH.Revit.Engine.Core - 7.3.0.0 + 8.0.0.0 diff --git a/Revit_Engine/Revit_Engine.csproj b/Revit_Engine/Revit_Engine.csproj index e53e3d8f1..e7266b697 100644 --- a/Revit_Engine/Revit_Engine.csproj +++ b/Revit_Engine/Revit_Engine.csproj @@ -2,13 +2,13 @@ net472 - 7.0.0.0 + 8.0.0.0 https://github.com/BHoM/Revit_Toolkit 6.0.0 BHoM Copyright © https://github.com/BHoM BH.Engine.Revit - 7.3.0.0 + 8.0.0.0 diff --git a/Revit_oM/Revit_oM.csproj b/Revit_oM/Revit_oM.csproj index a653dc062..842f23cba 100644 --- a/Revit_oM/Revit_oM.csproj +++ b/Revit_oM/Revit_oM.csproj @@ -2,13 +2,13 @@ net472 - 7.0.0.0 + 8.0.0.0 https://github.com/BHoM/Revit_Toolkit 6.0.0 BHoM Copyright © https://github.com/BHoM BH.oM.Revit - 7.3.0.0 + 8.0.0.0 From 5a06ccfd0ffb7ca98cbf5b8817c3c1a6c1927b65 Mon Sep 17 00:00:00 2001 From: BHoMBot Date: Fri, 20 Sep 2024 13:25:27 +0200 Subject: [PATCH 059/131] Remove previous version attributes for 8.0 --- Revit_Core_Engine/Query/LinkedElementsInView.cs | 1 - Revit_Core_Engine/Query/SpecFromName.cs | 1 - Revit_Core_Engine/Query/SpecName.cs | 3 --- Revit_Core_Engine/Query/ViewSolid.cs | 3 +-- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Revit_Core_Engine/Query/LinkedElementsInView.cs b/Revit_Core_Engine/Query/LinkedElementsInView.cs index 25e02ca8a..4ff682b52 100644 --- a/Revit_Core_Engine/Query/LinkedElementsInView.cs +++ b/Revit_Core_Engine/Query/LinkedElementsInView.cs @@ -33,7 +33,6 @@ public static partial class Query /**** Public methods ****/ /***************************************************/ - [PreviousVersion("7.3", "BH.Revit.Engine.Core.Query.LinkedElementsInView(Autodesk.Revit.DB.ViewPlan, Autodesk.Revit.DB.RevitLinkInstance, System.Collections.Generic.List)")] [Description("Return elements from the revit link instance located in the view scope (including hidden elements)")] [Input("view", "View to get visible elements from. The view needs to belong to the host document.")] [Input("linkInstance", "Revit link instance to get the elements from.")] diff --git a/Revit_Core_Engine/Query/SpecFromName.cs b/Revit_Core_Engine/Query/SpecFromName.cs index c0047fcfb..97733cb43 100644 --- a/Revit_Core_Engine/Query/SpecFromName.cs +++ b/Revit_Core_Engine/Query/SpecFromName.cs @@ -34,7 +34,6 @@ public static partial class Query /**** Public methods ****/ /***************************************************/ - [PreviousVersion("7.3", "BH.Revit.Engine.Core.Query.UnitTypeByPropertyName(System.String)")] [Description("Returns Revit spec object (enum for Revit up to 2020 or ForgeTypeId for later versions) based on SpecTypeId property name that represents it.")] [Input("name", "Name of SpecTypeId property to be queried for the correspondent spec.")] [Output("spec", "Spec object under the input SpecTypeId property name.")] diff --git a/Revit_Core_Engine/Query/SpecName.cs b/Revit_Core_Engine/Query/SpecName.cs index 94bd92327..16781859b 100644 --- a/Revit_Core_Engine/Query/SpecName.cs +++ b/Revit_Core_Engine/Query/SpecName.cs @@ -33,8 +33,6 @@ public static partial class Query /**** Public methods ****/ /***************************************************/ - [PreviousVersion("7.3", "BH.Revit.Engine.Core.Query.UnitTypePropertyName(Autodesk.Revit.DB.UnitType)")] - [PreviousVersion("7.3", "BH.Revit.Engine.Core.Query.UnitTypePropertyName(Autodesk.Revit.DB.ForgeTypeId)")] [Description("Returns name of SpecTypeId property that contains a given Revit spec object (enum for Revit up to 2020 or ForgeTypeId for later versions).")] [Input("spec", "Spec object to be queried for the correspondent SpecTypeId property name.")] [Output("name", "Name of SpecTypeId property that contains the input spec object.")] @@ -55,7 +53,6 @@ public static string SpecName(this ForgeTypeId spec) /***************************************************/ - [PreviousVersion("7.3", "BH.Revit.Engine.Core.Query.UnitTypePropertyName(Autodesk.Revit.DB.Parameter)")] [Description("Returns name of SpecTypeId property that contains given Revit parameter's spec object (enum for Revit up to 2020 or ForgeTypeId for later versions).")] [Input("parameter", "Parameter to be queried for the correspondent SpecTypeId property name.")] [Output("name", "Name of SpecTypeId property that contains the spec object correspondent to the input parameter.")] diff --git a/Revit_Core_Engine/Query/ViewSolid.cs b/Revit_Core_Engine/Query/ViewSolid.cs index f8393e31a..335c2d3ef 100644 --- a/Revit_Core_Engine/Query/ViewSolid.cs +++ b/Revit_Core_Engine/Query/ViewSolid.cs @@ -1,4 +1,4 @@ -/* +/* * This file is part of the Buildings and Habitats object Model (BHoM) * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. * @@ -35,7 +35,6 @@ public static partial class Query /**** Public methods ****/ /***************************************************/ - [PreviousVersion("7.3", "BH.Revit.Engine.Core.Query.ViewSolid(Autodesk.Revit.DB.View)")] [Description("Returns a solid that represents the 3-dimensional extents of a given view.")] [Input("view", "View to compute the solids.")] [Input("createUnlimitedIfViewUncropped", "If false, the method will return null in case of missing crop box (i.e. the view is unlimited, so it cannot be represented by a solid). If true, uncropped views will produce an 'unlimited' solid roughly 1e+6 by 1e+6 in dimensions perpendicular to the view direction, with depth equal to view depth or 1e+4 in case of views without depth.")] From 4be195dfd0f7d2d73a33bff0917452779a5553ea Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 14 Oct 2024 18:30:53 +0100 Subject: [PATCH 060/131] Incorporate PR comments from Pawel Baran - Part01 --- .../Convert/Revit/FromRevit/View.cs | 47 +- .../Convert/Revit/FromRevit/ViewFilter.cs | 30 +- .../Revit/ToRevit/ParameterFilterElement.cs | 487 +++++++++--------- Revit_Core_Engine/Modify/Update.cs | 5 +- Revit_oM/Enums/FillPattern.cs | 16 +- Revit_oM/Enums/LinePattern.cs | 8 +- Revit_oM/FilterRules/FilterLevelRule.cs | 2 +- .../FilterRules/FilterNumericValueRule.cs | 2 +- Revit_oM/FilterRules/FilterStringRule.cs | 2 +- .../FilterRules/ParameterValuePresenceRule.cs | 2 +- 10 files changed, 305 insertions(+), 296 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 09a7a94f8..03ca2e207 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -86,46 +86,47 @@ private static OverrideGraphicSettings overrideGraphicSettingsFromRevit(this Vie // Initialize BHoM OverrideGraphicsSettings object OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + // Convert COLORS - overrideGraphicsSettings.LineColor = System.Drawing.Color.FromArgb(revitOverrides.CutLineColor.Red, revitOverrides.CutLineColor.Green, revitOverrides.CutLineColor.Blue); - overrideGraphicsSettings.CutColor = System.Drawing.Color.FromArgb(revitOverrides.CutBackgroundPatternColor.Red, revitOverrides.CutBackgroundPatternColor.Green, revitOverrides.CutBackgroundPatternColor.Blue); - overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); + if (revitOverrides.CutLineColor.IsValid) overrideGraphicsSettings.LineColor = System.Drawing.Color.FromArgb(revitOverrides.CutLineColor.Red, revitOverrides.CutLineColor.Green, revitOverrides.CutLineColor.Blue); + if (revitOverrides.CutForegroundPatternColor.IsValid) overrideGraphicsSettings.CutColor = System.Drawing.Color.FromArgb(revitOverrides.CutBackgroundPatternColor.Red, revitOverrides.CutBackgroundPatternColor.Green, revitOverrides.CutBackgroundPatternColor.Blue); + if (revitOverrides.SurfaceBackgroundPatternColor.IsValid) overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); // Convert LINE PATTERNS String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; - if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DASH; } - else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DOT; } - else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.HIDDEN; } - else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.SOLID; } + if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dash; } + else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dot; } + else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Hidden; } + else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Solid; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } // Convert CUT PATTERNS String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; - if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } - else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } - else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } - else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.STEEL; } - else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.SOLID; } - else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.VERTICAL; } + if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Steel; } + else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Solid; } + else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Vertical; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } // Convert SURFACE PATTERNS String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; - if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } - else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } - else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } - else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.STEEL; } - else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.SOLID; } - else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.VERTICAL; } + if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Steel; } + else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Solid; } + else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Vertical; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } return overrideGraphicsSettings; diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 5f7b56c28..97249a119 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -68,15 +68,13 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par // If the Filter is assigned with any rules..... if (revitViewFilter.GetElementFilter()!=null) { - //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS - //List parameterNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() - Dictionary filterAndParNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() - .Select(filter => ((ElementParameterFilter)filter).GetRules()) - .SelectMany(list => list) - .ToDictionary(rule => rule, rule => (GetParameterById(revitViewFilter.Document, rule.GetRuleParameter()).Definition.Name.ToString())); - //.ToList(); + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS + List filterRules = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() + .Select(filter => ((ElementParameterFilter)filter).GetRules()) + .SelectMany(list => list) + .ToList(); //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) - List revitFilterRules = (filterAndParNames.Keys.ToList()); + List revitFilterRules = (filterRules); //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); } @@ -178,7 +176,7 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t bhomFilterStringRule = new oM.Revit.FilterRules.FilterStringRule(); bhomFilterStringRule.ParameterName = paramName; bhomFilterStringRule.Value = paramValue; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; + bhomFilterStringRule.ComparisonType = bhomTextEvaluator; return bhomFilterStringRule; } @@ -227,7 +225,7 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = paramName; bhomFilterDoubleRule.Value = paramValue; - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + bhomFilterDoubleRule.ComparisonType = bhomNumericEvaluator; return bhomFilterDoubleRule; } @@ -276,7 +274,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = paramName; bhomFilterIntegerRule.Value = paramValue; - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + bhomFilterIntegerRule.ComparisonType = bhomNumericEvaluator; return bhomFilterIntegerRule; } @@ -324,7 +322,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR bhomFilterElemIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); bhomFilterElemIdRule.ParameterName = paramName; bhomFilterElemIdRule.Value = paramValue; - bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; + bhomFilterElemIdRule.ComparisonType = bhomNumericEvaluator; return bhomFilterElemIdRule; } @@ -400,7 +398,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); bhomFilterStringRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; + bhomFilterStringRule.ComparisonType = bhomTextEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; } // FilterDoubleRule @@ -427,7 +425,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + bhomFilterDoubleRule.ComparisonType = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; } // FilterIntegerRule @@ -454,7 +452,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + bhomFilterIntegerRule.ComparisonType = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; } // FilterElementIdRule @@ -481,7 +479,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); bhomFilterElementIdRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); - bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; + bhomFilterElementIdRule.ComparisonType = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterElementIdRule; } default: diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index ac7711a99..34460952a 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -72,9 +72,9 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(catName => catName.ToUpper().Replace(" ", "")) // Get the corresponding BuiltInCategories .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) - .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_","")) + .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_", "")) .ToList(); - return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]);}) + return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]); }) // Get the ElementIds of the BuiltInCategories .Select(builtInCat => new ElementId(builtInCat)) // Turn the Stream into a List of ElementIds @@ -87,8 +87,8 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - if (filter.Rules.Count != 0) - { + if (filter.Rules.Count != 0) + { ElementFilter elFilter = new LogicalAndFilter(filter.Rules .GroupBy(rule => rule.GetType()) .ToDictionary(grp => grp.Key, grp => grp.ToList()) @@ -148,16 +148,16 @@ public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document, // FilterCategoryRule if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterCategoryRule)) - { return filterCategoryRuleToRevit(document, (oM.Revit.FilterRules.FilterCategoryRule)filterRule); } + { return filterCategoryRuleToRevit(document, (oM.Revit.FilterRules.FilterCategoryRule)filterRule); } // FilterMaterialRule else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterMaterialRule)) - { return filterMaterialRuleToRevit(document, (oM.Revit.FilterRules.FilterMaterialRule)filterRule); } + { return filterMaterialRuleToRevit(document, (oM.Revit.FilterRules.FilterMaterialRule)filterRule); } // FilterLevelRule else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterLevelRule)) - { return filterLevelRuleToRevit(document, (oM.Revit.FilterRules.FilterLevelRule)filterRule); } + { return filterLevelRuleToRevit(document, (oM.Revit.FilterRules.FilterLevelRule)filterRule); } // FilterValueRule else if (filterRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) - { return filterValueRuleToRevit(document, (oM.Revit.FilterRules.FilterValueRule)filterRule); } + { return filterValueRuleToRevit(document, (oM.Revit.FilterRules.FilterValueRule)filterRule); } return null; @@ -171,10 +171,10 @@ private static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document d /* 2. EXTRACT CATEGORIES */ List categories = new List(); - foreach (Autodesk.Revit.DB.Category cat in document.Settings.Categories) { categories.Add(cat);} - + foreach (Autodesk.Revit.DB.Category cat in document.Settings.Categories) { categories.Add(cat); } + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ - List categoryIds = categories + List categoryIds = categories // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) // Cast down to Category Class Instances (INTERMEDIATE OPERATION) @@ -204,7 +204,7 @@ private static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document d //revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); FilteredElementCollector collector = new FilteredElementCollector(document); - Element mat=collector.OfClass(typeof(Material)).Where(material => material.Name == filterMaterialRule.MaterialName).First(); + Element mat = collector.OfClass(typeof(Material)).Where(material => material.Name == filterMaterialRule.MaterialName).First(); revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), mat.Id); return revitFilterRule; @@ -217,7 +217,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; BuiltInParameter levParam = BuiltInParameter.SCHEDULE_LEVEL_PARAM; - ElementId levParamId=new ElementId(levParam); + ElementId levParamId = new ElementId(levParam); ElementId levelId; /* 2. GET ELEVATION OF LEVEL CORRESPONDING TO INPUT LEVEL NAME */ @@ -242,7 +242,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu /* 3. CREATE FILTERS RULE */ // Based on level's elevation and LevelComparisonType... - switch (filterLevelRule.Evaluator) + switch (filterLevelRule.ComparisonType) { case LevelComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory @@ -267,7 +267,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu case LevelComparisonType.AtOrBelow: revitFilterRule = ParameterFilterRuleFactory .CreateLessOrEqualRule(levParamId, levelId); - break; + break; default: break; } @@ -278,288 +278,301 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu /***************************************************/ + private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document, oM.Revit.FilterRules.FilterValueRule filterValueRule) { - private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { + /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; - /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ - Autodesk.Revit.DB.FilterRule revitFilterRule = null; + /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ + ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); + Parameter parameter = GetParameterByName(document, filterValueRule.ParameterName); - /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ - ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); - Parameter parameter = GetParameterByName(document, filterValueRule.ParameterName); + /* 3. CREATE FILTER-RULE */ - /* 3. CREATE FILTER-RULE */ + // Based on FilterStringRule... + if (filterValueRule.GetType() == typeof(FilterStringRule) || + filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) + { + FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; - // Based on FilterStringRule... - if (filterValueRule.GetType()==typeof(FilterStringRule)|| - filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) + switch (filterStringValueRule.ComparisonType) { - FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; + case TextComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Contains: + revitFilterRule = ParameterFilterRuleFactory + .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.ContainsNot: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.StartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotStartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.EndsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotEndsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; + default: + break; + } + + // Based on FilterNumericValueRule... + } else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterNumericValueRule) || + filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) + { + + if ((filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule))) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; + + /* 2. Convert input value to target data type */ + Double doubleValue = 0.0; + Boolean boolParam = Double.TryParse(filterDoubleRule.Value, out doubleValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); + } - switch (filterStringValueRule.Evaluator) + /* 3. Convert units of input value to internal units */ + double convertedValue = UnitUtils.ConvertToInternalUnits(doubleValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ + switch (filterDoubleRule.ComparisonType) { - case TextComparisonType.Equal: + case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateEqualsRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.NotEqual: + case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateNotEqualsRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.Contains: + case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.ContainsNot: + case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotContainsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterOrEqualRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.StartsWith: + case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateLessRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.NotStartsWith: + case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateLessOrEqualRule(parameterId, convertedValue, 0.01); + break; + default: break; - case TextComparisonType.EndsWith: + } + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterIntegerRule)) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterIntegerRule filterIntegerRule = (oM.Revit.FilterRules.FilterIntegerRule)filterValueRule; + + /* 2. Convert input value to target data type */ + int intValue = 0; + Boolean boolParam = int.TryParse(filterIntegerRule.Value, out intValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); + } + + /* 3. Convert units of input value to internal units */ + int convertedValue = (int)UnitUtils.ConvertToInternalUnits((Double)intValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ + switch (filterIntegerRule.ComparisonType) + { + case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateEqualsRule(parameterId, convertedValue); break; - case TextComparisonType.NotEndsWith: + case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateNotEqualsRule(parameterId, convertedValue); break; - case TextComparisonType.Greater: + case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterRule(parameterId, convertedValue); break; - case TextComparisonType.GreaterOrEqual: + case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterOrEqualRule(parameterId, convertedValue); break; - case TextComparisonType.Less: - revitFilterRule=ParameterFilterRuleFactory - .CreateLessRule(parameterId,(string)filterStringValueRule.Value, false); + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, convertedValue); break; - case TextComparisonType.LessOrEqual: + case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateLessOrEqualRule(parameterId, convertedValue); break; default: break; } - - // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType()==typeof(oM.Revit.FilterRules.FilterNumericValueRule)|| - filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterElementIdRule)) { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterElementIdRule filterElementIdRule = (oM.Revit.FilterRules.FilterElementIdRule)filterValueRule; - if ((filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule))) - { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; - - /* 2. Convert input value to target data type */ - Double doubleValue=0.0; - Boolean boolParam=Double.TryParse(filterDoubleRule.Value,out doubleValue); - - if (!boolParam) - { - BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); - } - - /* 3. Convert units of input value to internal units */ - double convertedValue =UnitUtils.ConvertToInternalUnits(doubleValue, parameter.GetUnitTypeId()); - - /* 4. Convert Evaluator from Revit to BHoM */ - switch (filterDoubleRule.Evaluator) - { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, convertedValue, 0.01); - break; - default: - break; - } - } - else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterIntegerRule)) + /* 2. Convert input value to target data type */ + Boolean boolParam = int.TryParse(filterElementIdRule.Value, out int intValue); + ElementId elId = new ElementId(intValue); + + if (!boolParam) { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterIntegerRule filterIntegerRule = (oM.Revit.FilterRules.FilterIntegerRule)filterValueRule; - - /* 2. Convert input value to target data type */ - int intValue = 0; - Boolean boolParam = int.TryParse(filterIntegerRule.Value, out intValue); - - if (!boolParam) - { - BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); - } - - /* 3. Convert units of input value to internal units */ - int convertedValue = (int)UnitUtils.ConvertToInternalUnits((Double)intValue, parameter.GetUnitTypeId()); - - /* 4. Convert Evaluator from Revit to BHoM */ - switch (filterIntegerRule.Evaluator) - { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, convertedValue); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, convertedValue); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, convertedValue); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, convertedValue); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, convertedValue); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, convertedValue); - break; - default: - break; - } + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); } - else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterElementIdRule)) + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterElementIdRule.ComparisonType) { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterElementIdRule filterElementIdRule = (oM.Revit.FilterRules.FilterElementIdRule)filterValueRule; - - /* 2. Convert input value to target data type */ - Boolean boolParam = int.TryParse(filterElementIdRule.Value, out int intValue); - ElementId elId = new ElementId(intValue); - - if (!boolParam) - { - BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); - } - - /* 3. Convert Evaluator from Revit to BHoM */ - switch (filterElementIdRule.Evaluator) - { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, elId); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, elId); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, elId); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, elId); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, elId); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, elId); - break; - default: - break; - } + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, elId); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, elId); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, elId); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, elId); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, elId); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, elId); + break; + default: + break; } - } - // Based on ParameterValuePresenceRule... - else if (filterValueRule.GetType()== typeof(oM.Revit.FilterRules.ParameterValuePresenceRule)|| - filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) - { - oM.Revit.FilterRules.ParameterValuePresenceRule parameterValuePresenceRule = (oM.Revit.FilterRules.ParameterValuePresenceRule)filterValueRule; - if (parameterValuePresenceRule.IsPresent) { - revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId);} - else { - revitFilterRule = ParameterFilterRuleFactory.CreateHasNoValueParameterRule(parameterId);} + } else { return null; } + return revitFilterRule; + } - } else { return null; } - return revitFilterRule; - } - private static ElementId GetParameterIdByName(Document doc, string parameterName) + /***************************************************/ + + private static Autodesk.Revit.DB.FilterRule parameterValuePresenceRuleToRevit(Document document, oM.Revit.FilterRules.ParameterValuePresenceRule paramValuePresenceRule) { - // Get all elements in the document - FilteredElementCollector collector = new FilteredElementCollector(doc); - collector.WhereElementIsNotElementType(); + /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; - // Iterate through all elements - foreach (Element element in collector) + /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ + ElementId parameterId = GetParameterIdByName(document, paramValuePresenceRule.ParameterName); + Parameter parameter = GetParameterByName(document, paramValuePresenceRule.ParameterName); + + if (paramValuePresenceRule.IsPresent) { - // Get the parameter by name - Parameter param = element.LookupParameter(parameterName); - if (param != null) - { - // Return the ElementId of the parameter - return param.Id; - } + revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId); } + else + { + revitFilterRule = ParameterFilterRuleFactory.CreateHasNoValueParameterRule(parameterId); + } + + return revitFilterRule; - // If the parameter is not found, return InvalidElementId - return ElementId.InvalidElementId; } + private static ElementId GetParameterIdByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); - private static Parameter GetParameterByName(Document doc, string parameterName) + // Iterate through all elements + foreach (Element element in collector) { - // Get all elements in the document - FilteredElementCollector collector = new FilteredElementCollector(doc); - collector.WhereElementIsNotElementType(); - - // Iterate through all elements - foreach (Element element in collector) + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) { - // Get the parameter by name - Parameter param = element.LookupParameter(parameterName); - if (param != null) - { - // Return the ElementId of the parameter - return param; - } + // Return the ElementId of the parameter + return param.Id; } + } - // If the parameter is not found, return InvalidElementId - return null; + // If the parameter is not found, return InvalidElementId + return ElementId.InvalidElementId; + } + + + private static Parameter GetParameterByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) + { + // Return the ElementId of the parameter + return param; + } } + + // If the parameter is not found, return InvalidElementId + return null; + } + } } diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 79d25de25..d26c11f67 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -257,7 +257,7 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re [Input("settings", "Revit adapter settings to be used while performing the action.")] [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] - public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) where T:Autodesk.Revit.DB.View + public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) where T:View { /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ @@ -414,9 +414,6 @@ private static void ErrorOnCategoryChange(this FamilyInstance element, IInstance } /***************************************************/ - - - } } diff --git a/Revit_oM/Enums/FillPattern.cs b/Revit_oM/Enums/FillPattern.cs index 17efeff82..81a9e6948 100644 --- a/Revit_oM/Enums/FillPattern.cs +++ b/Revit_oM/Enums/FillPattern.cs @@ -8,13 +8,13 @@ namespace BH.oM.Revit.Enums { public enum FillPattern { - CROSSHATCH, - DIAGONAL_CROSSHATCH, - DIAGONAL_DOWN, - DIAGONAL_UP, - HORIZONTAL, - STEEL, - SOLID, - VERTICAL + CrossHatch, + DiagonalCrossHatch, + DiagonalDown, + DiagonalUp, + Horizontal, + Steel, + Solid, + Vertical } } diff --git a/Revit_oM/Enums/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs index 1da829a39..742a2e96f 100644 --- a/Revit_oM/Enums/LinePattern.cs +++ b/Revit_oM/Enums/LinePattern.cs @@ -8,9 +8,9 @@ namespace BH.oM.Revit.Enums { public enum LinePattern { - DASH, - DOT, - HIDDEN, - SOLID + Dash, + Dot, + Hidden, + Solid } } diff --git a/Revit_oM/FilterRules/FilterLevelRule.cs b/Revit_oM/FilterRules/FilterLevelRule.cs index 5745b4b1d..8f502498c 100644 --- a/Revit_oM/FilterRules/FilterLevelRule.cs +++ b/Revit_oM/FilterRules/FilterLevelRule.cs @@ -10,7 +10,7 @@ namespace BH.oM.Revit.FilterRules public class FilterLevelRule : FilterRule { public virtual string LevelName { get; set; } - public virtual LevelComparisonType Evaluator { get; set; } + public virtual LevelComparisonType ComparisonType { get; set; } } } diff --git a/Revit_oM/FilterRules/FilterNumericValueRule.cs b/Revit_oM/FilterRules/FilterNumericValueRule.cs index 3f9d3d27e..45b16d732 100644 --- a/Revit_oM/FilterRules/FilterNumericValueRule.cs +++ b/Revit_oM/FilterRules/FilterNumericValueRule.cs @@ -9,7 +9,7 @@ namespace BH.oM.Revit.FilterRules { public abstract class FilterNumericValueRule : FilterValueRule { - public virtual NumberComparisonType Evaluator { get; set; } + public virtual NumberComparisonType ComparisonType { get; set; } } diff --git a/Revit_oM/FilterRules/FilterStringRule.cs b/Revit_oM/FilterRules/FilterStringRule.cs index 39116a35c..9b65a4c26 100644 --- a/Revit_oM/FilterRules/FilterStringRule.cs +++ b/Revit_oM/FilterRules/FilterStringRule.cs @@ -9,6 +9,6 @@ namespace BH.oM.Revit.FilterRules { public class FilterStringRule : FilterValueRule { - public virtual TextComparisonType Evaluator { get; set; } + public virtual TextComparisonType ComparisonType { get; set; } } } diff --git a/Revit_oM/FilterRules/ParameterValuePresenceRule.cs b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs index 7089a6bf2..30bfe16d2 100644 --- a/Revit_oM/FilterRules/ParameterValuePresenceRule.cs +++ b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs @@ -7,7 +7,7 @@ namespace BH.oM.Revit.FilterRules { - public class ParameterValuePresenceRule : FilterValueRule + public class ParameterValuePresenceRule : FilterParameterRule { public virtual bool IsPresent { get; set; } } From a2f620506bb364663ccf7e685ed3ffb9439b15c6 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 14 Oct 2024 18:31:20 +0100 Subject: [PATCH 061/131] Add new abstract class FilterParameterRule Using this abstract class it's possible to decouple the ParameterValuePresence Class from the FilterValueRule class. --- Revit_oM/FilterRules/FilterParameterRule.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Revit_oM/FilterRules/FilterParameterRule.cs diff --git a/Revit_oM/FilterRules/FilterParameterRule.cs b/Revit_oM/FilterRules/FilterParameterRule.cs new file mode 100644 index 000000000..9ba9c8021 --- /dev/null +++ b/Revit_oM/FilterRules/FilterParameterRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.FilterRules +{ + public abstract class FilterParameterRule: FilterRule + { + public virtual string ParameterName { get; set; } + } +} From b3484150cf4011905082fdae15f0fa31b269093c Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 11:36:50 +0100 Subject: [PATCH 062/131] Incorporate PR comments from Pawel Baran - Part02 --- Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs | 2 +- .../Convert/Revit/ToRevit/ParameterFilterElement.cs | 2 +- Revit_Core_Engine/Modify/Update.cs | 4 ++-- Revit_oM/Elements/ViewFilter.cs | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 97249a119..36e288155 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -62,7 +62,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 2. Transfer List of CATEGORY NAMES */ List categories = new List(); foreach (Autodesk.Revit.DB.Category cat in revitViewFilter.Document.Settings.Categories) { categories.Add(cat); } - viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat=>cat.Id==catId).First().Name).ToList(); + viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat=>cat.Id==catId).First()).Cast().ToList(); /* 3. Transfer List of FILTER RULES */ // If the Filter is assigned with any rules..... diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 34460952a..1276cac21 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -69,7 +69,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List categoryIdsList = filter.Categories // Format the string name of the categories - .Select(catName => catName.ToUpper().Replace(" ", "")) + .Select(catObj => catObj.ToString().ToUpper().Replace(" ", "")) // Get the corresponding BuiltInCategories .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_", "")) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index d26c11f67..b85251b1b 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -313,8 +313,8 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View public static bool Update(this ParameterFilterElement element, BH.oM.Adapters.Revit.Elements.ViewFilter bHoMObject, RevitSettings settings, bool setLocationOnUpdate) { // 1. Collect the ElementIds of the filter's categories - via Streams - List builtInCategoryIds= bHoMObject.Categories.Select(catName => { BuiltInCategory builtInCat; - Enum.TryParse(catName, out builtInCat); + List builtInCategoryIds= bHoMObject.Categories.Select(catObj => { BuiltInCategory builtInCat; + Enum.TryParse(catObj.ToString(), out builtInCat); return builtInCat; }) .Select(builtInCat=> new ElementId(builtInCat)) .ToList(); diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 19d833939..13959881d 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -6,12 +6,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using BH.oM.Revit.Enums; namespace BH.oM.Adapters.Revit.Elements { public class ViewFilter : BHoMObject { - public virtual List Categories { get; set; } + public virtual List Categories { get; set; } public virtual List Rules { get; set; } } } From 5486724529cf6601b1067157b49570e9f3688c0d Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 13:34:03 +0100 Subject: [PATCH 063/131] Incorporate comments from Pawel Baran - Part03 --- .../Convert/Revit/FromRevit/View.cs | 85 +++-- .../Convert/Revit/FromRevit/ViewFilter.cs | 335 ++++++++---------- Revit_Core_Engine/Modify/Update.cs | 4 +- Revit_oM/Enums/LinePattern.cs | 8 +- 4 files changed, 221 insertions(+), 211 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 03ca2e207..29eef3cde 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -93,41 +93,68 @@ private static OverrideGraphicSettings overrideGraphicSettingsFromRevit(this Vie if (revitOverrides.SurfaceBackgroundPatternColor.IsValid) overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); // Convert LINE PATTERNS - String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; - - if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dash; } - else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dot; } - else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Hidden; } - else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Solid; } - else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } + try + { + String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; + + if (linePatternName.Replace(" ","").ToUpper().Contains("DASHDOTDOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DashDotDot; } + else if (linePatternName.ToUpper().Replace(" ","").Contains("DASHDOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DashDot; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("DOUBLEDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DoubleDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("LONGDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.LongDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("LOOSEDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.LooseDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("TRIPLEDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.TripleDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dot; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Hidden; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Solid; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } + } + catch + { + BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); + } // Convert CUT PATTERNS - String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; - - if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CrossHatch; } - else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalDown; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalUp; } - else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Horizontal; } - else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Steel; } - else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Solid; } - else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Vertical; } - else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } + try + { + String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; + + if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Steel; } + else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Solid; } + else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Vertical; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } + } + catch + { + BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); + } // Convert SURFACE PATTERNS - String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; - - if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CrossHatch; } - else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalDown; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalUp; } - else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Horizontal; } - else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Steel; } - else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Solid; } - else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Vertical; } - else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } + try + { + String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; + + if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Steel; } + else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Solid; } + else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Vertical; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } + } + catch + { + BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); + } return overrideGraphicsSettings; } diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 36e288155..7ac50b832 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -94,21 +94,18 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par { List bhomFilterRules = revitFilterRules.Select(revitRule => { - TextComparisonType bhomTextEvaluator = 0; - NumberComparisonType bhomNumericEvaluator = 0; - // FILTER STRING RULE if (revitRule.GetType()== typeof(Autodesk.Revit.DB.FilterStringRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule); } // FILTER DOUBLE RULE else if (revitRule.GetType()==typeof(Autodesk.Revit.DB.FilterDoubleRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule); } // FILTER INTEGER RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterIntegerRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule); } // FILTER ELEMENTID RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterElementIdRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule); } // FILTER CATEGORY RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterCategoryRule)) { return (oM.Revit.FilterRules.FilterRule)FilterCategoryRuleFromRevit(revitViewFilter, revitRule); } @@ -117,7 +114,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par { return (oM.Revit.FilterRules.FilterRule)ParameterValuePresenceRuleFromRevit(revitViewFilter, revitRule); } // FILTER INVERSE RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterInverseRule)) - { return FilterInverseRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator, bhomNumericEvaluator); } + { return FilterInverseRuleFromRevit(revitViewFilter, revitRule); } return null; }).ToList(); @@ -126,7 +123,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -140,35 +137,8 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); // Convert the REVIT FilterStringEvaluator type into the BHOM TextComparisonType Enum - switch (stringEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterStringBeginsWith": - bhomTextEvaluator = TextComparisonType.StartsWith; - break; - case "Autodesk.Revit.DB.FilterStringEndsWith": - bhomTextEvaluator = TextComparisonType.EndsWith; - break; - case "Autodesk.Revit.DB.FilterStringEquals": - bhomTextEvaluator = TextComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterStringContains": - bhomTextEvaluator = TextComparisonType.Contains; - break; - case "Autodesk.Revit.DB.FilterStringGreater": - bhomTextEvaluator = TextComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": - bhomTextEvaluator = TextComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterStringLess": - bhomTextEvaluator = TextComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterStringLessOrEqual": - bhomTextEvaluator = TextComparisonType.LessOrEqual; - break; - default: - break; - } + TextComparisonType bhomTextEvaluator = TextComparisonTypeFromRevit(stringEvaluator.GetType().Name); + // 2. BUILD the BHOM FILTERRULE object @@ -183,7 +153,7 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -198,26 +168,8 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + NumberComparisonType bhomNumericEvaluator = NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); + // 2. BUILD the BHOM FILTERRULE object @@ -232,7 +184,7 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -247,26 +199,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + NumberComparisonType bhomNumericEvaluator=NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); // 2. BUILD the BHOM FILTERRULE object @@ -281,7 +214,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -295,26 +228,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + NumberComparisonType bhomNumericEvaluator = NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); // 2. BUILD the BHOM FILTERRULE object @@ -362,8 +276,7 @@ private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePre } - private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator, NumberComparisonType bhomNumericEvaluator) + private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -373,28 +286,15 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); // Convert the REVIT InnerRule into the corresponding BHOM FilterRule obj - switch (innerRule.GetType().ToString()) + TextComparisonType bhomTextEvaluator = 0; + NumberComparisonType bhomNumericEvaluator = 0; + + switch (innerRule.GetType().Name) { //FilterStringRule - case ("Autodesk.Revit.DB.FilterStringRule"): + case nameof(Autodesk.Revit.DB.FilterStringRule): { - switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterStringEquals"): - bhomTextEvaluator = TextComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterStringBeginsWith"): - bhomTextEvaluator = TextComparisonType.NotStartsWith; - break; - case ("Autodesk.Revit.DB.FilterStringEndsWith"): - bhomTextEvaluator = TextComparisonType.NotEndsWith; - break; - case ("Autodesk.Revit.DB.FilterStringContains"): - bhomTextEvaluator = TextComparisonType.ContainsNot; - break; - default: - break; - } + bhomTextEvaluator = InverseTextComparisonTypeFromRevit(((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().Name); oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); bhomFilterStringRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; @@ -402,26 +302,9 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; } // FilterDoubleRule - case ("Autodesk.Revit.DB.FilterDoubleRule"): + case nameof(Autodesk.Revit.DB.FilterDoubleRule): { - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } + bhomNumericEvaluator = InverseNumberComparisonTypeFromRevit(((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().Name); oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); @@ -429,26 +312,9 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; } // FilterIntegerRule - case ("Autodesk.Revit.DB.FilterIntegerRule"): + case nameof(Autodesk.Revit.DB.FilterIntegerRule): { - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } + bhomNumericEvaluator = InverseNumberComparisonTypeFromRevit(((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().Name); oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); @@ -456,26 +322,9 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; } // FilterElementIdRule - case ("Autodesk.Revit.DB.FilterElementIdRule"): + case nameof(Autodesk.Revit.DB.FilterElementIdRule): { - switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } + oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); bhomFilterElementIdRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); @@ -512,6 +361,134 @@ private static Parameter GetParameterById(Autodesk.Revit.DB.Document doc, Elemen return null; } + + private static NumberComparisonType NumberComparisonTypeFromRevit(string innerRuleName) + { + NumberComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterNumericEquals)): + return NumberComparisonType.Equal; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreater)): + return NumberComparisonType.Greater; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual)): + return NumberComparisonType.GreaterOrEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLess)): + return NumberComparisonType.Less; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLessOrEqual)): + return NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + return (NumberComparisonType)output; + + } + + + private static NumberComparisonType InverseNumberComparisonTypeFromRevit(string innerRuleName) + { + NumberComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterNumericEquals)): + return NumberComparisonType.NotEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreater)): + return NumberComparisonType.Less; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual)): + return NumberComparisonType.NotEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLess)): + return NumberComparisonType.Greater; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLessOrEqual)): + return NumberComparisonType.GreaterOrEqual; + break; + default: + break; + } + + return (NumberComparisonType)output; + + } + + + + private static TextComparisonType TextComparisonTypeFromRevit(string innerRuleName) + { + TextComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterStringEquals)): + return TextComparisonType.Equal; + break; + case (nameof(Autodesk.Revit.DB.FilterStringBeginsWith)): + return TextComparisonType.StartsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringEndsWith)): + return TextComparisonType.EndsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringContains)): + return TextComparisonType.Contains; + break; + case nameof(Autodesk.Revit.DB.FilterStringGreater): + return TextComparisonType.Greater; + break; + case nameof(Autodesk.Revit.DB.FilterStringGreaterOrEqual): + return TextComparisonType.GreaterOrEqual; + break; + case nameof(Autodesk.Revit.DB.FilterStringLess): + return TextComparisonType.Less; + break; + case nameof(Autodesk.Revit.DB.FilterStringLessOrEqual): + return TextComparisonType.LessOrEqual; + break; + default: + break; + } + + return (TextComparisonType)output; + + } + + + private static TextComparisonType InverseTextComparisonTypeFromRevit(string innerRuleName) + { + TextComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterStringEquals)): + return TextComparisonType.NotEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterStringBeginsWith)): + return TextComparisonType.NotStartsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringEndsWith)): + return TextComparisonType.NotEndsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringContains)): + return TextComparisonType.ContainsNot; + break; + default: + break; + } + + return (TextComparisonType)output; + + } + + } } diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index b85251b1b..e5381846d 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -275,11 +275,11 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().Replace("_"," ").ToUpper())); + .FirstOrDefault(pattern => pattern.Name.Replace(" ", "").ToUpper().Contains(kvp.Value.CutPattern.ToString().Replace(" ","").ToUpper())); FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().Replace("_", " ").ToUpper())); + .FirstOrDefault(pattern => pattern.Name.Replace(" ", "").ToUpper().Contains(kvp.Value.SurfacePattern.ToString().Replace(" ", "").ToUpper())); // 3.3 Create the OverrideGraphics by Properties OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); diff --git a/Revit_oM/Enums/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs index 742a2e96f..d0025cc17 100644 --- a/Revit_oM/Enums/LinePattern.cs +++ b/Revit_oM/Enums/LinePattern.cs @@ -9,8 +9,14 @@ namespace BH.oM.Revit.Enums public enum LinePattern { Dash, + DashDot, + DashDotDot, + DoubleDash, Dot, Hidden, - Solid + LongDash, + LooseDash, + Solid, + TripleDash } } From 3338dacd98dc725324d181979cc37e7650ccab0e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 18:44:39 +0100 Subject: [PATCH 064/131] Incorporate PR Comments from Pawel Baran - Part04 --- .../Convert/Revit/FromRevit/View.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 29eef3cde..7ae2448f0 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -61,14 +61,15 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, if (view != null) return view; - /*1. Transfer ViewFilters and corresponding OverrideGraphicSettings into ViewFilterWithOverrides Objects - via STREAMS */ - List filtersWithOverrides = revitView.GetFilters().ToDictionary - (elId => Convert.ViewFilterFromRevit((ParameterFilterElement)revitView.Document.GetElement(elId)), - elId => overrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() - .Select(kvp => new ViewFilterWithOverrides { Filter = kvp.Key, Overrides = kvp.Value }).ToList(); - - /*2. Create BHoM View Object with Name and FilterWithOverrides objects */ - view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name, FiltersWithOverrides = filtersWithOverrides }; + if (revitView.AreGraphicsOverridesAllowed()) { + /*1. Transfer ViewFilters and corresponding OverrideGraphicSettings into ViewFilterWithOverrides Objects - via STREAMS */ + List filtersWithOverrides = revitView.GetFilters().ToDictionary + (elId => Convert.ViewFilterFromRevit((ParameterFilterElement)revitView.Document.GetElement(elId)), + elId => overrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() + .Select(kvp => new ViewFilterWithOverrides { Filter = kvp.Key, Overrides = kvp.Value }).ToList(); + /*2. Create BHoM View Object with Name and FilterWithOverrides objects */ + view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name, FiltersWithOverrides = filtersWithOverrides };} + else { view = new oM.Adapters.Revit.Elements.View { Name=revitView.Name };} //Set identifiers, parameters & custom data view.SetIdentifiers(revitView); From 7abafcc3a998ccf22f6aae0743073599e9d3c87d Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Mon, 29 Jan 2024 19:04:11 +0100 Subject: [PATCH 065/131] draft oM classes added --- Revit_oM/Elements/View.cs | 14 ++++++++++++++ Revit_oM/Elements/ViewFilter.cs | 16 ++++++++++++++++ Revit_oM/Views/FilterWithOverrides.cs | 17 +++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 Revit_oM/Elements/View.cs create mode 100644 Revit_oM/Elements/ViewFilter.cs create mode 100644 Revit_oM/Views/FilterWithOverrides.cs diff --git a/Revit_oM/Elements/View.cs b/Revit_oM/Elements/View.cs new file mode 100644 index 000000000..5ce73c656 --- /dev/null +++ b/Revit_oM/Elements/View.cs @@ -0,0 +1,14 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Views +{ + public class View : BHoMObject + { + public virtual List FiltersWithOverrides { get; set; } + } +} diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs new file mode 100644 index 000000000..44400a0d3 --- /dev/null +++ b/Revit_oM/Elements/ViewFilter.cs @@ -0,0 +1,16 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Elements +{ + public class ViewFilter : BHoMObject + { + public virtual List Categories { get; set; } + + //public List Rules { get; set; } + } +} diff --git a/Revit_oM/Views/FilterWithOverrides.cs b/Revit_oM/Views/FilterWithOverrides.cs new file mode 100644 index 000000000..c5325f31e --- /dev/null +++ b/Revit_oM/Views/FilterWithOverrides.cs @@ -0,0 +1,17 @@ +using BH.oM.Adapters.Revit.Elements; +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit +{ + public class FilterWithOverrides + { + public virtual ViewFilter Filter { get; set; } + + //public virtual List Overrides { get; set; } + } +} From 919b232caeb7c7f3983d11374adc428e8e9e3520 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Mon, 29 Jan 2024 19:04:30 +0100 Subject: [PATCH 066/131] draft support for pull of views and view filters added --- .../Convert/Revit/FromRevit/View.cs | 71 +++++++++++++++++++ .../Convert/Revit/FromRevit/ViewFilter.cs | 71 +++++++++++++++++++ Revit_Core_Engine/Query/BHoMType.cs | 32 +++++++++ 3 files changed, 174 insertions(+) create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/View.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs new file mode 100644 index 000000000..a1f58357d --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -0,0 +1,71 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base; +using BH.oM.Base.Attributes; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.Revit.Engine.Core +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] + //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] + public static oM.Adapters.Revit.Views.View ViewFromRevit(this View revitView, RevitSettings settings = null, Dictionary> refObjects = null) + { + settings = settings.DefaultIfNull(); + + oM.Adapters.Revit.Views.View view = refObjects.GetValue(revitView.Id.IntegerValue); + if (view != null) + return view; + + view = new oM.Adapters.Revit.Views.View { Name = revitView.Name }; + //TODO: here goes the convertion method + + //Set identifiers, parameters & custom data + view.SetIdentifiers(revitView); + view.CopyParameters(revitView, settings.MappingSettings); + view.SetProperties(revitView, settings.MappingSettings); + + refObjects.AddOrReplace(revitView.Id, view); + return view; + } + + /***************************************************/ + } +} + + + + + diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs new file mode 100644 index 000000000..f763ce32b --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -0,0 +1,71 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base; +using BH.oM.Base.Attributes; +using System.Collections.Generic; +using System.ComponentModel; + +namespace BH.Revit.Engine.Core +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] + //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] + public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this ParameterFilterElement revitViewFilter, RevitSettings settings = null, Dictionary> refObjects = null) + { + settings = settings.DefaultIfNull(); + + oM.Adapters.Revit.Elements.ViewFilter viewFilter = refObjects.GetValue(revitViewFilter.Id.IntegerValue); + if (viewFilter != null) + return viewFilter; + + viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; + //TODO: here goes the convertion method + + //Set identifiers, parameters & custom data + viewFilter.SetIdentifiers(revitViewFilter); + viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); + viewFilter.SetProperties(revitViewFilter, settings.MappingSettings); + + refObjects.AddOrReplace(revitViewFilter.Id, viewFilter); + return viewFilter; + } + + /***************************************************/ + } +} + + + + + diff --git a/Revit_Core_Engine/Query/BHoMType.cs b/Revit_Core_Engine/Query/BHoMType.cs index 0dd6547b1..4faaad9c2 100644 --- a/Revit_Core_Engine/Query/BHoMType.cs +++ b/Revit_Core_Engine/Query/BHoMType.cs @@ -53,6 +53,38 @@ public static Type IBHoMType(this Element element, Discipline discipline, RevitS /**** Public Methods ****/ /***************************************************/ + //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] + //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] + //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + public static Type BHoMType(this View view, Discipline discipline, RevitSettings settings = null) + { + switch (discipline) + { + default: + return typeof(BH.oM.Adapters.Revit.Views.View); + } + } + + /***************************************************/ + + //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] + //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] + //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + public static Type BHoMType(this ParameterFilterElement viewFilter, Discipline discipline, RevitSettings settings = null) + { + switch (discipline) + { + default: + return typeof(BH.oM.Adapters.Revit.Elements.ViewFilter); + } + } + + /***************************************************/ + [Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] [Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] From 584b00a2d73d5b8c7d5cad6ff809715afeb3cfa8 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Mon, 29 Jan 2024 19:04:42 +0100 Subject: [PATCH 067/131] draft support for views and view filters added --- .../Revit/ToRevit/ParameterFilterElement.cs | 66 +++++++++++++++++++ Revit_Core_Engine/Convert/ToRevit.cs | 13 ++++ Revit_Core_Engine/Modify/Update.cs | 39 +++++++++++ 3 files changed, 118 insertions(+) create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs new file mode 100644 index 000000000..7bf653286 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -0,0 +1,66 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2024, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using Autodesk.Revit.DB; +using BH.oM.Adapters.Revit.Settings; +using BH.oM.Base; +using BH.oM.Base.Attributes; +using BH.oM.Physical.Elements; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; + +namespace BH.Revit.Engine.Core +{ + public static partial class Convert + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + //[Description("Converts BH.oM.Adapters.Revit.Elements.Assembly to a Revit AssemblyInstance." + + // "\nOnly the assembly instance itself is created, while any updates of name or parameters need to happen in a separate transaction, which is caused by Revit API limitations.")] + //[Input("assembly", "BH.oM.Adapters.Revit.Elements.Assembly to be converted.")] + //[Input("document", "Revit document, in which the output of the convert will be created.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("assemblyInstance", "Revit AssemblyInstance resulting from converting the input BH.oM.Adapters.Revit.Elements.Assembly.")] + public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) + { + ParameterFilterElement revitFilter = refObjects.GetValue(document, filter.BHoM_Guid); + if (revitFilter != null) + return revitFilter; + + //TODO: fill this in with the logic + List categories = new List(); + revitFilter = ParameterFilterElement.Create(document, filter.Name, categories); + + revitFilter.CopyParameters(filter, settings); + refObjects.AddOrReplace(filter, revitFilter); + return revitFilter; + } + + /***************************************************/ + } +} + diff --git a/Revit_Core_Engine/Convert/ToRevit.cs b/Revit_Core_Engine/Convert/ToRevit.cs index dca092351..9eb95122c 100644 --- a/Revit_Core_Engine/Convert/ToRevit.cs +++ b/Revit_Core_Engine/Convert/ToRevit.cs @@ -40,6 +40,19 @@ public static partial class Convert /**** Public methods ****/ /***************************************************/ + //[Description("Converts BH.oM.Spatial.SettingOut.Grid to a Revit Grid or MultiSegmentGrid.")] + //[Input("grid", "BH.oM.Spatial.SettingOut.Grid to be converted.")] + //[Input("document", "Revit document, in which the output of the convert will be created.")] + //[Input("settings", "Revit adapter settings to be used while performing the convert.")] + //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + //[Output("grid", "Revit Grid or MultiSegmentGrid resulting from converting the input BH.oM.Spatial.SettingOut.Grid.")] + public static Element ToRevit(this BH.oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) + { + return filter.ToRevitParameterFilterElement(document, settings, refObjects); + } + + /***************************************************/ + [Description("Converts BH.oM.Spatial.SettingOut.Grid to a Revit Grid or MultiSegmentGrid.")] [Input("grid", "BH.oM.Spatial.SettingOut.Grid to be converted.")] [Input("document", "Revit document, in which the output of the convert will be created.")] diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 22ce82abf..cd22bdb7d 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -243,6 +243,45 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re return true; } + /***************************************************/ + + //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] + //[Input("element", "Revit Assembly instance to be updated.")] + //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] + //[Input("settings", "Revit adapter settings to be used while performing the action.")] + //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] + //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] + public static bool Update(this View element, BH.oM.Adapters.Revit.Views.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + { + //TODO: fill in with logic + // update the filter overrides based on the BHoM view + // update name + // update parameteres (done below) + // otherhers as the class grows + + element.CopyParameters(bHoMObject, settings); + return true; + } + + /***************************************************/ + + //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] + //[Input("element", "Revit Assembly instance to be updated.")] + //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] + //[Input("settings", "Revit adapter settings to be used while performing the action.")] + //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] + //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] + public static bool Update(this ParameterFilterElement element, BH.oM.Adapters.Revit.Elements.ViewFilter bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + { + //TODO: fill in with logic + // update categories + // update parameteres (done below) + // maybe name? + + element.CopyParameters(bHoMObject, settings); + return true; + } + /***************************************************/ /**** Disallowed Types ****/ From 5fe79b2591f412c816d8c5fb1ba16a3d7e32d80f Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Feb 2024 07:27:10 +0000 Subject: [PATCH 068/131] Add bespoke classes defining graphics settings for new view filters - Enum LinePattern - Enum SolidPattern - Class OverrideGraphicSettings - Class FilterRule --- Revit_oM/Elements/FillPattern.cs | 20 +++++++++++++++++++ Revit_oM/Elements/FilterRule.cs | 15 ++++++++++++++ Revit_oM/Elements/LinePattern.cs | 16 +++++++++++++++ Revit_oM/Elements/OverrideGraphicSettings.cs | 21 ++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 Revit_oM/Elements/FillPattern.cs create mode 100644 Revit_oM/Elements/FilterRule.cs create mode 100644 Revit_oM/Elements/LinePattern.cs create mode 100644 Revit_oM/Elements/OverrideGraphicSettings.cs diff --git a/Revit_oM/Elements/FillPattern.cs b/Revit_oM/Elements/FillPattern.cs new file mode 100644 index 000000000..ab3c94ee6 --- /dev/null +++ b/Revit_oM/Elements/FillPattern.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public enum FillPattern + { + CROSSHATCH, + DIAGONAL_CROSSHATCH, + DIAGONAL_DOWN, + DIAGONAL_UP, + HORIZONTAL, + STEEL, + SOLID, + VERTICAL + } +} diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Elements/FilterRule.cs new file mode 100644 index 000000000..5993b6993 --- /dev/null +++ b/Revit_oM/Elements/FilterRule.cs @@ -0,0 +1,15 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Elements +{ + public abstract class FilterRule : BHoMObject + { + public virtual String ElementId { get; set; } + } + +} diff --git a/Revit_oM/Elements/LinePattern.cs b/Revit_oM/Elements/LinePattern.cs new file mode 100644 index 000000000..f75938f8a --- /dev/null +++ b/Revit_oM/Elements/LinePattern.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public enum LinePattern + { + DASH, + DOT, + HIDDEN, + SOLID + } +} diff --git a/Revit_oM/Elements/OverrideGraphicSettings.cs b/Revit_oM/Elements/OverrideGraphicSettings.cs new file mode 100644 index 000000000..c3922bd80 --- /dev/null +++ b/Revit_oM/Elements/OverrideGraphicSettings.cs @@ -0,0 +1,21 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public class OverrideGraphicSettings : BHoMObject + { + public virtual Color LineColor { get; set; } + public virtual Color CutColor { get; set; } + public virtual Color SurfaceColor { get; set; } + public virtual LinePattern LinePattern { get; set; } + public virtual FillPattern CutPattern { get; set; } + public virtual FillPattern SurfacePattern { get; set; } + + } +} From 35ea7facb3c3d7fb2ee3fddafd96aa7c5989725e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Feb 2024 07:30:00 +0000 Subject: [PATCH 069/131] Rename Class FilterWithOverrides to ViewFilterWithOverrides --- .../{FilterWithOverrides.cs => ViewFilterWithOverrides.cs} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename Revit_oM/Views/{FilterWithOverrides.cs => ViewFilterWithOverrides.cs} (65%) diff --git a/Revit_oM/Views/FilterWithOverrides.cs b/Revit_oM/Views/ViewFilterWithOverrides.cs similarity index 65% rename from Revit_oM/Views/FilterWithOverrides.cs rename to Revit_oM/Views/ViewFilterWithOverrides.cs index c5325f31e..4b73e0b39 100644 --- a/Revit_oM/Views/FilterWithOverrides.cs +++ b/Revit_oM/Views/ViewFilterWithOverrides.cs @@ -1,5 +1,6 @@ using BH.oM.Adapters.Revit.Elements; using BH.oM.Base; +using BH.oM.Revit.Elements; using System; using System.Collections.Generic; using System.Linq; @@ -8,10 +9,9 @@ namespace BH.oM.Adapters.Revit { - public class FilterWithOverrides + public class ViewFilterWithOverrides { public virtual ViewFilter Filter { get; set; } - - //public virtual List Overrides { get; set; } + public virtual List Overrides { get; set; } } } From 042e1b98f3a419ecf8495757d64516daa1247d95 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Feb 2024 08:53:49 +0000 Subject: [PATCH 070/131] Add FilterRuleType Enumeration - Enumeration Class that works as an attribute of the FilterRule Class, allowing to avoid the use of several abstract and concrete classes for each type of rule type. --- Revit_oM/Elements/ViewFilter.cs | 3 +-- Revit_oM/Views/FilterRuleType.cs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Revit_oM/Views/FilterRuleType.cs diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 44400a0d3..802bd2803 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -10,7 +10,6 @@ namespace BH.oM.Adapters.Revit.Elements public class ViewFilter : BHoMObject { public virtual List Categories { get; set; } - - //public List Rules { get; set; } + public List Rules { get; set; } } } diff --git a/Revit_oM/Views/FilterRuleType.cs b/Revit_oM/Views/FilterRuleType.cs new file mode 100644 index 000000000..01119a1a0 --- /dev/null +++ b/Revit_oM/Views/FilterRuleType.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public enum FilterRuleType + { + EQUALS, + GREATER, + GREATER_OR_EQUAL, + LESS, + LESS_OR_EQUAL, + CONTAINS, + NOT_CONTAINS, + BEGINSWITH, + NOT_BEGINSWITH, + ENDSWITH, + NOT_ENDSWITH + } +} From e0d96d64b62d64b9e176999d17362761b6f46ecd Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 12:13:15 +0000 Subject: [PATCH 071/131] Move classes FillPattern, FilterRule and LinePattern from Elements to Views namespace --- Revit_oM/{Elements => Views}/FillPattern.cs | 2 +- Revit_oM/{Elements => Views}/FilterRule.cs | 7 +++++-- Revit_oM/{Elements => Views}/LinePattern.cs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) rename Revit_oM/{Elements => Views}/FillPattern.cs (91%) rename Revit_oM/{Elements => Views}/FilterRule.cs (50%) rename Revit_oM/{Elements => Views}/LinePattern.cs (87%) diff --git a/Revit_oM/Elements/FillPattern.cs b/Revit_oM/Views/FillPattern.cs similarity index 91% rename from Revit_oM/Elements/FillPattern.cs rename to Revit_oM/Views/FillPattern.cs index ab3c94ee6..1e9451739 100644 --- a/Revit_oM/Elements/FillPattern.cs +++ b/Revit_oM/Views/FillPattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Revit.Views { public enum FillPattern { diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Views/FilterRule.cs similarity index 50% rename from Revit_oM/Elements/FilterRule.cs rename to Revit_oM/Views/FilterRule.cs index 5993b6993..a6a1fc79b 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/Views/FilterRule.cs @@ -5,11 +5,14 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.Views { public abstract class FilterRule : BHoMObject { - public virtual String ElementId { get; set; } + public virtual FilterRuleType RuleType { get; set; } + public virtual string ParameterName { get; set; } + public virtual object Value { get; set; } + } } diff --git a/Revit_oM/Elements/LinePattern.cs b/Revit_oM/Views/LinePattern.cs similarity index 87% rename from Revit_oM/Elements/LinePattern.cs rename to Revit_oM/Views/LinePattern.cs index f75938f8a..6e1292999 100644 --- a/Revit_oM/Elements/LinePattern.cs +++ b/Revit_oM/Views/LinePattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Revit.Views { public enum LinePattern { From 4a7247ea6a053465327aa6e817a4a4dd559cb6d8 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:05:54 +0000 Subject: [PATCH 072/131] Implement Update of View based on filters and overrides --- Revit_Core_Engine/Modify/Update.cs | 102 ++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index cd22bdb7d..465b2439f 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -20,16 +20,23 @@ * along with this code. If not, see . */ +using Autodesk.Revit.Creation; using Autodesk.Revit.DB; using BH.Engine.Adapters.Revit; using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Settings; +using BH.oM.Adapters.Revit.Views; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.MEP.Equipment.Parts; using System; using System.Collections.Generic; using System.ComponentModel; +using System.Drawing; using System.Linq; +using Color = Autodesk.Revit.DB.Color; +using OverrideGraphicSettings = Autodesk.Revit.DB.OverrideGraphicSettings; +using View = Autodesk.Revit.DB.View; namespace BH.Revit.Engine.Core { @@ -245,19 +252,52 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re /***************************************************/ - //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] - //[Input("element", "Revit Assembly instance to be updated.")] - //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] - //[Input("settings", "Revit adapter settings to be used while performing the action.")] - //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] - //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] - public static bool Update(this View element, BH.oM.Adapters.Revit.Views.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + [Description("Updates the existing Revit View based on the given BHoM View.")] + [Input("element", "Revit View instance to be updated.")] + [Input("bHoMObject", "BHoM View, based on which the Revit View will be updated.")] + [Input("settings", "Revit adapter settings to be used while performing the action.")] + [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] + [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] + public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) { - //TODO: fill in with logic - // update the filter overrides based on the BHoM view - // update name - // update parameteres (done below) - // otherhers as the class grows + /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ + + // Via Streams... + bHoMObject.FiltersWithOverrides + // 1. Turn Filters and Overrides into Keys and Values of a Dictionary + .ToDictionary(x => x.Filter, x => x.Overrides) + // 2. Turn the Dictionary into a List of KeyValue Pairs (to allow use of ForEach() + .ToList>() + // 3. Assign Filters to View and Set their Overrides + .ForEach(kvp => { ParameterFilterElement pfe = kvp.Key.ToRevitParameterFilterElement(element.Document, settings); + // 3.1 Add ViewFilter to the View + element.AddFilter(pfe.Id); + // 3.2 Get the Revit FillPatternElement Objects for CutPattern and SurfacePattern + FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); + FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); + // 3.3 Create the OverrideGraphics by Properties + OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); + Color revitCutColor = new Color(kvp.Value.CutColor.R, kvp.Value.CutColor.G, kvp.Value.CutColor.B); + Color revitSurfaceColor = new Color(kvp.Value.SurfaceColor.R, kvp.Value.SurfaceColor.G, kvp.Value.SurfaceColor.B); + overrideGraphicsSettings.SetCutLineColor(revitLineColor); + overrideGraphicsSettings.SetProjectionLineColor(revitLineColor); + overrideGraphicsSettings.SetCutBackgroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutBackgroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetCutForegroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutForegroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetSurfaceBackgroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceBackgroundPatternColor(revitSurfaceColor); + overrideGraphicsSettings.SetSurfaceForegroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceForegroundPatternColor(revitSurfaceColor); + // 3.4 Assign Overrides to the ViewFilter + element.SetFilterOverrides(pfe.Id, overrideGraphicsSettings); }); element.CopyParameters(bHoMObject, settings); return true; @@ -265,19 +305,32 @@ public static bool Update(this View element, BH.oM.Adapters.Revit.Views.View bHo /***************************************************/ - //[Description("Updates the existing Revit Assembly instance based on the given BHoM Assembly.")] - //[Input("element", "Revit Assembly instance to be updated.")] - //[Input("bHoMObject", "BHoM Assembly, based on which the Revit element will be updated.")] - //[Input("settings", "Revit adapter settings to be used while performing the action.")] - //[Input("setLocationOnUpdate", "Revit Assembly instance does not have location property, therefore this parameter is irrelevant.")] - //[Output("success", "True if the Revit Assembly instance has been updated successfully based on the input BHoM Assembly.")] + [Description("Updates the existing Revit ParameterFilterElement based on the given BHoM ViewFilter.")] + [Input("element", "Revit ParameterFilterElement to be updated.")] + [Input("bHoMObject", "BHoM ViewFilter, based on which the Revit element will be updated.")] + [Input("settings", "Revit adapter settings to be used while performing the action.")] + [Input("setLocationOnUpdate", "Revit ParameterFilterElement instance does not have location property, therefore this parameter is irrelevant.")] + [Output("success", "True if the Revit ParameterFilterElement instance has been updated successfully based on the input BHoM ViewFilter.")] public static bool Update(this ParameterFilterElement element, BH.oM.Adapters.Revit.Elements.ViewFilter bHoMObject, RevitSettings settings, bool setLocationOnUpdate) { - //TODO: fill in with logic - // update categories - // update parameteres (done below) - // maybe name? - + // 1. Collect the ElementIds of the filter's categories - via Streams + List builtInCategoryIds= bHoMObject.Categories.Select(catName => { BuiltInCategory builtInCat; + Enum.TryParse(catName, out builtInCat); + return builtInCat; }) + .Select(builtInCat=> new ElementId(builtInCat)) + .ToList(); + // 2. Assign Categories' Ids to the ParameterFilterElement + element.SetCategories(builtInCategoryIds); + // 3. Assign Name to the ParameterFilterElement + element.Name = bHoMObject.Name; + // 4. Assign Filter Rules to the ParameterFilterElement - via Streams + element.SetElementFilter(new LogicalAndFilter(bHoMObject.Rules + .Select(filterRule => Convert.filterRuleToRevit(element.Document, filterRule)) + .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) + .Cast() + .ToList())); + + // 5. Copy parameters to ParameterElementFilter element.CopyParameters(bHoMObject, settings); return true; } @@ -362,6 +415,9 @@ private static void ErrorOnCategoryChange(this FamilyInstance element, IInstance } /***************************************************/ + + + } } From 4031e853712e35e15b1718fdd1009296a8a6c040 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:09:15 +0000 Subject: [PATCH 073/131] Add minor updates to main classes in Elements namespace --- Revit_oM/Elements/OverrideGraphicSettings.cs | 5 +++-- Revit_oM/Elements/View.cs | 2 +- Revit_oM/Elements/ViewFilter.cs | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Revit_oM/Elements/OverrideGraphicSettings.cs b/Revit_oM/Elements/OverrideGraphicSettings.cs index c3922bd80..b2e205d57 100644 --- a/Revit_oM/Elements/OverrideGraphicSettings.cs +++ b/Revit_oM/Elements/OverrideGraphicSettings.cs @@ -1,4 +1,5 @@ using BH.oM.Base; +using BH.oM.Revit.Views; using System; using System.Collections.Generic; using System.Drawing; @@ -6,7 +7,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class OverrideGraphicSettings : BHoMObject { @@ -16,6 +17,6 @@ public class OverrideGraphicSettings : BHoMObject public virtual LinePattern LinePattern { get; set; } public virtual FillPattern CutPattern { get; set; } public virtual FillPattern SurfacePattern { get; set; } - + } } diff --git a/Revit_oM/Elements/View.cs b/Revit_oM/Elements/View.cs index 5ce73c656..ae7d48c58 100644 --- a/Revit_oM/Elements/View.cs +++ b/Revit_oM/Elements/View.cs @@ -9,6 +9,6 @@ namespace BH.oM.Adapters.Revit.Views { public class View : BHoMObject { - public virtual List FiltersWithOverrides { get; set; } + public virtual List FiltersWithOverrides { get; set; } } } diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 802bd2803..943746066 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,4 +1,5 @@ using BH.oM.Base; +using BH.oM.Revit.Views; using System; using System.Collections.Generic; using System.Linq; @@ -10,6 +11,6 @@ namespace BH.oM.Adapters.Revit.Elements public class ViewFilter : BHoMObject { public virtual List Categories { get; set; } - public List Rules { get; set; } + public virtual List Rules { get; set; } } } From 970b4f2facd25fc2fa6ae8e1ffe5e03a045a5e08 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:11:25 +0000 Subject: [PATCH 074/131] Implement Conversion of BHoM classes to Revit --- .../Revit/ToRevit/ParameterFilterElement.cs | 121 ++++++++++++++++-- Revit_Core_Engine/Convert/ToRevit.cs | 12 +- 2 files changed, 117 insertions(+), 16 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 7bf653286..dc5d78549 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -20,15 +20,21 @@ * along with this code. If not, see . */ +using Autodesk.Revit.Creation; using Autodesk.Revit.DB; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; +using BH.oM.Revit.Views; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Runtime.CompilerServices; +using Document = Autodesk.Revit.DB.Document; +using FilterRule = BH.oM.Revit.Views.FilterRule; namespace BH.Revit.Engine.Core { @@ -38,22 +44,48 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - //[Description("Converts BH.oM.Adapters.Revit.Elements.Assembly to a Revit AssemblyInstance." + - // "\nOnly the assembly instance itself is created, while any updates of name or parameters need to happen in a separate transaction, which is caused by Revit API limitations.")] - //[Input("assembly", "BH.oM.Adapters.Revit.Elements.Assembly to be converted.")] - //[Input("document", "Revit document, in which the output of the convert will be created.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("assemblyInstance", "Revit AssemblyInstance resulting from converting the input BH.oM.Adapters.Revit.Elements.Assembly.")] + [Description("Converts BH.oM.Adapters.Revit.Elements.ViewFilter to a Revit ParameterFilterElement." + + "\nThe Filter Rules are assigned after its creation due to Revit API limitations.")] + [Input("filter", "BH.oM.Adapters.Revit.Elements.ViewFilter to be converted.")] + [Input("document", "Revit document, in which the output of the convert will be created.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("filter", "Revit ParameterFilterElement resulting from converting the input BH.oM.Adapters.Revit.Elements.ViewFilter.")] public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) { ParameterFilterElement revitFilter = refObjects.GetValue(document, filter.BHoM_Guid); if (revitFilter != null) return revitFilter; - //TODO: fill this in with the logic - List categories = new List(); - revitFilter = ParameterFilterElement.Create(document, filter.Name, categories); + // 1. CREATE PARAMETERFILTERELEMENT with ASSIGNED CATEGORIES LIST + + /* 1.1 Turn list of Category Names into List of Category ElementIds via use of Streams */ + + List categoryIdsList = filter.Categories + // Format the string name of the categories + .Select(catName => catName.ToUpper().Replace(" ", "")) + // Get the corresponding BuiltInCategories + .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) + .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("ost_", "")) + .ToList(); + return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]);}) + // Get the ElementIds of the BuiltInCategories + .Select(builtInCat => new ElementId(builtInCat)) + // Turn the Stream into a List of ElementIds + .ToList(); + + /* 1.2 Create the ParameterFilterElement in the current Revit Document */ + revitFilter = ParameterFilterElement.Create(document, filter.Name, categoryIdsList); + + + // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT + + /* Via use of Streams*/ + revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules + .Select(filterRule => filterRuleToRevit(document, filterRule)) + .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) + .Cast() + .ToList())); revitFilter.CopyParameters(filter, settings); refObjects.AddOrReplace(filter, revitFilter); @@ -61,6 +93,75 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt } /***************************************************/ + + private static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { + + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + + ElementClassFilter paramFilter = new ElementClassFilter(typeof(Parameter)); + ElementClassFilter builtInParamFilter = new ElementClassFilter(typeof(BuiltInParameter)); + LogicalOrFilter logicalOrFilter = new LogicalOrFilter(paramFilter, builtInParamFilter); + + + ElementId parameterId = new FilteredElementCollector(document) + .WherePasses(logicalOrFilter) + .Where(par => par.Name.Equals(filterRule.ParameterName)) + .First() + .Id; + + switch (filterRule.RuleType) { + case FilterRuleType.BEGINSWITH: + revitFilterRule=ParameterFilterRuleFactory + .CreateBeginsWithRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.CONTAINS: + revitFilterRule = ParameterFilterRuleFactory + .CreateContainsRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.ENDSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateEndsWithRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.EQUALS: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, (int) filterRule.Value); + break; + case FilterRuleType.GREATER: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.GREATER_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.LESS: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.LESS_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (ElementId) filterRule.Value); + break; + case FilterRuleType.NOT_BEGINSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.NOT_CONTAINS: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string) filterRule.Value, false); + break; + case FilterRuleType.NOT_ENDSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEndsWithRule(parameterId, (string) filterRule.Value, false); + break; + default: + break;} + + return revitFilterRule; + } } + + + } diff --git a/Revit_Core_Engine/Convert/ToRevit.cs b/Revit_Core_Engine/Convert/ToRevit.cs index 9eb95122c..e97f6164d 100644 --- a/Revit_Core_Engine/Convert/ToRevit.cs +++ b/Revit_Core_Engine/Convert/ToRevit.cs @@ -40,12 +40,12 @@ public static partial class Convert /**** Public methods ****/ /***************************************************/ - //[Description("Converts BH.oM.Spatial.SettingOut.Grid to a Revit Grid or MultiSegmentGrid.")] - //[Input("grid", "BH.oM.Spatial.SettingOut.Grid to be converted.")] - //[Input("document", "Revit document, in which the output of the convert will be created.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("grid", "Revit Grid or MultiSegmentGrid resulting from converting the input BH.oM.Spatial.SettingOut.Grid.")] + [Description("Converts BH.oM.Adapters.Revit.Elements.ViewFilter to a Revit ParameterFilterElement.")] + [Input("filter", "BH.oM.Adapters.Revit.Elements.ViewFilter to be converted.")] + [Input("document", "Revit document, in which the output of the convert will be created.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("parameterFilterElement", "Revit ParameterFilterElement resulting from converting the input BH.oM.Adapters.Revit.Elements.ViewFilter.")] public static Element ToRevit(this BH.oM.Adapters.Revit.Elements.ViewFilter filter, Document document, RevitSettings settings = null, Dictionary> refObjects = null) { return filter.ToRevitParameterFilterElement(document, settings, refObjects); From b4724ed00abdd9ed932fb2b9bf2114be40474437 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:14:29 +0000 Subject: [PATCH 075/131] Add minor updates to BHoM ViewFilterOverrides Class --- Revit_oM/Views/ViewFilterWithOverrides.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Revit_oM/Views/ViewFilterWithOverrides.cs b/Revit_oM/Views/ViewFilterWithOverrides.cs index 4b73e0b39..8e9cd7162 100644 --- a/Revit_oM/Views/ViewFilterWithOverrides.cs +++ b/Revit_oM/Views/ViewFilterWithOverrides.cs @@ -1,17 +1,16 @@ using BH.oM.Adapters.Revit.Elements; using BH.oM.Base; -using BH.oM.Revit.Elements; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit +namespace BH.oM.Revit.Views { - public class ViewFilterWithOverrides + public class ViewFilterWithOverrides: BHoMObject { public virtual ViewFilter Filter { get; set; } - public virtual List Overrides { get; set; } + public virtual OverrideGraphicSettings Overrides { get; set; } } } From 3cf79858ce1f9ecf9fefae46dabf06b2bd26d35e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Feb 2024 21:15:19 +0000 Subject: [PATCH 076/131] Update Query/BHoMType.cs class for View and ParameterFilterElement --- Revit_Core_Engine/Query/BHoMType.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Revit_Core_Engine/Query/BHoMType.cs b/Revit_Core_Engine/Query/BHoMType.cs index 4faaad9c2..4d68623e3 100644 --- a/Revit_Core_Engine/Query/BHoMType.cs +++ b/Revit_Core_Engine/Query/BHoMType.cs @@ -53,27 +53,27 @@ public static Type IBHoMType(this Element element, Discipline discipline, RevitS /**** Public Methods ****/ /***************************************************/ - //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] - //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] - //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] - //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] - //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + [Description("Finds a suitable BHoM type to convert the given Revit View to, based on the requested engineering discipline and adapter settings.")] + [Input("view", "Revit View to find a correspondent BHoM type.")] + [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + [Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + [Output("bHoMType", "A suitable BHoM type to convert the given Revit View to.")] public static Type BHoMType(this View view, Discipline discipline, RevitSettings settings = null) { switch (discipline) { default: - return typeof(BH.oM.Adapters.Revit.Views.View); + return typeof(BH.oM.Adapters.Revit.Elements.View); } } /***************************************************/ - //[Description("Finds a suitable BHoM type to convert the given Revit ProjectInfo to, based on the requested engineering discipline and adapter settings.")] - //[Input("projectInfo", "Revit ProjectInfo to find a correspondent BHoM type.")] - //[Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] - //[Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] - //[Output("bHoMType", "A suitable BHoM type to convert the given Revit ProjectInfo to.")] + [Description("Finds a suitable BHoM type to convert the given Revit ParameterFilterElement to, based on the requested engineering discipline and adapter settings.")] + [Input("viewFilter", "Revit ParameterFilterElement to find a correspondent BHoM type.")] + [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + [Input("settings", "Revit adapter settings to be used while performing the search for the correspondent type.")] + [Output("bHoMType", "A suitable BHoM type to convert the given Revit ParameterFilterElement to.")] public static Type BHoMType(this ParameterFilterElement viewFilter, Discipline discipline, RevitSettings settings = null) { switch (discipline) From 99691d46499b549e66bccc05be692f0fb1cd89d0 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 12 Mar 2024 13:13:26 +0000 Subject: [PATCH 077/131] Minor updates to main new classes for View and filtering --- .../Convert/Revit/FromRevit/View.cs | 56 ++++++++++++++++--- .../Convert/Revit/FromRevit/ViewFilter.cs | 26 ++++++--- .../Revit/ToRevit/ParameterFilterElement.cs | 2 +- Revit_oM/Elements/View.cs | 3 +- Revit_oM/Views/FilterRule.cs | 2 +- 5 files changed, 70 insertions(+), 19 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index a1f58357d..84254b325 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -22,11 +22,19 @@ using Autodesk.Revit.DB; using BH.Engine.Adapters.Revit; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.Revit.Views; +using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using System.Xml.Linq; +using FilterRule = BH.oM.Revit.Views.FilterRule; +using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; +using View = Autodesk.Revit.DB.View; namespace BH.Revit.Engine.Core { @@ -36,20 +44,52 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] - //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] - public static oM.Adapters.Revit.Views.View ViewFromRevit(this View revitView, RevitSettings settings = null, Dictionary> refObjects = null) + [Description("Converts a Revit View to BH.oM.Adapters.Revit.Elements.View.")] + [Input("revitView", "Revit View to be converted.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("view", "BH.oM.Adapters.Revit.Elements.View resulting from converting the input Revit View.")] + public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, RevitSettings settings = null, Dictionary> refObjects = null) { settings = settings.DefaultIfNull(); - oM.Adapters.Revit.Views.View view = refObjects.GetValue(revitView.Id.IntegerValue); + oM.Adapters.Revit.Elements.View view = refObjects.GetValue(revitView.Id.IntegerValue); if (view != null) return view; - view = new oM.Adapters.Revit.Views.View { Name = revitView.Name }; + /* 1. Transfer NAME */ + view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name }; + + List filtersWithOverrides; + List viewFilters; + List overrides; + + List> categoriesNames=revitView.GetFilters() + .Select(elId => revitView.Document.GetElement(elId)) + .Cast() + .Select(pfe => pfe.GetCategories().ToList()) + .Select(catIdsList => catIdsList.Select(catId => revitView.Document.GetElement(catId).Name).ToList()) + .ToList>(); + + List filterRules = revitView.GetFilters() + .Select(elId => revitView.Document.GetElement(elId)) + .Cast() + .Select(epf => epf.GetRules()) + .ToDictionary(fvr => fvr.GetType(), + fvr => + { + Element param = revitView.Document.GetElement(fvr.GetRuleParameter()); + string paramName = param.Name; + string value = fvr.ToString(); + return new Array { paramName, value }; + }) + .ToList>() + .Select(kvp => new FilterRule { RuleType = FilterRuleType.BEGINSWITH, + ParameterName = kvp.Value[0], + Value = kvp.Value[1] }) + . + + //TODO: here goes the convertion method //Set identifiers, parameters & custom data diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index f763ce32b..35b8e78f7 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -27,6 +27,7 @@ using BH.oM.Base.Attributes; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; namespace BH.Revit.Engine.Core { @@ -36,11 +37,11 @@ public static partial class Convert /**** Public Methods ****/ /***************************************************/ - //[Description("Converts a Revit ViewPlan to BH.oM.Adapters.Revit.Elements.ViewPlan.")] - //[Input("revitViewPlan", "Revit ViewPlan to be converted.")] - //[Input("settings", "Revit adapter settings to be used while performing the convert.")] - //[Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - //[Output("viewPlan", "BH.oM.Adapters.Revit.Elements.ViewPlan resulting from converting the input Revit ViewPlan.")] + [Description("Converts a Revit ParameterFilterElement to BH.oM.Adapters.Revit.Elements.ViewFilter.")] + [Input("revitViewFilter", "Revit ParameterFilterElement to be converted.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("viewFilter", "BH.oM.Adapters.Revit.Elements.ViewFilter resulting from converting the input Revit ParameterFilterElement.")] public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this ParameterFilterElement revitViewFilter, RevitSettings settings = null, Dictionary> refObjects = null) { settings = settings.DefaultIfNull(); @@ -49,11 +50,20 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par if (viewFilter != null) return viewFilter; + /* 1. Transfer Filter NAME */ viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; - //TODO: here goes the convertion method + /* 2. Transfer List of CATEGORY NAMES */ + viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); + /* 3. Transfer List of FILTER RULES */ + ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => { string parameterName = revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString(); + ) + .ToList(); + - //Set identifiers, parameters & custom data - viewFilter.SetIdentifiers(revitViewFilter); + + //Set identifiers, parameters & custom data + viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); viewFilter.SetProperties(revitViewFilter, settings.MappingSettings); diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index dc5d78549..17405656c 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -94,7 +94,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - private static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { + public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { Autodesk.Revit.DB.FilterRule revitFilterRule = null; diff --git a/Revit_oM/Elements/View.cs b/Revit_oM/Elements/View.cs index ae7d48c58..a251c1811 100644 --- a/Revit_oM/Elements/View.cs +++ b/Revit_oM/Elements/View.cs @@ -4,8 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using BH.oM.Revit.Views; -namespace BH.oM.Adapters.Revit.Views +namespace BH.oM.Adapters.Revit.Elements { public class View : BHoMObject { diff --git a/Revit_oM/Views/FilterRule.cs b/Revit_oM/Views/FilterRule.cs index a6a1fc79b..a1b6b9c19 100644 --- a/Revit_oM/Views/FilterRule.cs +++ b/Revit_oM/Views/FilterRule.cs @@ -7,7 +7,7 @@ namespace BH.oM.Revit.Views { - public abstract class FilterRule : BHoMObject + public class FilterRule : BHoMObject { public virtual FilterRuleType RuleType { get; set; } public virtual string ParameterName { get; set; } From cd9f1aa571b86754fb9bcb3c6658f93b467ee36b Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sat, 20 Apr 2024 16:01:42 +0100 Subject: [PATCH 078/131] Add FilterRuleEvaluatorType Enumeration --- .../Convert/Revit/FromRevit/ViewFilter.cs | 17 ++++++++++------- Revit_oM/Views/FilterRuleEvaluatorType.cs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 Revit_oM/Views/FilterRuleEvaluatorType.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 35b8e78f7..352e6e211 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -25,6 +25,7 @@ using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.Revit.Views; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -55,18 +56,20 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 2. Transfer List of CATEGORY NAMES */ viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); /* 3. Transfer List of FILTER RULES */ - ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => { string parameterName = revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString(); - ) + //viewFilter.Rules + List parameterNames= ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); - + List ruleTypeNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => rule.GetType().ToString()) + .ToList(); + - //Set identifiers, parameters & custom data - viewFilter.SetIdentifiers(revitViewFilter); + //Set identifiers, parameters & custom data + viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); viewFilter.SetProperties(revitViewFilter, settings.MappingSettings); - refObjects.AddOrReplace(revitViewFilter.Id, viewFilter); return viewFilter; } diff --git a/Revit_oM/Views/FilterRuleEvaluatorType.cs b/Revit_oM/Views/FilterRuleEvaluatorType.cs new file mode 100644 index 000000000..68469da7d --- /dev/null +++ b/Revit_oM/Views/FilterRuleEvaluatorType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + internal class RuleEvaluatorType + { + } +} From 214fb7e9705f231e460776959359a65c6a0ac719 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sat, 20 Apr 2024 16:27:50 +0100 Subject: [PATCH 079/131] Add FilterValueRule and modify FilterRuleType To simplify the mirroring representation of the Revit API classes within the BHoM, it's necessary to add a concrete classe, subclass of FilterRule, that corresponds to the FilterValueRule from Revit API. Whatever sub-class type as well as Evaluator class type will be represented in BHoM via enumeration classes assigned to the RevitFilterRule and RevitFilterValueRule as attributes. --- Revit_oM/Views/FilterRuleType.cs | 21 ++++++++++----------- Revit_oM/Views/FilterValueRule.cs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 Revit_oM/Views/FilterValueRule.cs diff --git a/Revit_oM/Views/FilterRuleType.cs b/Revit_oM/Views/FilterRuleType.cs index 01119a1a0..565731a07 100644 --- a/Revit_oM/Views/FilterRuleType.cs +++ b/Revit_oM/Views/FilterRuleType.cs @@ -8,16 +8,15 @@ namespace BH.oM.Revit.Views { public enum FilterRuleType { - EQUALS, - GREATER, - GREATER_OR_EQUAL, - LESS, - LESS_OR_EQUAL, - CONTAINS, - NOT_CONTAINS, - BEGINSWITH, - NOT_BEGINSWITH, - ENDSWITH, - NOT_ENDSWITH + VALUE_STRINGRULE, + VALUE_NUMERICRULE_DOUBLE, + VALUE_NUMERICRULE_ELEMENTID, + VALUE_NUMERICRULE_INTEGER, + VALUE_GLOBALPARAMASSOCIATION, + INVERSE, + CATEGORY, + PARAMVALUEPRESENCE_NOVALUE, + PARAMVALUEPRESENCE_VALUE, + SHAREDPARAM_APPLICABLE } } diff --git a/Revit_oM/Views/FilterValueRule.cs b/Revit_oM/Views/FilterValueRule.cs new file mode 100644 index 000000000..f3005b663 --- /dev/null +++ b/Revit_oM/Views/FilterValueRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + internal class FilterValueRule + { + } +} From a8a659074423b2e933e06803052cdcde42a831b7 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Thu, 25 Apr 2024 16:52:10 +0100 Subject: [PATCH 080/131] Delete FilterRuleType Enum Instead of using a single class FilterRule with an Enumeration encapsulated to represent all the different Revit API Filter Rules, we go for creating multiple classes and sub-classes in BHoM as well, thus trying to match as much as possible the classes structure that is present in the API. --- Revit_oM/Views/FilterRuleType.cs | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 Revit_oM/Views/FilterRuleType.cs diff --git a/Revit_oM/Views/FilterRuleType.cs b/Revit_oM/Views/FilterRuleType.cs deleted file mode 100644 index 565731a07..000000000 --- a/Revit_oM/Views/FilterRuleType.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.oM.Revit.Views -{ - public enum FilterRuleType - { - VALUE_STRINGRULE, - VALUE_NUMERICRULE_DOUBLE, - VALUE_NUMERICRULE_ELEMENTID, - VALUE_NUMERICRULE_INTEGER, - VALUE_GLOBALPARAMASSOCIATION, - INVERSE, - CATEGORY, - PARAMVALUEPRESENCE_NOVALUE, - PARAMVALUEPRESENCE_VALUE, - SHAREDPARAM_APPLICABLE - } -} From 620b9c7924f205573188965544d6a4c654b870ff Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:27:43 +0100 Subject: [PATCH 081/131] Create FilterRule classes mirroring Revit API classes --- .../Revit/ToRevit/ParameterFilterElement.cs | 133 +++++++++++------- Revit_oM/Elements/FilterCategoryRule.cs | 13 ++ .../FilterDoubleRule.cs} | 5 +- Revit_oM/Elements/FilterIntegerRule.cs | 13 ++ Revit_oM/Elements/FilterLevelRule.cs | 16 +++ Revit_oM/Elements/FilterMaterialRule.cs | 13 ++ Revit_oM/Elements/FilterNumericValueRule.cs | 16 +++ .../FilterRule.cs} | 7 +- Revit_oM/Elements/FilterStringRule.cs | 14 ++ Revit_oM/Elements/FilterValueRule.cs | 15 ++ Revit_oM/Views/FilterRule.cs | 18 --- 11 files changed, 189 insertions(+), 74 deletions(-) create mode 100644 Revit_oM/Elements/FilterCategoryRule.cs rename Revit_oM/{Views/FilterValueRule.cs => Elements/FilterDoubleRule.cs} (59%) create mode 100644 Revit_oM/Elements/FilterIntegerRule.cs create mode 100644 Revit_oM/Elements/FilterLevelRule.cs create mode 100644 Revit_oM/Elements/FilterMaterialRule.cs create mode 100644 Revit_oM/Elements/FilterNumericValueRule.cs rename Revit_oM/{Views/FilterRuleEvaluatorType.cs => Elements/FilterRule.cs} (62%) create mode 100644 Revit_oM/Elements/FilterStringRule.cs create mode 100644 Revit_oM/Elements/FilterValueRule.cs delete mode 100644 Revit_oM/Views/FilterRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 17405656c..d2b0f5cac 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -22,19 +22,21 @@ using Autodesk.Revit.Creation; using Autodesk.Revit.DB; +using BH.oM.Adapters.Revit.Enums; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; -using BH.oM.Revit.Views; +using BH.oM.Revit.Elements; +using BH.oM.Revit.Enums; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; -using FilterRule = BH.oM.Revit.Views.FilterRule; +using FilterRule = BH.oM.Revit.Elements.FilterRule; namespace BH.Revit.Engine.Core { @@ -82,7 +84,9 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /* Via use of Streams*/ revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules - .Select(filterRule => filterRuleToRevit(document, filterRule)) + .Where(filterRule=> filterRule.GetType().IsSubclassOf(typeof(FilterValueRule))) + .Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) .Cast() .ToList())); @@ -94,7 +98,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,FilterRule filterRule) { + public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -105,57 +109,82 @@ public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document,F ElementId parameterId = new FilteredElementCollector(document) .WherePasses(logicalOrFilter) - .Where(par => par.Name.Equals(filterRule.ParameterName)) + .Where(par => par.Name.Equals(filterValueRule.ParameterName)) .First() .Id; + + + try + { + BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Revit.Elements.FilterStringRule)filterValueRule; + + switch (filterStringValueRule.Evaluator) + { + case TextComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + + case TextComparisonType.Contains: + revitFilterRule = ParameterFilterRuleFactory + .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.ContainsNot: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.StartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.EndsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case FilterRuleType.GREATER: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.GREATER_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.LESS: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.LESS_OR_EQUAL: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (ElementId)filterRule.Value); + break; + case FilterRuleType.NOT_BEGINSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string)filterRule.Value, false); + break; + case FilterRuleType.NOT_CONTAINS: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string)filterRule.Value, false); + break; + case FilterRuleType.NOT_ENDSWITH: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEndsWithRule(parameterId, (string)filterRule.Value, false); + break; + default: + break; + } + + } catch (Exception ex) + { + + } + + + - switch (filterRule.RuleType) { - case FilterRuleType.BEGINSWITH: - revitFilterRule=ParameterFilterRuleFactory - .CreateBeginsWithRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.CONTAINS: - revitFilterRule = ParameterFilterRuleFactory - .CreateContainsRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.ENDSWITH: - revitFilterRule = ParameterFilterRuleFactory - .CreateEndsWithRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.EQUALS: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, (int) filterRule.Value); - break; - case FilterRuleType.GREATER: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.GREATER_OR_EQUAL: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.LESS: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.LESS_OR_EQUAL: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (ElementId) filterRule.Value); - break; - case FilterRuleType.NOT_BEGINSWITH: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotBeginsWithRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.NOT_CONTAINS: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotContainsRule(parameterId, (string) filterRule.Value, false); - break; - case FilterRuleType.NOT_ENDSWITH: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEndsWithRule(parameterId, (string) filterRule.Value, false); - break; - default: - break;} return revitFilterRule; } diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/Elements/FilterCategoryRule.cs new file mode 100644 index 000000000..d5628fd5c --- /dev/null +++ b/Revit_oM/Elements/FilterCategoryRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public class FilterCategoryRule : FilterRule + { + public virtual List categoryNames { get; set; } + } +} diff --git a/Revit_oM/Views/FilterValueRule.cs b/Revit_oM/Elements/FilterDoubleRule.cs similarity index 59% rename from Revit_oM/Views/FilterValueRule.cs rename to Revit_oM/Elements/FilterDoubleRule.cs index f3005b663..3fcf2c561 100644 --- a/Revit_oM/Views/FilterValueRule.cs +++ b/Revit_oM/Elements/FilterDoubleRule.cs @@ -4,9 +4,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { - internal class FilterValueRule + public class FilterDoubleRule : FilterNumericValueRule { + } } diff --git a/Revit_oM/Elements/FilterIntegerRule.cs b/Revit_oM/Elements/FilterIntegerRule.cs new file mode 100644 index 000000000..a2c8bcb76 --- /dev/null +++ b/Revit_oM/Elements/FilterIntegerRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public class FilterIntegerRule : FilterNumericValueRule + { + + } +} diff --git a/Revit_oM/Elements/FilterLevelRule.cs b/Revit_oM/Elements/FilterLevelRule.cs new file mode 100644 index 000000000..4ef03af4e --- /dev/null +++ b/Revit_oM/Elements/FilterLevelRule.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BH.oM.Revit.Enums; + +namespace BH.oM.Revit.Elements +{ + public class FilterLevelRule : FilterRule + { + public virtual string LevelName { get; set; } + public virtual LevelComparisonType Evaluator { get; set; } + + } +} diff --git a/Revit_oM/Elements/FilterMaterialRule.cs b/Revit_oM/Elements/FilterMaterialRule.cs new file mode 100644 index 000000000..b6313e469 --- /dev/null +++ b/Revit_oM/Elements/FilterMaterialRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + public class FilterMaterialRule : FilterRule + { + public virtual string MaterialName { get; set; } + } +} diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/Elements/FilterNumericValueRule.cs new file mode 100644 index 000000000..6615732bb --- /dev/null +++ b/Revit_oM/Elements/FilterNumericValueRule.cs @@ -0,0 +1,16 @@ +using BH.oM.Adapters.Revit.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public class FilterNumericValueRule: FilterValueRule + { + public virtual NumberComparisonType evaluator { get; set; } + + + } +} diff --git a/Revit_oM/Views/FilterRuleEvaluatorType.cs b/Revit_oM/Elements/FilterRule.cs similarity index 62% rename from Revit_oM/Views/FilterRuleEvaluatorType.cs rename to Revit_oM/Elements/FilterRule.cs index 68469da7d..b2f4ffd9d 100644 --- a/Revit_oM/Views/FilterRuleEvaluatorType.cs +++ b/Revit_oM/Elements/FilterRule.cs @@ -1,4 +1,5 @@ -using System; +using BH.oM.Base; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,9 @@ namespace BH.oM.Revit.Views { - internal class RuleEvaluatorType + public abstract class FilterRule : BHoMObject { + } + } diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/Elements/FilterStringRule.cs new file mode 100644 index 000000000..5950dd5ff --- /dev/null +++ b/Revit_oM/Elements/FilterStringRule.cs @@ -0,0 +1,14 @@ +using BH.oM.Adapters.Revit.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public class FilterStringRule :FilterValueRule + { + public virtual TextComparisonType evaluator { get; set; } + } +} diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/Elements/FilterValueRule.cs new file mode 100644 index 000000000..17e53a916 --- /dev/null +++ b/Revit_oM/Elements/FilterValueRule.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Views +{ + public abstract class FilterValueRule : FilterRule + { + public virtual String parameterName { get; set; } + public virtual String value { get; set; } + + } +} diff --git a/Revit_oM/Views/FilterRule.cs b/Revit_oM/Views/FilterRule.cs deleted file mode 100644 index a1b6b9c19..000000000 --- a/Revit_oM/Views/FilterRule.cs +++ /dev/null @@ -1,18 +0,0 @@ -using BH.oM.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.oM.Revit.Views -{ - public class FilterRule : BHoMObject - { - public virtual FilterRuleType RuleType { get; set; } - public virtual string ParameterName { get; set; } - public virtual object Value { get; set; } - - } - -} From 045991f36d4ad27a7d067aae045584028c20728b Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:29:25 +0100 Subject: [PATCH 082/131] Move FillPattern and LinePattern to the Enums Namespace --- Revit_oM/{Views => Enums}/FillPattern.cs | 0 Revit_oM/{Views => Enums}/LinePattern.cs | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Revit_oM/{Views => Enums}/FillPattern.cs (100%) rename Revit_oM/{Views => Enums}/LinePattern.cs (100%) diff --git a/Revit_oM/Views/FillPattern.cs b/Revit_oM/Enums/FillPattern.cs similarity index 100% rename from Revit_oM/Views/FillPattern.cs rename to Revit_oM/Enums/FillPattern.cs diff --git a/Revit_oM/Views/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs similarity index 100% rename from Revit_oM/Views/LinePattern.cs rename to Revit_oM/Enums/LinePattern.cs From e08497644417e62ce054af66e0b947af423f1604 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:31:26 +0100 Subject: [PATCH 083/131] Modify BHoM Enum TextComparisonType Add NOT_START_WITH and NOT_ENDS_WITH enum values to the enumeration. These are required to implement the View Filtering in BHoM. --- Revit_oM/Enums/TextComparisonType.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Revit_oM/Enums/TextComparisonType.cs b/Revit_oM/Enums/TextComparisonType.cs index d0623cea4..c11575ca0 100644 --- a/Revit_oM/Enums/TextComparisonType.cs +++ b/Revit_oM/Enums/TextComparisonType.cs @@ -33,14 +33,18 @@ public enum TextComparisonType Equal, [Description("Check if input string and reference string are different.")] NotEqual, - [Description("Check if the input input string contains reference string.")] + [Description("Check if the input string contains the reference string.")] Contains, - [Description("Check if the input input string does not contain reference string.")] + [Description("Check if the input string does not contain the reference string.")] ContainsNot, - [Description("Check if the input input string starts with reference string.")] + [Description("Check if the input string starts with the reference string.")] StartsWith, - [Description("Check if the input input string ends with reference string.")] + [Description("Check if the input string does not start with the reference string ")] + NotStartsWith, + [Description("Check if the input string ends with the reference string.")] EndsWith, + [Description("Check if the input string does not end with the reference string")] + NotEndsWith } /***************************************************/ From 45d9b1c26b4633706cf67ac7eef8a37b738140e7 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 15:36:38 +0100 Subject: [PATCH 084/131] Add LevelComparisonType Enumeration Useful to create LevelFilterRule objects --- Revit_oM/Enums/LevelComparisonType.cs | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Revit_oM/Enums/LevelComparisonType.cs diff --git a/Revit_oM/Enums/LevelComparisonType.cs b/Revit_oM/Enums/LevelComparisonType.cs new file mode 100644 index 000000000..48c61c8ae --- /dev/null +++ b/Revit_oM/Enums/LevelComparisonType.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Enums +{ + /***************************************************/ + + [Description("Enumerator defining the way in which two levels are compared.")] + public enum LevelComparisonType + { + [Description("Check if input and reference level are at the same elevation.")] + Equal, + [Description("Check if input and reference level are at different elevations.")] + NotEqual, + [Description("Check if the input level is above the reference level.")] + Above, + [Description("Check if the input level is above or at the same elevation of the reference level.")] + AtOrAbove, + [Description("Check if the input level is below the reference level.")] + Below, + [Description("Check if the input level is below or at the same elevation of the reference level.")] + AtOrBelow, + } + + /***************************************************/ +} From ebe8d7b9a7f277c6d54c8824e00d1fdc65c1e8f0 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 17:29:09 +0100 Subject: [PATCH 085/131] Add conversion methods for FilterMaterialRule and FilterLevelRule in Convert.ToRevit Namespace --- .../Convert/Revit/FromRevit/View.cs | 2 +- .../Revit/ToRevit/ParameterFilterElement.cs | 132 ++++++++++++++---- Revit_oM/Elements/FilterCategoryRule.cs | 4 +- Revit_oM/Elements/FilterNumericValueRule.cs | 6 +- Revit_oM/Elements/FilterRule.cs | 2 +- Revit_oM/Elements/FilterStringRule.cs | 6 +- Revit_oM/Elements/FilterValueRule.cs | 6 +- Revit_oM/Elements/OverrideGraphicSettings.cs | 2 +- Revit_oM/Elements/ViewFilter.cs | 2 +- Revit_oM/Enums/FillPattern.cs | 2 +- Revit_oM/Enums/LinePattern.cs | 2 +- 11 files changed, 123 insertions(+), 43 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 84254b325..a34dae5eb 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -32,7 +32,7 @@ using System.ComponentModel; using System.Linq; using System.Xml.Linq; -using FilterRule = BH.oM.Revit.Views.FilterRule; +using FilterRule = BH.oM.Revit.Elements.FilterRule; using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; using View = Autodesk.Revit.DB.View; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index d2b0f5cac..b9f0c79e3 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -37,6 +37,7 @@ using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; using FilterRule = BH.oM.Revit.Elements.FilterRule; +using FilterStringRule = BH.oM.Revit.Elements.FilterStringRule; namespace BH.Revit.Engine.Core { @@ -98,23 +99,94 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + BuiltInParameter parameter = BuiltInParameter.MATERIAL_NAME; + + + //ParameterValueProvider provider = new ParameterValueProvider(new ElementId(parameter)); + revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); + + return revitFilterRule; + } + + + public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Revit.Elements.FilterLevelRule filterLevelRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; + BuiltInParameter elevationParam = BuiltInParameter.LEVEL_ELEV; + ElementId elevParamId=new ElementId(elevationParam); + Double levelElevation; + + try { + levelElevation=new FilteredElementCollector(document) + .OfCategory(BuiltInCategory.OST_Levels) + .Where(level => level.Name.ToUpper() == filterLevelRule.LevelName.ToUpper()) + .Cast() + .Select(level => level.Elevation) + .First(); + } catch (Exception ex){ + return null;} + + switch (filterLevelRule.Evaluator) + { + case LevelComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(elevParamId,(double)levelElevation, 0.001); + break; + case LevelComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.Above: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.AtOrAbove: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.Below: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(elevParamId, (double)levelElevation, 0.001); + break; + case LevelComparisonType.AtOrBelow: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(elevParamId, (double)levelElevation, 0.001); + break; + default: + break; + } + + return revitFilterRule; + + + } + + public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { + + /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; ElementClassFilter paramFilter = new ElementClassFilter(typeof(Parameter)); ElementClassFilter builtInParamFilter = new ElementClassFilter(typeof(BuiltInParameter)); LogicalOrFilter logicalOrFilter = new LogicalOrFilter(paramFilter, builtInParamFilter); - + /* 2. GET THE ELEMENT ID OF THE PARAMETER OBJECT */ ElementId parameterId = new FilteredElementCollector(document) .WherePasses(logicalOrFilter) .Where(par => par.Name.Equals(filterValueRule.ParameterName)) .First() .Id; - - try + /* 3. CREATE FILTER-RULES */ + + // Based on FilterStringRule... + if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Revit.Elements.FilterStringRule)filterValueRule; @@ -128,7 +200,6 @@ public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document revitFilterRule = ParameterFilterRuleFactory .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); break; - case TextComparisonType.Contains: revitFilterRule = ParameterFilterRuleFactory .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); @@ -141,49 +212,58 @@ public static Autodesk.Revit.DB.FilterValueRule filterValueRuleToRevit(Document revitFilterRule = ParameterFilterRuleFactory .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); break; + case TextComparisonType.NotStartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; case TextComparisonType.EndsWith: revitFilterRule = ParameterFilterRuleFactory .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); break; - case FilterRuleType.GREATER: + case TextComparisonType.NotEndsWith: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (ElementId)filterRule.Value); + .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + default: break; - case FilterRuleType.GREATER_OR_EQUAL: + } + + // Based on FilterNumericValueRule... + } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.Elements.FilterNumericValueRule))) + { + BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Revit.Elements.FilterNumericValueRule)filterValueRule; + + switch (filterNumericValueRule.Evaluator) + { + case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (ElementId)filterRule.Value); + .CreateEqualsRule(parameterId,(string)filterNumericValueRule.Value, false); break; - case FilterRuleType.LESS: + case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, (ElementId)filterRule.Value); + .CreateNotEqualsRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.LESS_OR_EQUAL: + case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (ElementId)filterRule.Value); + .CreateGreaterRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.NOT_BEGINSWITH: + case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotBeginsWithRule(parameterId, (string)filterRule.Value, false); + .CreateGreaterOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.NOT_CONTAINS: + case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateNotContainsRule(parameterId, (string)filterRule.Value, false); + .CreateLessRule(parameterId, (string)filterNumericValueRule.Value, false); break; - case FilterRuleType.NOT_ENDSWITH: + case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEndsWithRule(parameterId, (string)filterRule.Value, false); + .CreateLessOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); break; default: break; } - } catch (Exception ex) - { - - } - - - + } else { return null; } return revitFilterRule; diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/Elements/FilterCategoryRule.cs index d5628fd5c..6839e5326 100644 --- a/Revit_oM/Elements/FilterCategoryRule.cs +++ b/Revit_oM/Elements/FilterCategoryRule.cs @@ -4,10 +4,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { public class FilterCategoryRule : FilterRule { - public virtual List categoryNames { get; set; } + public virtual List CategoryNames { get; set; } } } diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/Elements/FilterNumericValueRule.cs index 6615732bb..14aa34daf 100644 --- a/Revit_oM/Elements/FilterNumericValueRule.cs +++ b/Revit_oM/Elements/FilterNumericValueRule.cs @@ -5,11 +5,11 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { - public class FilterNumericValueRule: FilterValueRule + public class FilterNumericValueRule : FilterValueRule { - public virtual NumberComparisonType evaluator { get; set; } + public virtual NumberComparisonType Evaluator { get; set; } } diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Elements/FilterRule.cs index b2f4ffd9d..567d22e54 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/Elements/FilterRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { public abstract class FilterRule : BHoMObject { diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/Elements/FilterStringRule.cs index 5950dd5ff..5ffb5c8ee 100644 --- a/Revit_oM/Elements/FilterStringRule.cs +++ b/Revit_oM/Elements/FilterStringRule.cs @@ -5,10 +5,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { - public class FilterStringRule :FilterValueRule + public class FilterStringRule : FilterValueRule { - public virtual TextComparisonType evaluator { get; set; } + public virtual TextComparisonType Evaluator { get; set; } } } diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/Elements/FilterValueRule.cs index 17e53a916..e47c16ad3 100644 --- a/Revit_oM/Elements/FilterValueRule.cs +++ b/Revit_oM/Elements/FilterValueRule.cs @@ -4,12 +4,12 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Elements { public abstract class FilterValueRule : FilterRule { - public virtual String parameterName { get; set; } - public virtual String value { get; set; } + public virtual string ParameterName { get; set; } + public virtual string Value { get; set; } } } diff --git a/Revit_oM/Elements/OverrideGraphicSettings.cs b/Revit_oM/Elements/OverrideGraphicSettings.cs index b2e205d57..99085dc18 100644 --- a/Revit_oM/Elements/OverrideGraphicSettings.cs +++ b/Revit_oM/Elements/OverrideGraphicSettings.cs @@ -1,5 +1,5 @@ using BH.oM.Base; -using BH.oM.Revit.Views; +using BH.oM.Revit.Enums; using System; using System.Collections.Generic; using System.Drawing; diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 943746066..9eb89989a 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,5 +1,5 @@ using BH.oM.Base; -using BH.oM.Revit.Views; +using BH.oM.Revit.Elements; using System; using System.Collections.Generic; using System.Linq; diff --git a/Revit_oM/Enums/FillPattern.cs b/Revit_oM/Enums/FillPattern.cs index 1e9451739..17efeff82 100644 --- a/Revit_oM/Enums/FillPattern.cs +++ b/Revit_oM/Enums/FillPattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Enums { public enum FillPattern { diff --git a/Revit_oM/Enums/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs index 6e1292999..1da829a39 100644 --- a/Revit_oM/Enums/LinePattern.cs +++ b/Revit_oM/Enums/LinePattern.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Views +namespace BH.oM.Revit.Enums { public enum LinePattern { From e8518057e49a446ba9bf1e0d8821769cd7325e7b Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 18:54:27 +0100 Subject: [PATCH 086/131] Update conversion of BHoM ViewFilters to Revit Parameter Filter Elements --- .../Revit/ToRevit/ParameterFilterElement.cs | 70 ++++++++++++++++--- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index b9f0c79e3..9fc43cdf5 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -22,6 +22,8 @@ using Autodesk.Revit.Creation; using Autodesk.Revit.DB; +using BH.Engine.Base; +using BH.Engine.Data; using BH.oM.Adapters.Revit.Enums; using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; @@ -80,26 +82,70 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /* 1.2 Create the ParameterFilterElement in the current Revit Document */ revitFilter = ParameterFilterElement.Create(document, filter.Name, categoryIdsList); - // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules - .Where(filterRule=> filterRule.GetType().IsSubclassOf(typeof(FilterValueRule))) - .Cast() - .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) - .Select(revitFilterRule => new ElementParameterFilter(revitFilterRule)) + .GroupBy(rule => rule.GetType()) + .ToDictionary(grp => grp.Key, grp => grp.ToList()) + .ToList() + .Select(kvp =>{ + + List filterRules = new List(); + + if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterCategoryRule))){ + filterRules = kvp.Value.Cast() + .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) + .ToList();} + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterValueRule))){ + filterRules = kvp.Value.Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) + .ToList();} + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterMaterialRule))){ + filterRules = kvp.Value.Cast() + .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) + .ToList();} + return filterRules; }) + .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) .Cast() .ToList())); + revitFilter.CopyParameters(filter, settings); refObjects.AddOrReplace(filter, revitFilter); return revitFilter; } + /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) + public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Revit.Elements.FilterCategoryRule filterCategoryRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ + List categoryIds = new FilteredElementCollector(document) + // Get all the Categories (INTERMEDIATE OPERATION) + .OfClass(typeof(Autodesk.Revit.DB.Category)) + // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) + .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) + // Cast down to Category Class Instances (INTERMEDIATE OPERATION) + .Cast() + // Get the ids of the retain categories (INTERMEDIATE OPERATION) + .Select(cat => cat.Id) + // Turn the Stream into a List (TERMINAL OPERATION) + .ToList(); + + /* 3. CREATE THE FILTER RULE */ + revitFilterRule = new Autodesk.Revit.DB.FilterCategoryRule(categoryIds); + + return revitFilterRule; + } + + /***************************************************/ + + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -113,6 +159,7 @@ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document do return revitFilterRule; } + /***************************************************/ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Revit.Elements.FilterLevelRule filterLevelRule) { @@ -122,6 +169,9 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum ElementId elevParamId=new ElementId(elevationParam); Double levelElevation; + /* 2. GET ELEVATION OF LEVEL CORRESPONDING TO INPUT LEVEL NAME */ + // Via Streams and withing a Try-Catch statement to make sure the code is compact and if the level is not found, we prevent any error + // being thrown when executing .First() while returning null instead. try { levelElevation=new FilteredElementCollector(document) .OfCategory(BuiltInCategory.OST_Levels) @@ -132,6 +182,9 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum } catch (Exception ex){ return null;} + /* 3. CREATE FILTERS RULE */ + + // Based on level's elevation and LevelComparisonType... switch (filterLevelRule.Evaluator) { case LevelComparisonType.Equal: @@ -163,9 +216,10 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum } return revitFilterRule; + } - } + /***************************************************/ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { @@ -183,7 +237,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum .First() .Id; - /* 3. CREATE FILTER-RULES */ + /* 3. CREATE FILTER-RULE */ // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) From 92f256f4453243e5b328f38a922052e0e35f1c35 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 21:36:09 +0100 Subject: [PATCH 087/131] Add enum values to TextComparisonType Enumeration Greater, GreaterOrEqual, Less, LessOrEqual are added to reflect the types and names of the subclasses of the Revit API class FilterStringRuleEvaluator --- Revit_oM/Enums/TextComparisonType.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Revit_oM/Enums/TextComparisonType.cs b/Revit_oM/Enums/TextComparisonType.cs index c11575ca0..90ba8da6c 100644 --- a/Revit_oM/Enums/TextComparisonType.cs +++ b/Revit_oM/Enums/TextComparisonType.cs @@ -44,7 +44,15 @@ public enum TextComparisonType [Description("Check if the input string ends with the reference string.")] EndsWith, [Description("Check if the input string does not end with the reference string")] - NotEndsWith + NotEndsWith, + [Description("Check if the input string is greater than the reference string.")] + Greater, + [Description("Check if the input string is greater or equal to the reference string")] + GreaterOrEqual, + [Description("Check if the input string is smaller to the reference string")] + Less, + [Description("Check if the input string is smaller or equal to the reference string")] + LessOrEqual } /***************************************************/ From b15705b7e1517c7b8300ed43d8b9632b70211b4e Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Fri, 26 Apr 2024 21:49:58 +0100 Subject: [PATCH 088/131] Update ToRevit ParameterFilterElement with additional TextComparisonType Enum Values Greater, GreaterOrEqual, Less, LessOrEqual --- .../Revit/ToRevit/ParameterFilterElement.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 9fc43cdf5..e03e9003c 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -278,6 +278,22 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum revitFilterRule = ParameterFilterRuleFactory .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); break; + case TextComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Less: + revitFilterRule=ParameterFilterRuleFactory + .CreateLessRule(parameterId,(string)filterStringValueRule.Value, false); + break; + case TextComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; default: break; } From f14e5303415a71c3e3b858682cc307a2b716b98b Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sat, 27 Apr 2024 19:17:50 +0100 Subject: [PATCH 089/131] Add adapter code for FilterRules in ViewFilterFromRevit Method in FromRevit Namespace --- .../Convert/Revit/FromRevit/View.cs | 10 +- .../Convert/Revit/FromRevit/ViewFilter.cs | 184 +++++++++++++++++- 2 files changed, 187 insertions(+), 7 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index a34dae5eb..0f14b9dfd 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -60,10 +60,7 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, /* 1. Transfer NAME */ view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name }; - List filtersWithOverrides; - List viewFilters; - List overrides; - + /* 2. Collect FILTER CATEGORY NAMES */ List> categoriesNames=revitView.GetFilters() .Select(elId => revitView.Document.GetElement(elId)) .Cast() @@ -71,6 +68,11 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, .Select(catIdsList => catIdsList.Select(catId => revitView.Document.GetElement(catId).Name).ToList()) .ToList>(); + + List filtersWithOverrides; + List viewFilters; + List overrides; + List filterRules = revitView.GetFilters() .Select(elId => revitView.Document.GetElement(elId)) .Cast() diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 352e6e211..03091f40c 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,9 +26,14 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; +using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using FilterRule = Autodesk.Revit.DB.FilterRule; +using System.CodeDom; +using System; +using Autodesk.Revit.DB.Architecture; namespace BH.Revit.Engine.Core { @@ -60,12 +65,185 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par List parameterNames= ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); - List ruleTypeNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => rule.GetType().ToString()) - .ToList(); + List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); + List bhomFilterRules = revitFilterRules.Select(revitRule => + { + // FILTER STRING RULE + if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + { + Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramValue = revitFilterStringRule.RuleString; + FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); + + TextComparisonType bhomEvaluator; + + switch (stringEvaluator.GetType()) + { + case typeof(Autodesk.Revit.DB.FilterStringBeginsWith): + bhomEvaluator = TextComparisonType.StartsWith; + break; + case typeof(Autodesk.Revit.DB.FilterStringEndsWith): + bhomEvaluator = TextComparisonType.EndsWith; + break; + case typeof(Autodesk.Revit.DB.FilterStringEquals): + bhomEvaluator = TextComparisonType.Equal; + break; + case typeof(Autodesk.Revit.DB.FilterStringContains): + bhomEvaluator = TextComparisonType.Contains; + break; + case typeof(Autodesk.Revit.DB.FilterStringGreater): + bhomEvaluator = TextComparisonType.Greater; + break; + case typeof(Autodesk.Revit.DB.FilterStringGreaterOrEqual): + bhomEvaluator = TextComparisonType.GreaterOrEqual; + break; + case typeof(Autodesk.Revit.DB.FilterStringLess): + bhomEvaluator = TextComparisonType.Less; + break; + case typeof(Autodesk.Revit.DB.FilterStringLessOrEqual): + bhomEvaluator = TextComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = paramName; + bhomFilterStringRule.Value = paramValue; + bhomFilterStringRule.Evaluator = bhomEvaluator; + + return bhomFilterStringRule; + } + + // FILTER DOUBLE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + { + Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); + + NumberComparisonType bhomEvaluator; + + switch (numericEvaluator.GetType()) + { + case typeof(Autodesk.Revit.DB.FilterNumericEquals): + bhomEvaluator = NumberComparisonType.Equal; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreater): + bhomEvaluator = NumberComparisonType.Greater; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): + bhomEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLess): + bhomEvaluator = NumberComparisonType.Less; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): + bhomEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = paramName; + bhomFilterDoubleRule.Value = paramValue; + bhomFilterDoubleRule.Evaluator = bhomEvaluator; + + return bhomFilterDoubleRule; + } + + // FILTER INTEGER RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + { + Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); + + NumberComparisonType bhomEvaluator; + + switch (numericEvaluator.GetType()) + { + case typeof(Autodesk.Revit.DB.FilterNumericEquals): + bhomEvaluator = NumberComparisonType.Equal; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreater): + bhomEvaluator = NumberComparisonType.Greater; + break; + case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): + bhomEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLess): + bhomEvaluator = NumberComparisonType.Less; + break; + case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): + bhomEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = paramName; + bhomFilterIntegerRule.Value = paramValue; + bhomFilterIntegerRule.Evaluator = bhomEvaluator; + + return bhomFilterIntegerRule; + } + + // FILTER CATEGORY RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + { + Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; + List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); + + BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); + bhomFilterCategoryRule.CategoryNames = categoryNames; + + return bhomFilterCategoryRule; + } + + // FILTER INVERSE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + { + Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; + Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); + TextComparisonType bhomTextEvaluator; + NumberComparisonType bhomNumberEvaluator; + + switch (innerRule.GetType()) + { + case (typeof(Autodesk.Revit.DB.FilterStringRule)): + switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType()) { + case (typeof(FilterStringEquals)): + bhomTextEvaluator = TextComparisonType.NotEqual; + break; + case (typeof(FilterStringBeginsWith)): + bhomTextEvaluator = TextComparisonType.NotStartsWith; + break; + case (typeof(FilterStringEndsWith)): + bhomTextEvaluator = TextComparisonType.NotEndsWith; + break; + case (typeof(FilterStringContains)): + bhomTextEvaluator = TextComparisonType.ContainsNot; + break; + default: + break;} + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule; + } + return ; + } + }); //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); From 167de7a35cd6b4aa413cbfe3d392a11ff68fc0bf Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 17:06:12 +0100 Subject: [PATCH 090/131] Add FilterElementIdRule to the Revit BHoM Objects --- Revit_oM/Elements/FilterElementIdRule.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Revit_oM/Elements/FilterElementIdRule.cs diff --git a/Revit_oM/Elements/FilterElementIdRule.cs b/Revit_oM/Elements/FilterElementIdRule.cs new file mode 100644 index 000000000..6012f2b70 --- /dev/null +++ b/Revit_oM/Elements/FilterElementIdRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.Elements +{ + internal class FilterElementIdRule + { + } +} From 49cb7b6028055a545fe1d868b360755778bc60e5 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 17:15:17 +0100 Subject: [PATCH 091/131] Add handling of FilterElementIdRule in conversion of ViewFilter From Revit --- .../Convert/Revit/FromRevit/ViewFilter.cs | 352 ++++++++++-------- 1 file changed, 195 insertions(+), 157 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 03091f40c..446b45d2c 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,11 +26,11 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; +using BH.oM.Revit.Elements; using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using FilterRule = Autodesk.Revit.DB.FilterRule; using System.CodeDom; using System; using Autodesk.Revit.DB.Architecture; @@ -62,186 +62,224 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); /* 3. Transfer List of FILTER RULES */ //viewFilter.Rules - List parameterNames= ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); List bhomFilterRules = revitFilterRules.Select(revitRule => { - // FILTER STRING RULE - if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) - { - Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; - string paramValue = revitFilterStringRule.RuleString; - FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); - - TextComparisonType bhomEvaluator; - - switch (stringEvaluator.GetType()) - { - case typeof(Autodesk.Revit.DB.FilterStringBeginsWith): - bhomEvaluator = TextComparisonType.StartsWith; - break; - case typeof(Autodesk.Revit.DB.FilterStringEndsWith): - bhomEvaluator = TextComparisonType.EndsWith; - break; - case typeof(Autodesk.Revit.DB.FilterStringEquals): - bhomEvaluator = TextComparisonType.Equal; - break; - case typeof(Autodesk.Revit.DB.FilterStringContains): - bhomEvaluator = TextComparisonType.Contains; - break; - case typeof(Autodesk.Revit.DB.FilterStringGreater): - bhomEvaluator = TextComparisonType.Greater; - break; - case typeof(Autodesk.Revit.DB.FilterStringGreaterOrEqual): - bhomEvaluator = TextComparisonType.GreaterOrEqual; - break; - case typeof(Autodesk.Revit.DB.FilterStringLess): - bhomEvaluator = TextComparisonType.Less; - break; - case typeof(Autodesk.Revit.DB.FilterStringLessOrEqual): - bhomEvaluator = TextComparisonType.LessOrEqual; - break; - default: - break; - } + TextComparisonType bhomTextEvaluator = 0; + NumberComparisonType bhomNumericEvaluator = 0; - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; - bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = paramName; - bhomFilterStringRule.Value = paramValue; - bhomFilterStringRule.Evaluator = bhomEvaluator; - - return bhomFilterStringRule; - } + // FILTER STRING RULE + if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + { + Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramValue = revitFilterStringRule.RuleString; + FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); - // FILTER DOUBLE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + switch (stringEvaluator.GetType().ToString()) { - Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; - string paramValue = revitFilterDoubleRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); - - NumberComparisonType bhomEvaluator; + case "Autodesk.Revit.DB.FilterStringBeginsWith": + bhomTextEvaluator = TextComparisonType.StartsWith; + break; + case "Autodesk.Revit.DB.FilterStringEndsWith": + bhomTextEvaluator = TextComparisonType.EndsWith; + break; + case "Autodesk.Revit.DB.FilterStringEquals": + bhomTextEvaluator = TextComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterStringContains": + bhomTextEvaluator = TextComparisonType.Contains; + break; + case "Autodesk.Revit.DB.FilterStringGreater": + bhomTextEvaluator = TextComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": + bhomTextEvaluator = TextComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterStringLess": + bhomTextEvaluator = TextComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterStringLessOrEqual": + bhomTextEvaluator = TextComparisonType.LessOrEqual; + break; + default: + break; + } - switch (numericEvaluator.GetType()) - { - case typeof(Autodesk.Revit.DB.FilterNumericEquals): - bhomEvaluator = NumberComparisonType.Equal; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreater): - bhomEvaluator = NumberComparisonType.Greater; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): - bhomEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLess): - bhomEvaluator = NumberComparisonType.Less; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): - bhomEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = paramName; + bhomFilterStringRule.Value = paramValue; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; - BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; - bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = paramName; - bhomFilterDoubleRule.Value = paramValue; - bhomFilterDoubleRule.Evaluator = bhomEvaluator; + return bhomFilterStringRule; + } - return bhomFilterDoubleRule; - } + // FILTER DOUBLE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + { + Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); - // FILTER INTEGER RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + switch (numericEvaluator.GetType().ToString()) { - Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; - string paramValue = revitFilterIntegerRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } - NumberComparisonType bhomEvaluator; + BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = paramName; + bhomFilterDoubleRule.Value = paramValue; + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; - switch (numericEvaluator.GetType()) - { - case typeof(Autodesk.Revit.DB.FilterNumericEquals): - bhomEvaluator = NumberComparisonType.Equal; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreater): - bhomEvaluator = NumberComparisonType.Greater; - break; - case typeof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual): - bhomEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLess): - bhomEvaluator = NumberComparisonType.Less; - break; - case typeof(Autodesk.Revit.DB.FilterNumericLessOrEqual): - bhomEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + return bhomFilterDoubleRule; + } - BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; - bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = paramName; - bhomFilterIntegerRule.Value = paramValue; - bhomFilterIntegerRule.Evaluator = bhomEvaluator; + // FILTER INTEGER RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + { + Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); - return bhomFilterIntegerRule; + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; } - // FILTER CATEGORY RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) - { - Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; - List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); + BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = paramName; + bhomFilterIntegerRule.Value = paramValue; + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; - BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; - bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); - bhomFilterCategoryRule.CategoryNames = categoryNames; + return bhomFilterIntegerRule; + } - return bhomFilterCategoryRule; - } + // FILTER CATEGORY RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + { + Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; + List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); - // FILTER INVERSE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) - { - Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; - Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); - TextComparisonType bhomTextEvaluator; - NumberComparisonType bhomNumberEvaluator; - - switch (innerRule.GetType()) - { - case (typeof(Autodesk.Revit.DB.FilterStringRule)): - switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType()) { - case (typeof(FilterStringEquals)): - bhomTextEvaluator = TextComparisonType.NotEqual; - break; - case (typeof(FilterStringBeginsWith)): - bhomTextEvaluator = TextComparisonType.NotStartsWith; - break; - case (typeof(FilterStringEndsWith)): - bhomTextEvaluator = TextComparisonType.NotEndsWith; - break; - case (typeof(FilterStringContains)): - bhomTextEvaluator = TextComparisonType.ContainsNot; - break; - default: - break;} - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule; + BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); + bhomFilterCategoryRule.CategoryNames = categoryNames; - } + return bhomFilterCategoryRule; + } - return ; - } + // FILTER INVERSE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + { + Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; + Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); + + switch (innerRule.GetType().ToString()) + { + case ("Autodesk.Revit.DB.FilterStringRule"): { + switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) { + case ("FilterStringEquals"): + bhomTextEvaluator = TextComparisonType.NotEqual; + break; + case ("FilterStringBeginsWith"): + bhomTextEvaluator = TextComparisonType.NotStartsWith; + break; + case ("FilterStringEndsWith"): + bhomTextEvaluator = TextComparisonType.NotEndsWith; + break; + case ("FilterStringContains"): + bhomTextEvaluator = TextComparisonType.ContainsNot; + break; + default: + break; } + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + return bhomFilterStringRule; } + case ("Autodesk.Revit.DB.FilterDoubleRule"): { + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator= NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break;} + BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + return bhomFilterDoubleRule;} + case ("Autodesk.Revit.DB.FilterIntegerRule"):{ + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()){ + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break;} + BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + return bhomFilterStringRule;} }); //Set identifiers, parameters & custom data From d4aa31a12d12b7668be18c1cf359134385e02681 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 17:30:26 +0100 Subject: [PATCH 092/131] Initialize FilterRule Classes in FromRevit and ToRevit Namespaces Instead of keeping the conversion of FilterRule objects from/to Revit/BHoM within the ParameterFilter/ViewFilter conversion classes only, we split the code in each different FilterRule Class keeping the code more modular and reusable. --- .../Convert/Revit/FromRevit/FilterCategoryRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterDoubleRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterElementIdRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterIntegerRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterInverseRule.cs | 12 ++++++++++++ .../Convert/Revit/FromRevit/FilterStringRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterCategoryRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterDoubleRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterElementIdRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterIntegerRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterInverseRule.cs | 12 ++++++++++++ .../Convert/Revit/ToRevit/FilterStringRule.cs | 12 ++++++++++++ 12 files changed, 144 insertions(+) create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs create mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs new file mode 100644 index 000000000..5f673d9f0 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterCategoryRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs new file mode 100644 index 000000000..92e03930f --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterDoubleRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs new file mode 100644 index 000000000..4941f781c --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterElementIdRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs new file mode 100644 index 000000000..a2dfb88db --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterIntegerRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs new file mode 100644 index 000000000..6562f897d --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterInverseRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs new file mode 100644 index 000000000..f2efab1e1 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit +{ + internal class FilterStringRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs new file mode 100644 index 000000000..820ee9b17 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterCategoryRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs new file mode 100644 index 000000000..a629d739e --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterDoubleRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs new file mode 100644 index 000000000..a9d6ee96d --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterElementIdRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs new file mode 100644 index 000000000..9b5a1e1da --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterIntegerRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs new file mode 100644 index 000000000..00aea9676 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterInverseRule + { + } +} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs new file mode 100644 index 000000000..e4b2c8aa0 --- /dev/null +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit +{ + internal class FilterStringRule + { + } +} From f65b8025d068b7002f944b213ba6c1537a9912c1 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:04:08 +0100 Subject: [PATCH 093/131] Delete all FilterRule classes created in the Convert.FromRevit/ToRevit namespaces. Any class that can be stored in the Convert.FromRevit/ToRevit namespace, has to be convertible into Revit.DB.Element Class. Since FilterRule classes are not convertible into Revit.DB.Elements, they cannot be present in the Convert.FromRevit/ToRevit. --- .../Revit/FromRevit/FilterCategoryRule.cs | 12 --- .../Revit/FromRevit/FilterDoubleRule.cs | 12 --- .../Revit/FromRevit/FilterElementIdRule.cs | 12 --- .../Revit/FromRevit/FilterIntegerRule.cs | 12 --- .../Revit/FromRevit/FilterInverseRule.cs | 12 --- .../Revit/FromRevit/FilterStringRule.cs | 12 --- .../Convert/Revit/FromRevit/ViewFilter.cs | 78 +++++++++++++++++-- .../Revit/ToRevit/FilterCategoryRule.cs | 12 --- .../Convert/Revit/ToRevit/FilterDoubleRule.cs | 12 --- .../Revit/ToRevit/FilterElementIdRule.cs | 12 --- .../Revit/ToRevit/FilterIntegerRule.cs | 12 --- .../Revit/ToRevit/FilterInverseRule.cs | 12 --- .../Convert/Revit/ToRevit/FilterStringRule.cs | 12 --- .../Revit/ToRevit/ParameterFilterElement.cs | 24 ------ Revit_oM/Elements/FilterCategoryRule.cs | 2 +- Revit_oM/Elements/FilterDoubleRule.cs | 2 +- Revit_oM/Elements/FilterElementIdRule.cs | 4 +- Revit_oM/Elements/FilterIntegerRule.cs | 2 +- Revit_oM/Elements/FilterLevelRule.cs | 2 +- Revit_oM/Elements/FilterMaterialRule.cs | 2 +- Revit_oM/Elements/FilterNumericValueRule.cs | 2 +- Revit_oM/Elements/FilterRule.cs | 2 +- Revit_oM/Elements/FilterStringRule.cs | 2 +- Revit_oM/Elements/FilterValueRule.cs | 2 +- 24 files changed, 83 insertions(+), 185 deletions(-) delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs delete mode 100644 Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs deleted file mode 100644 index 5f673d9f0..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterCategoryRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterCategoryRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs deleted file mode 100644 index 92e03930f..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterDoubleRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterDoubleRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs deleted file mode 100644 index 4941f781c..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterElementIdRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterElementIdRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs deleted file mode 100644 index a2dfb88db..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterIntegerRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterIntegerRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs deleted file mode 100644 index 6562f897d..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterInverseRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterInverseRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs deleted file mode 100644 index f2efab1e1..000000000 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/FilterStringRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.FromRevit -{ - internal class FilterStringRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 446b45d2c..f32aa1f52 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -194,6 +194,44 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par return bhomFilterIntegerRule; } + // FILTER ELEMENTID RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) + { + Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; + string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; + string paramValue = revitFilterElemIdRule.RuleValue.ToString(); + FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); + + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; + bhomFilterElemIdRule = new oM.Revit.Elements.FilterElementIdRule(); + bhomFilterElemIdRule.ParameterName = paramName; + bhomFilterElemIdRule.Value = paramValue; + bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterElemIdRule; + } + // FILTER CATEGORY RULE else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) { @@ -275,13 +313,41 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par case ("FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break;} - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; - return bhomFilterStringRule;} + BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + return bhomFilterIntegerRule;} + case ("Autodesk.Revit.DB.FilterElementIdRule"): + { + switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new oM.Revit.Elements.FilterElementIdRule(); + bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); + bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; + return bhomFilterElementIdRule; + } + + - }); + }); //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs deleted file mode 100644 index 820ee9b17..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterCategoryRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterCategoryRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs deleted file mode 100644 index a629d739e..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterDoubleRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterDoubleRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs deleted file mode 100644 index a9d6ee96d..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterElementIdRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterElementIdRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs deleted file mode 100644 index 9b5a1e1da..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterIntegerRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterIntegerRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs deleted file mode 100644 index 00aea9676..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterInverseRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterInverseRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs deleted file mode 100644 index e4b2c8aa0..000000000 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/FilterStringRule.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Revit.Engine.Core.Convert.Revit.ToRevit -{ - internal class FilterStringRule - { - } -} diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index e03e9003c..a905e0945 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -119,30 +119,6 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Revit.Elements.FilterCategoryRule filterCategoryRule) - { - /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ - Autodesk.Revit.DB.FilterRule revitFilterRule = null; - - /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ - List categoryIds = new FilteredElementCollector(document) - // Get all the Categories (INTERMEDIATE OPERATION) - .OfClass(typeof(Autodesk.Revit.DB.Category)) - // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) - .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) - // Cast down to Category Class Instances (INTERMEDIATE OPERATION) - .Cast() - // Get the ids of the retain categories (INTERMEDIATE OPERATION) - .Select(cat => cat.Id) - // Turn the Stream into a List (TERMINAL OPERATION) - .ToList(); - - /* 3. CREATE THE FILTER RULE */ - revitFilterRule = new Autodesk.Revit.DB.FilterCategoryRule(categoryIds); - - return revitFilterRule; - } - /***************************************************/ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/Elements/FilterCategoryRule.cs index 6839e5326..8e5bdf13d 100644 --- a/Revit_oM/Elements/FilterCategoryRule.cs +++ b/Revit_oM/Elements/FilterCategoryRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterCategoryRule : FilterRule { diff --git a/Revit_oM/Elements/FilterDoubleRule.cs b/Revit_oM/Elements/FilterDoubleRule.cs index 3fcf2c561..8b4b59a35 100644 --- a/Revit_oM/Elements/FilterDoubleRule.cs +++ b/Revit_oM/Elements/FilterDoubleRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterDoubleRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterElementIdRule.cs b/Revit_oM/Elements/FilterElementIdRule.cs index 6012f2b70..6d1ff5b18 100644 --- a/Revit_oM/Elements/FilterElementIdRule.cs +++ b/Revit_oM/Elements/FilterElementIdRule.cs @@ -4,9 +4,9 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { - internal class FilterElementIdRule + public class FilterElementIdRule : FilterNumericValueRule { } } diff --git a/Revit_oM/Elements/FilterIntegerRule.cs b/Revit_oM/Elements/FilterIntegerRule.cs index a2c8bcb76..dbcf8313d 100644 --- a/Revit_oM/Elements/FilterIntegerRule.cs +++ b/Revit_oM/Elements/FilterIntegerRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterIntegerRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterLevelRule.cs b/Revit_oM/Elements/FilterLevelRule.cs index 4ef03af4e..4e244aec9 100644 --- a/Revit_oM/Elements/FilterLevelRule.cs +++ b/Revit_oM/Elements/FilterLevelRule.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using BH.oM.Revit.Enums; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterLevelRule : FilterRule { diff --git a/Revit_oM/Elements/FilterMaterialRule.cs b/Revit_oM/Elements/FilterMaterialRule.cs index b6313e469..3c86f85c0 100644 --- a/Revit_oM/Elements/FilterMaterialRule.cs +++ b/Revit_oM/Elements/FilterMaterialRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterMaterialRule : FilterRule { diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/Elements/FilterNumericValueRule.cs index 14aa34daf..4a07b6e98 100644 --- a/Revit_oM/Elements/FilterNumericValueRule.cs +++ b/Revit_oM/Elements/FilterNumericValueRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterNumericValueRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/Elements/FilterRule.cs index 567d22e54..187db502a 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/Elements/FilterRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public abstract class FilterRule : BHoMObject { diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/Elements/FilterStringRule.cs index 5ffb5c8ee..9189bfc94 100644 --- a/Revit_oM/Elements/FilterStringRule.cs +++ b/Revit_oM/Elements/FilterStringRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public class FilterStringRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/Elements/FilterValueRule.cs index e47c16ad3..684616ba8 100644 --- a/Revit_oM/Elements/FilterValueRule.cs +++ b/Revit_oM/Elements/FilterValueRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Revit.Elements +namespace BH.oM.Adapters.Revit.Elements { public abstract class FilterValueRule : FilterRule { From 0d761a225d0301570ae31f15f0c384a9f9c33deb Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:33:31 +0100 Subject: [PATCH 094/131] Reinstate the method filterCategoryRuleToRevit in the Convert.ToRevit.ParameterFilterElement Class. Deleted previously by mistake. --- .../Revit/ToRevit/ParameterFilterElement.cs | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a905e0945..a0f28fefc 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -93,16 +93,16 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterCategoryRule))){ - filterRules = kvp.Value.Cast() + if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterCategoryRule))){ + filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterValueRule))){ - filterRules = kvp.Value.Cast() + else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterValueRule))){ + filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.Elements.FilterMaterialRule))){ - filterRules = kvp.Value.Cast() + else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterMaterialRule))){ + filterRules = kvp.Value.Cast< BH.oM.Adapters.Revit.Elements.FilterMaterialRule >() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList();} return filterRules; }) @@ -119,9 +119,34 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document,BH.oM.Revit.Elements.FilterMaterialRule filterMaterialRule) + public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterCategoryRule filterCategoryRule) + { + /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; + + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ + List categoryIds = new FilteredElementCollector(document) + // Get all the Categories (INTERMEDIATE OPERATION) + .OfClass(typeof(Autodesk.Revit.DB.Category)) + // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) + .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) + // Cast down to Category Class Instances (INTERMEDIATE OPERATION) + .Cast() + // Get the ids of the retain categories (INTERMEDIATE OPERATION) + .Select(cat => cat.Id) + // Turn the Stream into a List (TERMINAL OPERATION) + .ToList(); + + /* 3. CREATE THE FILTER RULE */ + revitFilterRule = new Autodesk.Revit.DB.FilterCategoryRule(categoryIds); + + return revitFilterRule; + } + + /***************************************************/ + + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -137,7 +162,7 @@ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Revit.Elements.FilterLevelRule filterLevelRule) + public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterLevelRule filterLevelRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -198,7 +223,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Revit.Elements.FilterValueRule filterValueRule) { + public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Adapters.Revit.Elements.FilterValueRule filterValueRule) { /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -218,7 +243,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { - BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Revit.Elements.FilterStringRule)filterValueRule; + BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; switch (filterStringValueRule.Evaluator) { @@ -275,9 +300,9 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum } // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.Elements.FilterNumericValueRule))) + } else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterNumericValueRule))) { - BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Revit.Elements.FilterNumericValueRule)filterValueRule; + BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; switch (filterNumericValueRule.Evaluator) { From 4c9918d72b2eb2b60943307d25875af832be9c6f Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:54:41 +0100 Subject: [PATCH 095/131] Add method to convert a Revit ParameterFilterElement into a BHoM ViewFilter. --- Revit_Core_Engine/Convert/FromRevit.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Revit_Core_Engine/Convert/FromRevit.cs b/Revit_Core_Engine/Convert/FromRevit.cs index 66f80fe35..715afb7da 100644 --- a/Revit_Core_Engine/Convert/FromRevit.cs +++ b/Revit_Core_Engine/Convert/FromRevit.cs @@ -70,6 +70,28 @@ public static IGeometry IFromRevit(this Location location) /**** Convert Revit elements to BHoM ****/ /***************************************************/ + [Description("Converts a Revit ParameterFilterElement to a BHoM object based on the requested engineering discipline.")] + [Input("parameterFilterElement", "Revit ParameterFilterElement to be converted.")] + [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] + [Input("transform", "Optional, a transform to apply to the converted object.")] + [Input("settings", "Revit adapter settings to be used while performing the convert.")] + [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] + [Output("fromRevit", "Resulted BHoM object converted from a Revit ParameterFilterElement.")] + public static List FromRevit(this ParameterFilterElement parameterFilterElement, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary> refObjects = null) + { + if (parameterFilterElement == null) + { + BH.Engine.Base.Compute.RecordWarning("BHoM object could not be read because Revit Parameter Filter Element is null."); + return null; + } + else + { + return new List { ViewFilterFromRevit(parameterFilterElement, settings, refObjects) }; + } + } + + /***************************************************/ + [Description("Converts a Revit EnergyAnalysisDetailModel to a BHoM object based on the requested engineering discipline.")] [Input("energyAnalysisModel", "Revit EnergyAnalysisDetailModel to be converted.")] [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] From 223768c1a300eddb543cb926fbfeb1d27ead18d3 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 18:56:10 +0100 Subject: [PATCH 096/131] Incorporate minor fixes to references between classes --- .../Convert/Revit/FromRevit/ViewFilter.cs | 32 +++++++++---------- .../Revit/ToRevit/ParameterFilterElement.cs | 10 +++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index f32aa1f52..bf9478cf1 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,7 +26,7 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; -using BH.oM.Revit.Elements; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; @@ -66,7 +66,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); - List bhomFilterRules = revitFilterRules.Select(revitRule => + List bhomFilterRules = revitFilterRules.Select(revitRule => { TextComparisonType bhomTextEvaluator = 0; NumberComparisonType bhomNumericEvaluator = 0; @@ -109,8 +109,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule; - bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); bhomFilterStringRule.ParameterName = paramName; bhomFilterStringRule.Value = paramValue; bhomFilterStringRule.Evaluator = bhomTextEvaluator; @@ -147,8 +147,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; - bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = paramName; bhomFilterDoubleRule.Value = paramValue; bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; @@ -185,8 +185,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; - bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = paramName; bhomFilterIntegerRule.Value = paramValue; bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; @@ -223,8 +223,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; } - BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; - bhomFilterElemIdRule = new oM.Revit.Elements.FilterElementIdRule(); + BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; + bhomFilterElemIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); bhomFilterElemIdRule.ParameterName = paramName; bhomFilterElemIdRule.Value = paramValue; bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; @@ -238,8 +238,8 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); - BH.oM.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; - bhomFilterCategoryRule = new oM.Revit.Elements.FilterCategoryRule(); + BH.oM.Adapters.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new BH.oM.Adapters.Revit.Elements.FilterCategoryRule(); bhomFilterCategoryRule.CategoryNames = categoryNames; return bhomFilterCategoryRule; @@ -269,7 +269,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par break; default: break; } - BH.oM.Revit.Elements.FilterStringRule bhomFilterStringRule = new oM.Revit.Elements.FilterStringRule(); + BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; bhomFilterStringRule.Evaluator = bhomTextEvaluator; @@ -291,7 +291,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par case ("FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break;} - BH.oM.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new oM.Revit.Elements.FilterDoubleRule(); + BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; @@ -313,7 +313,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par case ("FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break;} - BH.oM.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new oM.Revit.Elements.FilterIntegerRule(); + BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; @@ -338,7 +338,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } - BH.oM.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new oM.Revit.Elements.FilterElementIdRule(); + BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a0f28fefc..836a8b59d 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -30,7 +30,7 @@ using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; -using BH.oM.Revit.Elements; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Revit.Enums; using System; using System.Collections.Generic; @@ -38,8 +38,8 @@ using System.Linq; using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; -using FilterRule = BH.oM.Revit.Elements.FilterRule; -using FilterStringRule = BH.oM.Revit.Elements.FilterStringRule; +using FilterRule = BH.oM.Adapters.Revit.Elements.FilterRule; +using FilterStringRule = BH.oM.Adapters.Revit.Elements.FilterStringRule; namespace BH.Revit.Engine.Core { @@ -243,7 +243,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { - BH.oM.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; + BH.oM.Adapters.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; switch (filterStringValueRule.Evaluator) { @@ -302,7 +302,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterNumericValueRule... } else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterNumericValueRule))) { - BH.oM.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; + BH.oM.Adapters.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; switch (filterNumericValueRule.Evaluator) { From 0c1c4bf8f0d172a87150a140adc222e545e0ef58 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Sun, 28 Apr 2024 19:29:58 +0100 Subject: [PATCH 097/131] Add ParameterValuePresenceRule Add it as BHoM Class and implement code for conversion to/from Revit --- .../Convert/Revit/FromRevit/ViewFilter.cs | 12 ++++++++++++ .../Revit/ToRevit/ParameterFilterElement.cs | 12 ++++++++++++ Revit_oM/Elements/ParameterValuePresenceRule.cs | 14 ++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 Revit_oM/Elements/ParameterValuePresenceRule.cs diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index bf9478cf1..baa3ec31e 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -245,6 +245,18 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par return bhomFilterCategoryRule; } + // FILTER PARAMETER VALUE PRESENCE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) + { + BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule bhomParamValuePresenceRule; + bhomParamValuePresenceRule = new BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule(); + + bhomParamValuePresenceRule.ParameterName= revitViewFilter.Document.GetElement(((Autodesk.Revit.DB.ParameterValuePresenceRule)revitRule).Parameter).Name; + bhomParamValuePresenceRule.IsPresent = (revitRule.GetType() == typeof(HasValueFilterRule)) ? true : false; + + return bhomParamValuePresenceRule; + } + // FILTER INVERSE RULE else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) { diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 836a8b59d..2e2624a8d 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -333,6 +333,18 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum default: break; } + } + + // Based on ParameterValuePresenceRule... + else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule))) + { + BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule parameterValuePresenceRule = (BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule)filterValueRule; + + if (parameterValuePresenceRule.IsPresent) { + revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId);} + else { + revitFilterRule = ParameterFilterRuleFactory.CreateHasNoValueParameterRule(parameterId);} + } else { return null; } diff --git a/Revit_oM/Elements/ParameterValuePresenceRule.cs b/Revit_oM/Elements/ParameterValuePresenceRule.cs new file mode 100644 index 000000000..ffdc94241 --- /dev/null +++ b/Revit_oM/Elements/ParameterValuePresenceRule.cs @@ -0,0 +1,14 @@ +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Adapters.Revit.Elements +{ + public class ParameterValuePresenceRule : FilterValueRule + { + public virtual bool IsPresent { get; set; } + } +} From 76bf7ec3bb1c7ad95354f0e6301b0cca1bf32c53 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 15:45:21 +0100 Subject: [PATCH 098/131] Move all BHoM Filter Rules from oM.Elements to oM.FilterRules namespace. In the oM.Elements namespace we can store only the BHoM object that have a direct corresponding object in Revit. --- .../Revit/ToRevit/ParameterFilterElement.cs | 36 +++++++++---------- Revit_oM/Elements/ViewFilter.cs | 1 + .../FilterCategoryRule.cs | 2 +- .../FilterDoubleRule.cs | 2 +- .../FilterElementIdRule.cs | 2 +- .../FilterIntegerRule.cs | 2 +- .../FilterLevelRule.cs | 2 +- .../FilterMaterialRule.cs | 2 +- .../FilterNumericValueRule.cs | 2 +- .../{Elements => FilterRules}/FilterRule.cs | 2 +- .../FilterStringRule.cs | 2 +- .../FilterValueRule.cs | 2 +- .../ParameterValuePresenceRule.cs | 4 +-- 13 files changed, 31 insertions(+), 30 deletions(-) rename Revit_oM/{Elements => FilterRules}/FilterCategoryRule.cs (86%) rename Revit_oM/{Elements => FilterRules}/FilterDoubleRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterElementIdRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterIntegerRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterLevelRule.cs (89%) rename Revit_oM/{Elements => FilterRules}/FilterMaterialRule.cs (85%) rename Revit_oM/{Elements => FilterRules}/FilterNumericValueRule.cs (88%) rename Revit_oM/{Elements => FilterRules}/FilterRule.cs (83%) rename Revit_oM/{Elements => FilterRules}/FilterStringRule.cs (87%) rename Revit_oM/{Elements => FilterRules}/FilterValueRule.cs (88%) rename Revit_oM/{Elements => FilterRules}/ParameterValuePresenceRule.cs (69%) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 2e2624a8d..7bb739841 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -30,16 +30,16 @@ using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; using BH.oM.Physical.Elements; -using BH.oM.Adapters.Revit.Elements; using BH.oM.Revit.Enums; +using BH.oM.Revit.FilterRules; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using Document = Autodesk.Revit.DB.Document; -using FilterRule = BH.oM.Adapters.Revit.Elements.FilterRule; -using FilterStringRule = BH.oM.Adapters.Revit.Elements.FilterStringRule; +using FilterRule = BH.oM.Revit.FilterRules.FilterRule; +using FilterStringRule = BH.oM.Revit.FilterRules.FilterStringRule; namespace BH.Revit.Engine.Core { @@ -93,16 +93,16 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterCategoryRule))){ - filterRules = kvp.Value.Cast() + if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))){ + filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterValueRule))){ - filterRules = kvp.Value.Cast() + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))){ + filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterMaterialRule))){ - filterRules = kvp.Value.Cast< BH.oM.Adapters.Revit.Elements.FilterMaterialRule >() + else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))){ + filterRules = kvp.Value.Cast() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList();} return filterRules; }) @@ -120,7 +120,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterCategoryRule filterCategoryRule) + public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, oM.Revit.FilterRules.FilterCategoryRule filterCategoryRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -146,7 +146,7 @@ public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterMaterialRule filterMaterialRule) + public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -162,7 +162,7 @@ public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, BH.oM.Adapters.Revit.Elements.FilterLevelRule filterLevelRule) + public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, FilterLevelRule filterLevelRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -223,7 +223,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,BH.oM.Adapters.Revit.Elements.FilterValueRule filterValueRule) { + public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -243,7 +243,7 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum // Based on FilterStringRule... if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { - BH.oM.Adapters.Revit.Elements.FilterStringRule filterStringValueRule = (BH.oM.Adapters.Revit.Elements.FilterStringRule)filterValueRule; + FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; switch (filterStringValueRule.Evaluator) { @@ -300,9 +300,9 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum } // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.FilterNumericValueRule))) + } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { - BH.oM.Adapters.Revit.Elements.FilterNumericValueRule filterNumericValueRule = (BH.oM.Adapters.Revit.Elements.FilterNumericValueRule)filterValueRule; + oM.Revit.FilterRules.FilterNumericValueRule filterNumericValueRule = (oM.Revit.FilterRules.FilterNumericValueRule)filterValueRule; switch (filterNumericValueRule.Evaluator) { @@ -336,9 +336,9 @@ public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docum } // Based on ParameterValuePresenceRule... - else if (filterValueRule.GetType().IsSubclassOf(typeof(BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule))) + else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) { - BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule parameterValuePresenceRule = (BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule)filterValueRule; + oM.Revit.FilterRules.ParameterValuePresenceRule parameterValuePresenceRule = (oM.Revit.FilterRules.ParameterValuePresenceRule)filterValueRule; if (parameterValuePresenceRule.IsPresent) { revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId);} diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 9eb89989a..a33b5bb16 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,5 +1,6 @@ using BH.oM.Base; using BH.oM.Revit.Elements; +using BH.oM.Revit.FilterRules; using System; using System.Collections.Generic; using System.Linq; diff --git a/Revit_oM/Elements/FilterCategoryRule.cs b/Revit_oM/FilterRules/FilterCategoryRule.cs similarity index 86% rename from Revit_oM/Elements/FilterCategoryRule.cs rename to Revit_oM/FilterRules/FilterCategoryRule.cs index 8e5bdf13d..6e96aa1e7 100644 --- a/Revit_oM/Elements/FilterCategoryRule.cs +++ b/Revit_oM/FilterRules/FilterCategoryRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterCategoryRule : FilterRule { diff --git a/Revit_oM/Elements/FilterDoubleRule.cs b/Revit_oM/FilterRules/FilterDoubleRule.cs similarity index 83% rename from Revit_oM/Elements/FilterDoubleRule.cs rename to Revit_oM/FilterRules/FilterDoubleRule.cs index 8b4b59a35..5a1b38436 100644 --- a/Revit_oM/Elements/FilterDoubleRule.cs +++ b/Revit_oM/FilterRules/FilterDoubleRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterDoubleRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterElementIdRule.cs b/Revit_oM/FilterRules/FilterElementIdRule.cs similarity index 83% rename from Revit_oM/Elements/FilterElementIdRule.cs rename to Revit_oM/FilterRules/FilterElementIdRule.cs index 6d1ff5b18..4aff13a04 100644 --- a/Revit_oM/Elements/FilterElementIdRule.cs +++ b/Revit_oM/FilterRules/FilterElementIdRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterElementIdRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterIntegerRule.cs b/Revit_oM/FilterRules/FilterIntegerRule.cs similarity index 83% rename from Revit_oM/Elements/FilterIntegerRule.cs rename to Revit_oM/FilterRules/FilterIntegerRule.cs index dbcf8313d..7de43b6ec 100644 --- a/Revit_oM/Elements/FilterIntegerRule.cs +++ b/Revit_oM/FilterRules/FilterIntegerRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterIntegerRule : FilterNumericValueRule { diff --git a/Revit_oM/Elements/FilterLevelRule.cs b/Revit_oM/FilterRules/FilterLevelRule.cs similarity index 89% rename from Revit_oM/Elements/FilterLevelRule.cs rename to Revit_oM/FilterRules/FilterLevelRule.cs index 4e244aec9..5745b4b1d 100644 --- a/Revit_oM/Elements/FilterLevelRule.cs +++ b/Revit_oM/FilterRules/FilterLevelRule.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using BH.oM.Revit.Enums; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterLevelRule : FilterRule { diff --git a/Revit_oM/Elements/FilterMaterialRule.cs b/Revit_oM/FilterRules/FilterMaterialRule.cs similarity index 85% rename from Revit_oM/Elements/FilterMaterialRule.cs rename to Revit_oM/FilterRules/FilterMaterialRule.cs index 3c86f85c0..2214b22c7 100644 --- a/Revit_oM/Elements/FilterMaterialRule.cs +++ b/Revit_oM/FilterRules/FilterMaterialRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterMaterialRule : FilterRule { diff --git a/Revit_oM/Elements/FilterNumericValueRule.cs b/Revit_oM/FilterRules/FilterNumericValueRule.cs similarity index 88% rename from Revit_oM/Elements/FilterNumericValueRule.cs rename to Revit_oM/FilterRules/FilterNumericValueRule.cs index 4a07b6e98..416e19b62 100644 --- a/Revit_oM/Elements/FilterNumericValueRule.cs +++ b/Revit_oM/FilterRules/FilterNumericValueRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterNumericValueRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterRule.cs b/Revit_oM/FilterRules/FilterRule.cs similarity index 83% rename from Revit_oM/Elements/FilterRule.cs rename to Revit_oM/FilterRules/FilterRule.cs index 187db502a..52b0f5fba 100644 --- a/Revit_oM/Elements/FilterRule.cs +++ b/Revit_oM/FilterRules/FilterRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public abstract class FilterRule : BHoMObject { diff --git a/Revit_oM/Elements/FilterStringRule.cs b/Revit_oM/FilterRules/FilterStringRule.cs similarity index 87% rename from Revit_oM/Elements/FilterStringRule.cs rename to Revit_oM/FilterRules/FilterStringRule.cs index 9189bfc94..39116a35c 100644 --- a/Revit_oM/Elements/FilterStringRule.cs +++ b/Revit_oM/FilterRules/FilterStringRule.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class FilterStringRule : FilterValueRule { diff --git a/Revit_oM/Elements/FilterValueRule.cs b/Revit_oM/FilterRules/FilterValueRule.cs similarity index 88% rename from Revit_oM/Elements/FilterValueRule.cs rename to Revit_oM/FilterRules/FilterValueRule.cs index 684616ba8..46a80d90a 100644 --- a/Revit_oM/Elements/FilterValueRule.cs +++ b/Revit_oM/FilterRules/FilterValueRule.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public abstract class FilterValueRule : FilterRule { diff --git a/Revit_oM/Elements/ParameterValuePresenceRule.cs b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs similarity index 69% rename from Revit_oM/Elements/ParameterValuePresenceRule.cs rename to Revit_oM/FilterRules/ParameterValuePresenceRule.cs index ffdc94241..7089a6bf2 100644 --- a/Revit_oM/Elements/ParameterValuePresenceRule.cs +++ b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs @@ -5,10 +5,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Revit.Elements +namespace BH.oM.Revit.FilterRules { public class ParameterValuePresenceRule : FilterValueRule { - public virtual bool IsPresent { get; set; } + public virtual bool IsPresent { get; set; } } } From aecfb013f422877a9365d8f67ff47e41f77f8aab Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 17:00:29 +0100 Subject: [PATCH 099/131] Refactor the partial class FromRevit.ViewFilter --- .../Convert/Revit/FromRevit/ViewFilter.cs | 703 ++++++++++-------- 1 file changed, 406 insertions(+), 297 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index baa3ec31e..58e37f9d1 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -26,7 +26,6 @@ using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.Revit.Views; -using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Enums; using System.Collections.Generic; using System.ComponentModel; @@ -58,308 +57,20 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 1. Transfer Filter NAME */ viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; + /* 2. Transfer List of CATEGORY NAMES */ viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); + /* 3. Transfer List of FILTER RULES */ - //viewFilter.Rules + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) .ToList(); + //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); - List bhomFilterRules = revitFilterRules.Select(revitRule => - { - TextComparisonType bhomTextEvaluator = 0; - NumberComparisonType bhomNumericEvaluator = 0; - - // FILTER STRING RULE - if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) - { - Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; - string paramValue = revitFilterStringRule.RuleString; - FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); - - switch (stringEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterStringBeginsWith": - bhomTextEvaluator = TextComparisonType.StartsWith; - break; - case "Autodesk.Revit.DB.FilterStringEndsWith": - bhomTextEvaluator = TextComparisonType.EndsWith; - break; - case "Autodesk.Revit.DB.FilterStringEquals": - bhomTextEvaluator = TextComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterStringContains": - bhomTextEvaluator = TextComparisonType.Contains; - break; - case "Autodesk.Revit.DB.FilterStringGreater": - bhomTextEvaluator = TextComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": - bhomTextEvaluator = TextComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterStringLess": - bhomTextEvaluator = TextComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterStringLessOrEqual": - bhomTextEvaluator = TextComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule; - bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = paramName; - bhomFilterStringRule.Value = paramValue; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; - - return bhomFilterStringRule; - } - - // FILTER DOUBLE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) - { - Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; - string paramValue = revitFilterDoubleRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); - - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule; - bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = paramName; - bhomFilterDoubleRule.Value = paramValue; - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; - - return bhomFilterDoubleRule; - } - - // FILTER INTEGER RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) - { - Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; - string paramValue = revitFilterIntegerRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); - - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule; - bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = paramName; - bhomFilterIntegerRule.Value = paramValue; - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; - - return bhomFilterIntegerRule; - } - - // FILTER ELEMENTID RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) - { - Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; - string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; - string paramValue = revitFilterElemIdRule.RuleValue.ToString(); - FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); - - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } - - BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElemIdRule; - bhomFilterElemIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); - bhomFilterElemIdRule.ParameterName = paramName; - bhomFilterElemIdRule.Value = paramValue; - bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; - - return bhomFilterElemIdRule; - } - - // FILTER CATEGORY RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) - { - Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; - List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); - - BH.oM.Adapters.Revit.Elements.FilterCategoryRule bhomFilterCategoryRule; - bhomFilterCategoryRule = new BH.oM.Adapters.Revit.Elements.FilterCategoryRule(); - bhomFilterCategoryRule.CategoryNames = categoryNames; - - return bhomFilterCategoryRule; - } - - // FILTER PARAMETER VALUE PRESENCE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) - { - BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule bhomParamValuePresenceRule; - bhomParamValuePresenceRule = new BH.oM.Adapters.Revit.Elements.ParameterValuePresenceRule(); - - bhomParamValuePresenceRule.ParameterName= revitViewFilter.Document.GetElement(((Autodesk.Revit.DB.ParameterValuePresenceRule)revitRule).Parameter).Name; - bhomParamValuePresenceRule.IsPresent = (revitRule.GetType() == typeof(HasValueFilterRule)) ? true : false; - - return bhomParamValuePresenceRule; - } - - // FILTER INVERSE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) - { - Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; - Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); - - switch (innerRule.GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterStringRule"): { - switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterStringEquals"): - bhomTextEvaluator = TextComparisonType.NotEqual; - break; - case ("FilterStringBeginsWith"): - bhomTextEvaluator = TextComparisonType.NotStartsWith; - break; - case ("FilterStringEndsWith"): - bhomTextEvaluator = TextComparisonType.NotEndsWith; - break; - case ("FilterStringContains"): - bhomTextEvaluator = TextComparisonType.ContainsNot; - break; - default: - break; } - BH.oM.Adapters.Revit.Elements.FilterStringRule bhomFilterStringRule = new BH.oM.Adapters.Revit.Elements.FilterStringRule(); - bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; - return bhomFilterStringRule; } - case ("Autodesk.Revit.DB.FilterDoubleRule"): { - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericGreater"): - bhomNumericEvaluator= NumberComparisonType.Less; - break; - case ("FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break;} - BH.oM.Adapters.Revit.Elements.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Adapters.Revit.Elements.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; - return bhomFilterDoubleRule;} - case ("Autodesk.Revit.DB.FilterIntegerRule"):{ - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()){ - case ("FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break;} - BH.oM.Adapters.Revit.Elements.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Adapters.Revit.Elements.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; - return bhomFilterIntegerRule;} - case ("Autodesk.Revit.DB.FilterElementIdRule"): - { - switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } - BH.oM.Adapters.Revit.Elements.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Adapters.Revit.Elements.FilterElementIdRule(); - bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; - bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); - bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; - return bhomFilterElementIdRule; - } - - - - }); + //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects + viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); + //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); viewFilter.CopyParameters(revitViewFilter, settings.MappingSettings); @@ -369,7 +80,405 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par } /***************************************************/ - } + + //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and store them in a List - via STREAMS + private static List FilterRulesFromRevit(this ParameterFilterElement revitViewFilter, List revitFilterRules) + { + List bhomFilterRules = revitFilterRules.Select(revitRule => + { + TextComparisonType bhomTextEvaluator = 0; + NumberComparisonType bhomNumericEvaluator = 0; + + // FILTER STRING RULE + if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator); } + // FILTER DOUBLE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + // FILTER INTEGER RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + // FILTER ELEMENTID RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + // FILTER CATEGORY RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + { return (oM.Revit.FilterRules.FilterRule)FilterCategoryRuleFromRevit(revitViewFilter, revitRule); } + // FILTER PARAMETER VALUE PRESENCE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) + { return (oM.Revit.FilterRules.FilterRule)ParameterValuePresenceRuleFromRevit(revitViewFilter, revitRule); } + // FILTER INVERSE RULE + else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + { return FilterInverseRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator, bhomNumericEvaluator); } + return null; + }).ToList(); + + return bhomFilterRules; + } + + + private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterStringRule obj + Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; + // Extract name and value assigned to the parameter of the FilterStringRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramValue = revitFilterStringRule.RuleString; + // Get the RuleEvaluator of the FilterStringRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); + + // Convert the REVIT FilterStringEvaluator type into the BHOM TextComparisonType Enum + switch (stringEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterStringBeginsWith": + bhomTextEvaluator = TextComparisonType.StartsWith; + break; + case "Autodesk.Revit.DB.FilterStringEndsWith": + bhomTextEvaluator = TextComparisonType.EndsWith; + break; + case "Autodesk.Revit.DB.FilterStringEquals": + bhomTextEvaluator = TextComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterStringContains": + bhomTextEvaluator = TextComparisonType.Contains; + break; + case "Autodesk.Revit.DB.FilterStringGreater": + bhomTextEvaluator = TextComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": + bhomTextEvaluator = TextComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterStringLess": + bhomTextEvaluator = TextComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterStringLessOrEqual": + bhomTextEvaluator = TextComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule; + bhomFilterStringRule = new oM.Revit.FilterRules.FilterStringRule(); + bhomFilterStringRule.ParameterName = paramName; + bhomFilterStringRule.Value = paramValue; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + + return bhomFilterStringRule; + } + + + private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterDoubleRule obj + Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; + // Extract name and value assigned to the parameter of the FilterDoubleRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + // Get the RuleEvaluator of the FilterDoubleRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); + + // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule; + bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = paramName; + bhomFilterDoubleRule.Value = paramValue; + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterDoubleRule; + } + + + private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterIntegerRule obj + Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; + // Extract name and value assigned to the parameter of the FilterIntegerRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + // Get the RuleEvaluator of the FilterIntegerRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); + + // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule; + bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = paramName; + bhomFilterIntegerRule.Value = paramValue; + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterIntegerRule; + } + + + private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterElementIdRule obj + Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; + // Extract name and value assigned to the parameter of the FilterElementIdRule obj + string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; + string paramValue = revitFilterElemIdRule.RuleValue.ToString(); + // Get the RuleEvaluator of the FilterElementIdRule (Class defining the way the string value + // assigned to the parameter is compared with the one assigned by the filter) + FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); + + // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum + switch (numericEvaluator.GetType().ToString()) + { + case "Autodesk.Revit.DB.FilterNumericEquals": + bhomNumericEvaluator = NumberComparisonType.Equal; + break; + case "Autodesk.Revit.DB.FilterNumericGreater": + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + case "Autodesk.Revit.DB.FilterNumericLess": + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case "Autodesk.Revit.DB.FilterNumericLessOrEqual": + bhomNumericEvaluator = NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterElementIdRule bhomFilterElemIdRule; + bhomFilterElemIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); + bhomFilterElemIdRule.ParameterName = paramName; + bhomFilterElemIdRule.Value = paramValue; + bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; + + return bhomFilterElemIdRule; + } + + + private static oM.Revit.FilterRules.FilterCategoryRule FilterCategoryRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterCategoryRule obj + Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; + // Extract name and value assigned to the parameter of the FilterElementIdRule obj + List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); + + // 2. BUILD the BHOM FILTERRULE object + + oM.Revit.FilterRules.FilterCategoryRule bhomFilterCategoryRule; + bhomFilterCategoryRule = new BH.oM.Revit.FilterRules.FilterCategoryRule(); + bhomFilterCategoryRule.CategoryNames = categoryNames; + + return bhomFilterCategoryRule; + } + + + private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePresenceRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + oM.Revit.FilterRules.ParameterValuePresenceRule bhomParamValuePresenceRule; + bhomParamValuePresenceRule = new BH.oM.Revit.FilterRules.ParameterValuePresenceRule(); + + // 2. BUILD the BHOM FILTERRULE object + + bhomParamValuePresenceRule.ParameterName = revitViewFilter.Document.GetElement(((Autodesk.Revit.DB.ParameterValuePresenceRule)revitRule).Parameter).Name; + bhomParamValuePresenceRule.IsPresent = (revitRule.GetType() == typeof(HasValueFilterRule)) ? true : false; + + return bhomParamValuePresenceRule; + } + + + private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator, NumberComparisonType bhomNumericEvaluator) + { + // 1. EXTRACT DATA from the REVIT FILTERRULE object + + // Downcast Revit FilterRule obj to Revit FilterInverseRule obj + Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; + // Extract innerRule assigned to the Revit FilterInverseRule obj + Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); + + // Convert the REVIT InnerRule into the corresponding BHOM FilterRule obj + switch (innerRule.GetType().ToString()) + { + //FilterStringRule + case ("Autodesk.Revit.DB.FilterStringRule"): + { + switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterStringEquals"): + bhomTextEvaluator = TextComparisonType.NotEqual; + break; + case ("FilterStringBeginsWith"): + bhomTextEvaluator = TextComparisonType.NotStartsWith; + break; + case ("FilterStringEndsWith"): + bhomTextEvaluator = TextComparisonType.NotEndsWith; + break; + case ("FilterStringContains"): + bhomTextEvaluator = TextComparisonType.ContainsNot; + break; + default: + break; + } + oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); + bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; + bhomFilterStringRule.Evaluator = bhomTextEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; + } + // FilterDoubleRule + case ("Autodesk.Revit.DB.FilterDoubleRule"): + { + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); + bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); + bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; + } + // FilterIntegerRule + case ("Autodesk.Revit.DB.FilterIntegerRule"): + { + switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); + bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); + bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; + } + // FilterElementIdRule + case ("Autodesk.Revit.DB.FilterElementIdRule"): + { + switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) + { + case ("FilterNumericEquals"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericGreater"): + bhomNumericEvaluator = NumberComparisonType.Less; + break; + case ("FilterNumericGreaterOrEqual"): + bhomNumericEvaluator = NumberComparisonType.NotEqual; + break; + case ("FilterNumericLess"): + bhomNumericEvaluator = NumberComparisonType.Greater; + break; + case ("FilterNumericLessOrEqual"): + bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; + break; + } + oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); + bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); + bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; + return (oM.Revit.FilterRules.FilterRule)bhomFilterElementIdRule; + } + default: + { return null; } + + } + } + +} } From 7ca2b5c1aabccb2afd5df06b483cd0a2e91c800a Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 20:43:11 +0100 Subject: [PATCH 100/131] Fix code for conversion of Revit Views into BHoM Views --- .../Convert/Revit/FromRevit/View.cs | 104 +++++++++++------- 1 file changed, 63 insertions(+), 41 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 0f14b9dfd..6f054e518 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -26,11 +26,15 @@ using BH.oM.Adapters.Revit.Settings; using BH.oM.Base; using BH.oM.Base.Attributes; +using BH.oM.Revit.Enums; using BH.oM.Revit.Views; +using BH.Revit.Engine.Core; using System; using System.Collections.Generic; using System.ComponentModel; +using System.Drawing; using System.Linq; +using System.Security.Policy; using System.Xml.Linq; using FilterRule = BH.oM.Revit.Elements.FilterRule; using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; @@ -57,42 +61,14 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, if (view != null) return view; - /* 1. Transfer NAME */ - view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name }; - - /* 2. Collect FILTER CATEGORY NAMES */ - List> categoriesNames=revitView.GetFilters() - .Select(elId => revitView.Document.GetElement(elId)) - .Cast() - .Select(pfe => pfe.GetCategories().ToList()) - .Select(catIdsList => catIdsList.Select(catId => revitView.Document.GetElement(catId).Name).ToList()) - .ToList>(); - - - List filtersWithOverrides; - List viewFilters; - List overrides; - - List filterRules = revitView.GetFilters() - .Select(elId => revitView.Document.GetElement(elId)) - .Cast() - .Select(epf => epf.GetRules()) - .ToDictionary(fvr => fvr.GetType(), - fvr => - { - Element param = revitView.Document.GetElement(fvr.GetRuleParameter()); - string paramName = param.Name; - string value = fvr.ToString(); - return new Array { paramName, value }; - }) - .ToList>() - .Select(kvp => new FilterRule { RuleType = FilterRuleType.BEGINSWITH, - ParameterName = kvp.Value[0], - Value = kvp.Value[1] }) - . - - - //TODO: here goes the convertion method + /*1. Transfer ViewFilters and corresponding OverrideGraphicSettings into ViewFilterWithOverrides Objects - via STREAMS */ + List filtersWithOverrides = revitView.GetFilters().ToDictionary + (elId => Convert.ViewFilterFromRevit((ParameterFilterElement)revitView.Document.GetElement(elId)), + elId => overrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() + .Select(kvp => new ViewFilterWithOverrides { Filter = kvp.Key, Overrides = kvp.Value }).ToList(); + + /*2. Create BHoM View Object with Name and FilterWithOverrides objects */ + view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name, FiltersWithOverrides = filtersWithOverrides }; //Set identifiers, parameters & custom data view.SetIdentifiers(revitView); @@ -104,10 +80,56 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, } /***************************************************/ - } -} - - - + private static OverrideGraphicSettings overrideGraphicSettingsFromRevit(this View element, Autodesk.Revit.DB.OverrideGraphicSettings revitOverrides) + { + // Initialize BHoM OverrideGraphicsSettings object + OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + + // Convert COLORS + overrideGraphicsSettings.LineColor = System.Drawing.Color.FromArgb(revitOverrides.CutLineColor.Red, revitOverrides.CutLineColor.Green, revitOverrides.CutLineColor.Blue); + overrideGraphicsSettings.CutColor = System.Drawing.Color.FromArgb(revitOverrides.CutBackgroundPatternColor.Red, revitOverrides.CutBackgroundPatternColor.Green, revitOverrides.CutBackgroundPatternColor.Blue); + overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); + + // Convert LINE PATTERNS + String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; + + if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DASH; } + else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DOT; } + else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.HIDDEN; } + else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.SOLID; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } + + + // Convert CUT PATTERNS + String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; + + if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } + else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } + else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } + else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.STEEL; } + else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.SOLID; } + else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.VERTICAL; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } + + + // Convert SURFACE PATTERNS + String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; + + if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } + else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } + else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } + else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.STEEL; } + else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.SOLID; } + else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.VERTICAL; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } + + return overrideGraphicsSettings; + } + } +} \ No newline at end of file From 0ce26f7ee48751a930ce2a6512fb2554669cb39f Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 19 Aug 2024 21:03:35 +0100 Subject: [PATCH 101/131] Make explicit distinction between Revit and BHoM View Class instances --- .../Convert/Revit/FromRevit/DraftingInstance.cs | 2 +- Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs | 2 +- Revit_Core_Engine/Convert/Revit/FromRevit/View.cs | 2 +- .../Convert/Revit/ToRevit/CurveElement.cs | 2 +- Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs | 10 +++++----- Revit_Core_Engine/Modify/SetLocation.cs | 2 +- Revit_Core_Engine/Modify/Update.cs | 1 - Revit_Core_Engine/Query/View.cs | 8 ++++---- Revit_oM/Elements/ViewFilter.cs | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs index 48dc7599a..94b46db32 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/DraftingInstance.cs @@ -53,7 +53,7 @@ public static DraftingInstance DraftingInstanceFromRevit(this FilledRegion fille if (draftingInstance != null) return draftingInstance; - View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View; + Autodesk.Revit.DB.View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as Autodesk.Revit.DB.View; if (view == null) return null; diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs index b9d53b2f7..7627a5388 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/IInstance.cs @@ -55,7 +55,7 @@ public static IInstance InstanceFromRevit(this CurveElement curveElement, RevitS if (curveElement.ViewSpecific) { - View view = curveElement.Document.GetElement(curveElement.OwnerViewId) as View; + Autodesk.Revit.DB.View view = curveElement.Document.GetElement(curveElement.OwnerViewId) as Autodesk.Revit.DB.View; if (view == null) return null; diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 6f054e518..09a7a94f8 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -36,7 +36,7 @@ using System.Linq; using System.Security.Policy; using System.Xml.Linq; -using FilterRule = BH.oM.Revit.Elements.FilterRule; +using FilterRule = BH.oM.Revit.FilterRules.FilterRule; using OverrideGraphicSettings = BH.oM.Adapters.Revit.Elements.OverrideGraphicSettings; using View = Autodesk.Revit.DB.View; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs index 11b0c63b8..8a36b24ab 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/CurveElement.cs @@ -128,7 +128,7 @@ public static CurveElement ToCurveElement(this DraftingInstance draftingInstance if (!BH.Engine.Geometry.Query.IsPlanar(curve as dynamic)) return null; - View view = Query.View(draftingInstance, document); + Autodesk.Revit.DB.View view = Query.View(draftingInstance, document); if (view == null) return null; diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs index 7b5a7db83..27b467068 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/Element.cs @@ -119,7 +119,7 @@ public static Element ToRevitElement(this DraftingInstance draftingInstance, Doc settings = settings.DefaultIfNull(); - View view = draftingInstance.View(document); + Autodesk.Revit.DB.View view = draftingInstance.View(document); if (view == null) return null; @@ -256,7 +256,7 @@ private static Element ToRevitElement(this ModelInstance modelInstance, FamilySy /**** Private Methods - Drafting Instances ****/ /***************************************************/ - private static Element IToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, View view, RevitSettings settings) + private static Element IToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, Autodesk.Revit.DB.View view, RevitSettings settings) { if (elementType == null) { @@ -269,7 +269,7 @@ private static Element IToRevitElement(this DraftingInstance draftingInstance, E /***************************************************/ - private static Element ToRevitElement(this DraftingInstance draftingInstance, FilledRegionType regionType, View view, RevitSettings settings) + private static Element ToRevitElement(this DraftingInstance draftingInstance, FilledRegionType regionType, Autodesk.Revit.DB.View view, RevitSettings settings) { ISurface location = draftingInstance.Location as ISurface; @@ -310,7 +310,7 @@ private static Element ToRevitElement(this DraftingInstance draftingInstance, Fi /***************************************************/ - private static Element ToRevitElement(this DraftingInstance draftingInstance, FamilySymbol familySymbol, View view, RevitSettings settings) + private static Element ToRevitElement(this DraftingInstance draftingInstance, FamilySymbol familySymbol, Autodesk.Revit.DB.View view, RevitSettings settings) { if (draftingInstance?.Location == null) return null; @@ -328,7 +328,7 @@ private static Element ToRevitElement(this DraftingInstance draftingInstance, Fa /**** Fallback Methods ****/ /***************************************************/ - private static Element ToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, View view, RevitSettings settings) + private static Element ToRevitElement(this DraftingInstance draftingInstance, ElementType elementType, Autodesk.Revit.DB.View view, RevitSettings settings) { return null; } diff --git a/Revit_Core_Engine/Modify/SetLocation.cs b/Revit_Core_Engine/Modify/SetLocation.cs index 5684d07a4..b8e628eaa 100644 --- a/Revit_Core_Engine/Modify/SetLocation.cs +++ b/Revit_Core_Engine/Modify/SetLocation.cs @@ -546,7 +546,7 @@ private static bool SetLocation(this FamilyInstance element, BH.oM.Geometry.Poin typeof(Autodesk.Revit.DB.Family), typeof(ElementType), typeof(Material), - typeof(View) + typeof(Autodesk.Revit.DB.View) }; /***************************************************/ diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 465b2439f..01f290d5e 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -25,7 +25,6 @@ using BH.Engine.Adapters.Revit; using BH.oM.Adapters.Revit.Elements; using BH.oM.Adapters.Revit.Settings; -using BH.oM.Adapters.Revit.Views; using BH.oM.Base; using BH.oM.Base.Attributes; using BH.oM.MEP.Equipment.Parts; diff --git a/Revit_Core_Engine/Query/View.cs b/Revit_Core_Engine/Query/View.cs index d4eba8641..62e4a3d1d 100644 --- a/Revit_Core_Engine/Query/View.cs +++ b/Revit_Core_Engine/Query/View.cs @@ -39,15 +39,15 @@ public static partial class Query [Input("draftingInstance", "BHoM drafting instance to find owner Revit view for.")] [Input("document", "Revit document to parse in view search.")] [Output("view", "Revit view owning the input BHoM drafting instance.")] - public static View View(this DraftingInstance draftingInstance, Document document) + public static Autodesk.Revit.DB.View View(this DraftingInstance draftingInstance, Document document) { if (string.IsNullOrWhiteSpace(draftingInstance.ViewName)) return null; - List views = new FilteredElementCollector(document).OfClass(typeof(View)).Cast().ToList(); + List views = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.View)).Cast().ToList(); views.RemoveAll(x => x.IsTemplate || x is ViewSchedule || x is View3D || x is ViewSheet); - View view = null; + Autodesk.Revit.DB.View view = null; if (views != null && views.Count > 0) view = views.Find(x => x.Name == draftingInstance.ViewName); @@ -55,7 +55,7 @@ public static View View(this DraftingInstance draftingInstance, Document documen if (view != null) return view; - views = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast().ToList(); + views = new FilteredElementCollector(document).OfClass(typeof(ViewSheet)).Cast().ToList(); string title = draftingInstance.ViewName; if (!title.StartsWith("Sheet: ")) title = string.Format("Sheet: {0}", title); diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index a33b5bb16..19d833939 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -1,5 +1,5 @@ using BH.oM.Base; -using BH.oM.Revit.Elements; +using BH.oM.Adapters.Revit.Elements; using BH.oM.Revit.FilterRules; using System; using System.Collections.Generic; From 8bfe55d0527fd256cdb0b71f1bb9beeff1a57e23 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Aug 2024 11:17:27 +0100 Subject: [PATCH 102/131] Add conversion of BHoM FilterRule to Revit FilterRule --- .../Revit/ToRevit/ParameterFilterElement.cs | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 7bb739841..c7e6096c8 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -33,6 +33,7 @@ using BH.oM.Revit.Enums; using BH.oM.Revit.FilterRules; using System; +using System.CodeDom; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -120,9 +121,32 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, oM.Revit.FilterRules.FilterCategoryRule filterCategoryRule) + public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document, oM.Revit.FilterRules.FilterRule filterRule) { - /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ + + /* 1. CONVERT BHOM FILTERRULE INTO REVIT FILTERRULE */ + + // FilterCategoryRule + if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterCategoryRule)) + { return filterCategoryRuleToRevit(document, (oM.Revit.FilterRules.FilterCategoryRule)filterRule); } + // FilterMaterialRule + else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterMaterialRule)) + { return filterMaterialRuleToRevit(document, (oM.Revit.FilterRules.FilterMaterialRule)filterRule); } + // FilterLevelRule + else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterLevelRule)) + { return filterLevelRuleToRevit(document, (oM.Revit.FilterRules.FilterLevelRule)filterRule); } + // FilterValueRule + else if (filterRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) + { return filterValueRuleToRevit(document, (oM.Revit.FilterRules.FilterValueRule)filterRule); } + + return null; + + } + + + private static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document document, oM.Revit.FilterRules.FilterCategoryRule filterCategoryRule) + { + /* 1. INITIALIZE FILTERRULE */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ @@ -146,23 +170,22 @@ public static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document do /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, FilterMaterialRule filterMaterialRule) + private static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document document, FilterMaterialRule filterMaterialRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; BuiltInParameter parameter = BuiltInParameter.MATERIAL_NAME; - + /* 2. CREATE THE FILTER RULE */ //ParameterValueProvider provider = new ParameterValueProvider(new ElementId(parameter)); revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); - return revitFilterRule; } /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, FilterLevelRule filterLevelRule) + private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document document, FilterLevelRule filterLevelRule) { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; @@ -183,6 +206,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum } catch (Exception ex){ return null;} + /* 3. CREATE FILTERS RULE */ // Based on level's elevation and LevelComparisonType... @@ -223,7 +247,7 @@ public static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docum /***************************************************/ - public static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { + private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; From 7f22f9dc6216f430a70529de6b360bbf88687307 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 20 Aug 2024 16:58:49 +0100 Subject: [PATCH 103/131] Fix bug with extraction of revit Id of selected parameter --- .../Revit/ToRevit/ParameterFilterElement.cs | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index c7e6096c8..c667e8f50 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -72,7 +72,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(catName => catName.ToUpper().Replace(" ", "")) // Get the corresponding BuiltInCategories .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) - .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("ost_", "")) + .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_","")) .ToList(); return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]);}) // Get the ElementIds of the BuiltInCategories @@ -251,16 +251,9 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - ElementClassFilter paramFilter = new ElementClassFilter(typeof(Parameter)); - ElementClassFilter builtInParamFilter = new ElementClassFilter(typeof(BuiltInParameter)); - LogicalOrFilter logicalOrFilter = new LogicalOrFilter(paramFilter, builtInParamFilter); /* 2. GET THE ELEMENT ID OF THE PARAMETER OBJECT */ - ElementId parameterId = new FilteredElementCollector(document) - .WherePasses(logicalOrFilter) - .Where(par => par.Name.Equals(filterValueRule.ParameterName)) - .First() - .Id; + ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); /* 3. CREATE FILTER-RULE */ @@ -326,8 +319,10 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu // Based on FilterNumericValueRule... } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { + /* 1. Downcast to subclass */ oM.Revit.FilterRules.FilterNumericValueRule filterNumericValueRule = (oM.Revit.FilterRules.FilterNumericValueRule)filterValueRule; + /* 2. Convert Evaluator from Revit to BHoM */ switch (filterNumericValueRule.Evaluator) { case NumberComparisonType.Equal: @@ -375,9 +370,30 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu return revitFilterRule; } - } + private static ElementId GetParameterIdByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) + { + // Return the ElementId of the parameter + return param.Id; + } + } + + // If the parameter is not found, return InvalidElementId + return ElementId.InvalidElementId; + } + + } } From f99df398456bb4c6fdc31a185fef354b2d91eb60 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 14:20:00 +0100 Subject: [PATCH 104/131] Fix code for conversion of filterRules from BHoM to Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement Adapt code to work better with the restraints of the Revit API Rule Factory Classes --- .../Revit/ToRevit/ParameterFilterElement.cs | 165 ++++++++++++++---- 1 file changed, 134 insertions(+), 31 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index c667e8f50..f295b142e 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -319,41 +319,144 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu // Based on FilterNumericValueRule... } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterNumericValueRule filterNumericValueRule = (oM.Revit.FilterRules.FilterNumericValueRule)filterValueRule; - /* 2. Convert Evaluator from Revit to BHoM */ - switch (filterNumericValueRule.Evaluator) + if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule)) { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId,(string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (string)filterNumericValueRule.Value, false); - break; - default: - break; + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; + + /* 2. Convert input value to target data type */ + Double doubleValue=0.0; + Boolean boolParam=Double.TryParse(filterDoubleRule.Value,out doubleValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); + } + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterDoubleRule.Evaluator) + { + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, doubleValue, 0.01); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, doubleValue, 0.01); + break; + default: + break; + } + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterIntegerRule)) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterIntegerRule filterIntegerRule = (oM.Revit.FilterRules.FilterIntegerRule)filterValueRule; + + /* 2. Convert input value to target data type */ + int intValue = 0; + Boolean boolParam = int.TryParse(filterIntegerRule.Value, out intValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); + } + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterIntegerRule.Evaluator) + { + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, intValue); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, intValue); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, intValue); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, intValue); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, intValue); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, intValue); + break; + default: + break; + } + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterElementIdRule)) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterElementIdRule filterElementIdRule = (oM.Revit.FilterRules.FilterElementIdRule)filterValueRule; + + /* 2. Convert input value to target data type */ + Boolean boolParam = int.TryParse(filterElementIdRule.Value, out int intValue); + ElementId elId = new ElementId(intValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); + } + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterElementIdRule.Evaluator) + { + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, elId); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, elId); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, elId); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, elId); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, elId); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, elId); + break; + default: + break; + } } - } + } // Based on ParameterValuePresenceRule... else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) { From 65f491b3e6c171a4a20cbb86f87060110761b526 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 14:23:16 +0100 Subject: [PATCH 105/131] Add call to method for convertion of FilterLevelRule to Revit. --- .../Revit/ToRevit/ParameterFilterElement.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index f295b142e..c18fcfc26 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -94,18 +94,25 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))){ + if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))) + { filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) - .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))){ - filterRules = kvp.Value.Cast() - .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) - .ToList();} - else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))){ + .ToList(); + } + + else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))) + { filterRules = kvp.Value.Cast() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) - .ToList();} + .ToList(); + } + else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) + { + filterRules = kvp.Value.Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) + .ToList(); + } return filterRules; }) .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) .Cast() @@ -334,6 +341,9 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); } + ForgeTypeId units = new ForgeTypeId(); + Convert.ToSI(doubleValue,) + /* 3. Convert Evaluator from Revit to BHoM */ switch (filterDoubleRule.Evaluator) { From a4a98af05195164c89ae43fca456e5ab6d6145be Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 17:28:32 +0100 Subject: [PATCH 106/131] Fix bug in creation of Revit Element Filter from BHoM FilterRules --- Revit_Adapter/Revit_Adapter.csproj | 2 +- .../Revit/ToRevit/ParameterFilterElement.cs | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Revit_Adapter/Revit_Adapter.csproj b/Revit_Adapter/Revit_Adapter.csproj index 0f801e86b..57a57e079 100644 --- a/Revit_Adapter/Revit_Adapter.csproj +++ b/Revit_Adapter/Revit_Adapter.csproj @@ -17,7 +17,7 @@ - + diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index c18fcfc26..a890b2e0e 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -86,37 +86,48 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - revitFilter.SetElementFilter(new LogicalAndFilter(filter.Rules + ElementFilter elFilter=new LogicalAndFilter(filter.Rules .GroupBy(rule => rule.GetType()) .ToDictionary(grp => grp.Key, grp => grp.ToList()) .ToList() - .Select(kvp =>{ + .Select(kvp => + { List filterRules = new List(); - if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterCategoryRule))) + if (kvp.Key.Name == "FilterCategoryRule") { filterRules = kvp.Value.Cast() .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) .ToList(); } - - else if (kvp.Key.IsSubclassOf(typeof(FilterMaterialRule))) + else if (kvp.Key.Name == "FilterLevelRule") + { + filterRules = kvp.Value.Cast() + .Select(filterLevelRule => filterLevelRuleToRevit(document, filterLevelRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterMaterialRule") { filterRules = kvp.Value.Cast() .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList(); } - else if (kvp.Key.IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || + kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") { filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) .ToList(); } - return filterRules; }) + return filterRules; + }) .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) .Cast() - .ToList())); + .ToList()); + + + revitFilter.SetElementFilter(elFilter); revitFilter.CopyParameters(filter, settings); @@ -341,9 +352,6 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); } - ForgeTypeId units = new ForgeTypeId(); - Convert.ToSI(doubleValue,) - /* 3. Convert Evaluator from Revit to BHoM */ switch (filterDoubleRule.Evaluator) { From 5aeb945acaf472afdd060632c3ce47da6c325ab9 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 18:54:54 +0100 Subject: [PATCH 107/131] Add changes to Level and Material FilterRule Conversion --- Revit_Adapter/Revit_Adapter.csproj | 2 +- .../Revit/ToRevit/ParameterFilterElement.cs | 42 ++++++++++++------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Revit_Adapter/Revit_Adapter.csproj b/Revit_Adapter/Revit_Adapter.csproj index 57a57e079..0221c170c 100644 --- a/Revit_Adapter/Revit_Adapter.csproj +++ b/Revit_Adapter/Revit_Adapter.csproj @@ -17,7 +17,7 @@ - + diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a890b2e0e..4272ca201 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -192,11 +192,16 @@ private static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document d { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - BuiltInParameter parameter = BuiltInParameter.MATERIAL_NAME; + BuiltInParameter parameter = BuiltInParameter.STRUCTURAL_MATERIAL_PARAM; /* 2. CREATE THE FILTER RULE */ + //ParameterValueProvider provider = new ParameterValueProvider(new ElementId(parameter)); - revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); + //revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); + + FilteredElementCollector collector = new FilteredElementCollector(document); + Element mat=collector.OfClass(typeof(Material)).Where(material => material.Name == filterMaterialRule.MaterialName).First(); + revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), mat.Id); return revitFilterRule; } @@ -207,22 +212,27 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - BuiltInParameter elevationParam = BuiltInParameter.LEVEL_ELEV; - ElementId elevParamId=new ElementId(elevationParam); - Double levelElevation; + BuiltInParameter levParam = BuiltInParameter.LEVEL_PARAM; + ElementId levParamId=new ElementId(levParam); + ElementId levelId; /* 2. GET ELEVATION OF LEVEL CORRESPONDING TO INPUT LEVEL NAME */ // Via Streams and withing a Try-Catch statement to make sure the code is compact and if the level is not found, we prevent any error // being thrown when executing .First() while returning null instead. - try { - levelElevation=new FilteredElementCollector(document) + try + { + levelId = new FilteredElementCollector(document) .OfCategory(BuiltInCategory.OST_Levels) .Where(level => level.Name.ToUpper() == filterLevelRule.LevelName.ToUpper()) .Cast() - .Select(level => level.Elevation) + .Select(level => level.Id) .First(); - } catch (Exception ex){ - return null;} + } + catch (Exception ex) + { + return null; + } + /* 3. CREATE FILTERS RULE */ @@ -232,27 +242,27 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { case LevelComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(elevParamId,(double)levelElevation, 0.001); + .CreateEqualsRule(levParamId, filterLevelRule.LevelName,false); break; case LevelComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(elevParamId, (double)levelElevation, 0.001); + .CreateNotEqualsRule(levParamId, levelId); break; case LevelComparisonType.Above: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(elevParamId, (double)levelElevation, 0.001); + .CreateGreaterRule(levParamId, levelId); break; case LevelComparisonType.AtOrAbove: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(elevParamId, (double)levelElevation, 0.001); + .CreateGreaterOrEqualRule(levParamId, levelId); break; case LevelComparisonType.Below: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(elevParamId, (double)levelElevation, 0.001); + .CreateLessRule(levParamId, levelId); break; case LevelComparisonType.AtOrBelow: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(elevParamId, (double)levelElevation, 0.001); + .CreateLessOrEqualRule(levParamId, levelId); break; default: break; From 3fe9b8fc558a7ee570be58f7a0e83f496be3114b Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 21 Aug 2024 22:28:55 +0100 Subject: [PATCH 108/131] Fix bug with Push of View Filters based on Levels --- Revit_Adapter/Revit_Adapter.csproj | 2 +- .../Convert/Revit/ToRevit/ParameterFilterElement.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Revit_Adapter/Revit_Adapter.csproj b/Revit_Adapter/Revit_Adapter.csproj index 0221c170c..0f801e86b 100644 --- a/Revit_Adapter/Revit_Adapter.csproj +++ b/Revit_Adapter/Revit_Adapter.csproj @@ -17,7 +17,7 @@ - + diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 4272ca201..a0f6963e7 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -212,7 +212,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - BuiltInParameter levParam = BuiltInParameter.LEVEL_PARAM; + BuiltInParameter levParam = BuiltInParameter.SCHEDULE_LEVEL_PARAM; ElementId levParamId=new ElementId(levParam); ElementId levelId; @@ -242,7 +242,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { case LevelComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(levParamId, filterLevelRule.LevelName,false); + .CreateEqualsRule(levParamId, levelId); break; case LevelComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory From ccb18c53f0e42c47d5399785b304d496068ff6b6 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 15:08:37 +0100 Subject: [PATCH 109/131] Fix bug dispatching different types of FilterRule --- .../Revit/ToRevit/ParameterFilterElement.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index a0f6963e7..0d27cc778 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -113,8 +113,8 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList(); } - else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || - kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule"|| + kvp.Key.Name=="FilterIntegerRule"||kvp.Key.Name=="FilterElementIdRule") { filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) @@ -286,7 +286,8 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu /* 3. CREATE FILTER-RULE */ // Based on FilterStringRule... - if (filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) + if (filterValueRule.GetType()==typeof(FilterStringRule)|| + filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) { FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; @@ -345,10 +346,11 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu } // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) + } else if (filterValueRule.GetType()==typeof(oM.Revit.FilterRules.FilterNumericValueRule)|| + filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) { - if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule)) + if ((filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule))) { /* 1. Downcast to subclass */ oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; @@ -486,7 +488,8 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu } // Based on ParameterValuePresenceRule... - else if (filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) + else if (filterValueRule.GetType()== typeof(oM.Revit.FilterRules.ParameterValuePresenceRule)|| + filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) { oM.Revit.FilterRules.ParameterValuePresenceRule parameterValuePresenceRule = (oM.Revit.FilterRules.ParameterValuePresenceRule)filterValueRule; From dcf3b3273036937267981538a9133bf8a70c7744 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 15:08:46 +0100 Subject: [PATCH 110/131] Turn FilterNumericValueRule into an abstract class In this way its corresponding Grasshopper Component will disappear, thus forcing the user to use only its specific sub-components: DoubleRule, IntegerRule and ElementIdRule. --- Revit_oM/FilterRules/FilterNumericValueRule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Revit_oM/FilterRules/FilterNumericValueRule.cs b/Revit_oM/FilterRules/FilterNumericValueRule.cs index 416e19b62..3f9d3d27e 100644 --- a/Revit_oM/FilterRules/FilterNumericValueRule.cs +++ b/Revit_oM/FilterRules/FilterNumericValueRule.cs @@ -7,7 +7,7 @@ namespace BH.oM.Revit.FilterRules { - public class FilterNumericValueRule : FilterValueRule + public abstract class FilterNumericValueRule : FilterValueRule { public virtual NumberComparisonType Evaluator { get; set; } From 1ba1bcafe27f84e2346746103b8d332d2d23bbe6 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 18:30:11 +0100 Subject: [PATCH 111/131] Fix bug related to incorrect extraction of Categories from the model. Rather than using a FilteredElementCollector on which to call the .OfClass() method, better to get all the Category objects getting the Categories data structure from the Revit model and then iterate on its elements to extract all the categories and transfer them into a list. --- .../Revit/ToRevit/ParameterFilterElement.cs | 75 +++++++++++++------ 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 0d27cc778..15cec5445 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -86,7 +86,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - ElementFilter elFilter=new LogicalAndFilter(filter.Rules + ElementFilter elFilter = new LogicalAndFilter(filter.Rules .GroupBy(rule => rule.GetType()) .ToDictionary(grp => grp.Key, grp => grp.ToList()) .ToList() @@ -113,8 +113,8 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) .ToList(); } - else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule"|| - kvp.Key.Name=="FilterIntegerRule"||kvp.Key.Name=="FilterElementIdRule") + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || + kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") { filterRules = kvp.Value.Cast() .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) @@ -167,10 +167,12 @@ private static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document d /* 1. INITIALIZE FILTERRULE */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; + /* 2. EXTRACT CATEGORIES */ + List categories = new List(); + foreach (Autodesk.Revit.DB.Category cat in document.Settings.Categories) { categories.Add(cat);} + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ - List categoryIds = new FilteredElementCollector(document) - // Get all the Categories (INTERMEDIATE OPERATION) - .OfClass(typeof(Autodesk.Revit.DB.Category)) + List categoryIds = categories // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) // Cast down to Category Class Instances (INTERMEDIATE OPERATION) @@ -280,8 +282,9 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; - /* 2. GET THE ELEMENT ID OF THE PARAMETER OBJECT */ + /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); + Parameter parameter = GetParameterByName(document, filterValueRule.ParameterName); /* 3. CREATE FILTER-RULE */ @@ -364,32 +367,35 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); } - /* 3. Convert Evaluator from Revit to BHoM */ + /* 3. Convert units of input value to internal units */ + double convertedValue =UnitUtils.ConvertToInternalUnits(doubleValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ switch (filterDoubleRule.Evaluator) { case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, doubleValue, 0.01); + .CreateEqualsRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, doubleValue, 0.01); + .CreateNotEqualsRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, doubleValue, 0.01); + .CreateGreaterRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, doubleValue, 0.01); + .CreateGreaterOrEqualRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, doubleValue, 0.01); + .CreateLessRule(parameterId, convertedValue, 0.01); break; case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, doubleValue, 0.01); + .CreateLessOrEqualRule(parameterId, convertedValue, 0.01); break; default: break; @@ -409,32 +415,35 @@ private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document docu BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); } - /* 3. Convert Evaluator from Revit to BHoM */ + /* 3. Convert units of input value to internal units */ + int convertedValue = (int)UnitUtils.ConvertToInternalUnits((Double)intValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ switch (filterIntegerRule.Evaluator) { case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, intValue); + .CreateEqualsRule(parameterId, convertedValue); break; case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, intValue); + .CreateNotEqualsRule(parameterId, convertedValue); break; case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, intValue); + .CreateGreaterRule(parameterId, convertedValue); break; case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, intValue); + .CreateGreaterOrEqualRule(parameterId, convertedValue); break; case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, intValue); + .CreateLessRule(parameterId, convertedValue); break; case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, intValue); + .CreateLessOrEqualRule(parameterId, convertedValue); break; default: break; @@ -526,7 +535,29 @@ private static ElementId GetParameterIdByName(Document doc, string parameterName // If the parameter is not found, return InvalidElementId return ElementId.InvalidElementId; } - + + + private static Parameter GetParameterByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) + { + // Return the ElementId of the parameter + return param; + } + } + + // If the parameter is not found, return InvalidElementId + return null; + } } } From afc9460d9b854130156a96de0803d7fe004d1da0 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 27 Aug 2024 19:33:37 +0100 Subject: [PATCH 112/131] Add feature to create ViewFilters with No Rules. --- .../Revit/ToRevit/ParameterFilterElement.cs | 86 ++++++++++--------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 15cec5445..ac7711a99 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -79,56 +79,58 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(builtInCat => new ElementId(builtInCat)) // Turn the Stream into a List of ElementIds .ToList(); - + /* 1.2 Create the ParameterFilterElement in the current Revit Document */ revitFilter = ParameterFilterElement.Create(document, filter.Name, categoryIdsList); + // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - ElementFilter elFilter = new LogicalAndFilter(filter.Rules - .GroupBy(rule => rule.GetType()) - .ToDictionary(grp => grp.Key, grp => grp.ToList()) - .ToList() - .Select(kvp => - { - - List filterRules = new List(); - - if (kvp.Key.Name == "FilterCategoryRule") - { - filterRules = kvp.Value.Cast() - .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) - .ToList(); - } - else if (kvp.Key.Name == "FilterLevelRule") - { - filterRules = kvp.Value.Cast() - .Select(filterLevelRule => filterLevelRuleToRevit(document, filterLevelRule)) - .ToList(); - } - else if (kvp.Key.Name == "FilterMaterialRule") - { - filterRules = kvp.Value.Cast() - .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) - .ToList(); - } - else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || - kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") + if (filter.Rules.Count != 0) + { + ElementFilter elFilter = new LogicalAndFilter(filter.Rules + .GroupBy(rule => rule.GetType()) + .ToDictionary(grp => grp.Key, grp => grp.ToList()) + .ToList() + .Select(kvp => { - filterRules = kvp.Value.Cast() - .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) - .ToList(); - } - return filterRules; - }) - .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) - .Cast() - .ToList()); - - - revitFilter.SetElementFilter(elFilter); + List filterRules = new List(); + + if (kvp.Key.Name == "FilterCategoryRule") + { + filterRules = kvp.Value.Cast() + .Select(filterCategoryRule => filterCategoryRuleToRevit(document, filterCategoryRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterLevelRule") + { + filterRules = kvp.Value.Cast() + .Select(filterLevelRule => filterLevelRuleToRevit(document, filterLevelRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterMaterialRule") + { + filterRules = kvp.Value.Cast() + .Select(filterMaterialRule => filterMaterialRuleToRevit(document, filterMaterialRule)) + .ToList(); + } + else if (kvp.Key.Name == "FilterStringRule" || kvp.Key.Name == "FilterDoubleRule" || + kvp.Key.Name == "FilterIntegerRule" || kvp.Key.Name == "FilterElementIdRule") + { + filterRules = kvp.Value.Cast() + .Select(filterValueRule => filterValueRuleToRevit(document, filterValueRule)) + .ToList(); + } + return filterRules; + }) + .Select(filterRulesList => new ElementParameterFilter(filterRulesList)) + .Cast() + .ToList()); + + revitFilter.SetElementFilter(elFilter); + } revitFilter.CopyParameters(filter, settings); refObjects.AddOrReplace(filter, revitFilter); From b172fb2ad1094ef37b32b09a2022d0c10ca5fa17 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 10:52:10 +0100 Subject: [PATCH 113/131] Fix code for extraction of categories and filter rules from Revit when pulling --- .../Convert/Revit/FromRevit/ViewFilter.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 58e37f9d1..4158ee488 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -33,6 +33,7 @@ using System.CodeDom; using System; using Autodesk.Revit.DB.Architecture; +using Autodesk.Revit.Creation; namespace BH.Revit.Engine.Core { @@ -59,17 +60,23 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par viewFilter = new oM.Adapters.Revit.Elements.ViewFilter { Name = revitViewFilter.Name }; /* 2. Transfer List of CATEGORY NAMES */ - viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => revitViewFilter.Document.GetElement(catId).Name).ToList(); + List categories = new List(); + foreach (Autodesk.Revit.DB.Category cat in revitViewFilter.Document.Settings.Categories) { categories.Add(cat); } + viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat=>cat.Id==catId).First().Name).ToList(); /* 3. Transfer List of FILTER RULES */ - //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS - List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) - .ToList(); - //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) - List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); - //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects - viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); + // If the Filter is assigned with any rules..... + if (((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().Count !=0) + { + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS + List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() + .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) + .ToList(); + //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) + List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); + //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects + viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); + } //Set identifiers, parameters & custom data viewFilter.SetIdentifiers(revitViewFilter); From 71f2d47ee2dd00fd66a175613c75a1219a2d7a56 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 16:13:39 +0100 Subject: [PATCH 114/131] Add GetParameterById Utility function and minor updates to parameter collection streams --- .../Convert/Revit/FromRevit/ViewFilter.cs | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 4158ee488..bf0bd8a0f 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -66,14 +66,17 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 3. Transfer List of FILTER RULES */ // If the Filter is assigned with any rules..... - if (((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().Count !=0) + if (revitViewFilter.GetElementFilter()!=null) { - //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS - List parameterNames = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules() - .Select(rule => revitViewFilter.Document.GetElement(rule.GetRuleParameter()).Name.ToString()) - .ToList(); + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS + //List parameterNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() + Dictionary filterAndParNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() + .Select(filter => ((ElementParameterFilter)filter).GetRules()) + .SelectMany(list => list) + .ToDictionary(rule => rule, rule => (GetParameterById(revitViewFilter.Document, rule.GetRuleParameter()).Definition.Name.ToString())); + //.ToList(); //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) - List revitFilterRules = ((ElementParameterFilter)revitViewFilter.GetElementFilter()).GetRules().ToList(); + List revitFilterRules = (filterAndParNames.Keys.ToList()); //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); } @@ -97,25 +100,25 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par NumberComparisonType bhomNumericEvaluator = 0; // FILTER STRING RULE - if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterStringRule))) + if (revitRule.GetType()== typeof(Autodesk.Revit.DB.FilterStringRule)) { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator); } // FILTER DOUBLE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterDoubleRule))) + else if (revitRule.GetType()==typeof(Autodesk.Revit.DB.FilterDoubleRule)) { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } // FILTER INTEGER RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterIntegerRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterIntegerRule)) { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } // FILTER ELEMENTID RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterElementIdRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterElementIdRule)) { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } // FILTER CATEGORY RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterCategoryRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterCategoryRule)) { return (oM.Revit.FilterRules.FilterRule)FilterCategoryRuleFromRevit(revitViewFilter, revitRule); } // FILTER PARAMETER VALUE PRESENCE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.ParameterValuePresenceRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.ParameterValuePresenceRule)) { return (oM.Revit.FilterRules.FilterRule)ParameterValuePresenceRuleFromRevit(revitViewFilter, revitRule); } // FILTER INVERSE RULE - else if (revitRule.GetType().IsSubclassOf(typeof(Autodesk.Revit.DB.FilterInverseRule))) + else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterInverseRule)) { return FilterInverseRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator, bhomNumericEvaluator); } return null; }).ToList(); @@ -485,7 +488,31 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P } } -} + + /* UTILITY METHODS */ + + private static Parameter GetParameterById(Autodesk.Revit.DB.Document doc, ElementId parameterId) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by its own Id + List matchingParams=element.Parameters().Where(prm => prm.Id == parameterId).ToList(); + + if (matchingParams.Count!=0) + {return matchingParams.First();} + + } + + // If the parameter is not found, return InvalidElementId + return null; + } + + } } From bb2b11cfc27bb2bc0c880986f7d77919c977633c Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 18:57:32 +0100 Subject: [PATCH 115/131] Add use of utility function GetParameterById where required to get parameter objects --- .../Convert/Revit/FromRevit/ViewFilter.cs | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index bf0bd8a0f..498a24fe4 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -135,7 +135,7 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t // Downcast Revit FilterRule obj to Revit FilterStringRule obj Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; // Extract name and value assigned to the parameter of the FilterStringRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterStringRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document, revitFilterStringRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterStringRule.RuleString; // Get the RuleEvaluator of the FilterStringRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -192,7 +192,7 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t // Downcast Revit FilterRule obj to Revit FilterDoubleRule obj Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; // Extract name and value assigned to the parameter of the FilterDoubleRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterDoubleRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document,revitFilterDoubleRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterDoubleRule.RuleValue.ToString(); // Get the RuleEvaluator of the FilterDoubleRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -240,7 +240,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit // Downcast Revit FilterRule obj to Revit FilterIntegerRule obj Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; // Extract name and value assigned to the parameter of the FilterIntegerRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterIntegerRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterIntegerRule.RuleValue.ToString(); // Get the RuleEvaluator of the FilterIntegerRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -288,7 +288,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR // Downcast Revit FilterRule obj to Revit FilterElementIdRule obj Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj - string paramName = revitViewFilter.Document.GetElement(revitFilterElemIdRule.GetRuleParameter()).Name; + string paramName = GetParameterById(revitViewFilter.Document, revitFilterElemIdRule.GetRuleParameter()).Definition.Name; string paramValue = revitFilterElemIdRule.RuleValue.ToString(); // Get the RuleEvaluator of the FilterElementIdRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) @@ -380,23 +380,23 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterStringEquals"): + case ("Autodesk.Revit.DB.FilterStringEquals"): bhomTextEvaluator = TextComparisonType.NotEqual; break; - case ("FilterStringBeginsWith"): + case ("Autodesk.Revit.DB.FilterStringBeginsWith"): bhomTextEvaluator = TextComparisonType.NotStartsWith; break; - case ("FilterStringEndsWith"): + case ("Autodesk.Revit.DB.FilterStringEndsWith"): bhomTextEvaluator = TextComparisonType.NotEndsWith; break; - case ("FilterStringContains"): + case ("Autodesk.Revit.DB.FilterStringContains"): bhomTextEvaluator = TextComparisonType.ContainsNot; break; default: break; } oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); - bhomFilterStringRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterStringRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; bhomFilterStringRule.Evaluator = bhomTextEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; @@ -406,24 +406,24 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): + case ("Autodesk.Revit.DB.FilterNumericEquals"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericGreater"): + case ("Autodesk.Revit.DB.FilterNumericGreater"): bhomNumericEvaluator = NumberComparisonType.Less; break; - case ("FilterNumericGreaterOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericLess"): + case ("Autodesk.Revit.DB.FilterNumericLess"): bhomNumericEvaluator = NumberComparisonType.Greater; break; - case ("FilterNumericLessOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); - bhomFilterDoubleRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterDoubleRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; @@ -433,24 +433,24 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): + case ("Autodesk.Revit.DB.FilterNumericEquals"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericGreater"): + case ("Autodesk.Revit.DB.FilterNumericGreater"): bhomNumericEvaluator = NumberComparisonType.Less; break; - case ("FilterNumericGreaterOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericLess"): + case ("Autodesk.Revit.DB.FilterNumericLess"): bhomNumericEvaluator = NumberComparisonType.Greater; break; - case ("FilterNumericLessOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); - bhomFilterIntegerRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterIntegerRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; @@ -460,24 +460,24 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P { switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) { - case ("FilterNumericEquals"): + case ("Autodesk.Revit.DB.FilterNumericEquals"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericGreater"): + case ("Autodesk.Revit.DB.FilterNumericGreater"): bhomNumericEvaluator = NumberComparisonType.Less; break; - case ("FilterNumericGreaterOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): bhomNumericEvaluator = NumberComparisonType.NotEqual; break; - case ("FilterNumericLess"): + case ("Autodesk.Revit.DB.FilterNumericLess"): bhomNumericEvaluator = NumberComparisonType.Greater; break; - case ("FilterNumericLessOrEqual"): + case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; break; } oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); - bhomFilterElementIdRule.ParameterName = revitViewFilter.Document.GetElement(innerRule.GetRuleParameter()).Name; + bhomFilterElementIdRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterElementIdRule; From 4e5f8f9f5d5cafd4f0f9ab900fa0325be39df36a Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 28 Aug 2024 19:21:24 +0100 Subject: [PATCH 116/131] Add conversion of double internal units when pulling filter parameter values --- Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 498a24fe4..5f7b56c28 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -193,7 +193,8 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; // Extract name and value assigned to the parameter of the FilterDoubleRule obj string paramName = GetParameterById(revitViewFilter.Document,revitFilterDoubleRule.GetRuleParameter()).Definition.Name; - string paramValue = revitFilterDoubleRule.RuleValue.ToString(); + ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitFilterDoubleRule.GetRuleParameter()).GetUnitTypeId(); + string paramValue = UnitUtils.ConvertFromInternalUnits(revitFilterDoubleRule.RuleValue,paramTypeId).ToString(); // Get the RuleEvaluator of the FilterDoubleRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); @@ -241,7 +242,8 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; // Extract name and value assigned to the parameter of the FilterIntegerRule obj string paramName = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).Definition.Name; - string paramValue = revitFilterIntegerRule.RuleValue.ToString(); + ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).GetUnitTypeId(); + string paramValue = UnitUtils.ConvertFromInternalUnits(revitFilterIntegerRule.RuleValue, paramTypeId).ToString(); // Get the RuleEvaluator of the FilterIntegerRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); @@ -289,7 +291,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj string paramName = GetParameterById(revitViewFilter.Document, revitFilterElemIdRule.GetRuleParameter()).Definition.Name; - string paramValue = revitFilterElemIdRule.RuleValue.ToString(); + string paramValue = revitViewFilter.Document.GetElement(revitFilterElemIdRule.RuleValue).Name.ToString(); // Get the RuleEvaluator of the FilterElementIdRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); From 4796b1224f9ccb8242eb8dc137684d4e995544bb Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 14:51:09 +0100 Subject: [PATCH 117/131] Add Update Method for Autodesk Revit View3D Class The View3D Class is a subclass of the View Class. To let the BHoM run the Update method on the View3D class, we need to specify an overloaded version of the Update Method taking a View3D class instance rather than a View class instance as input. --- Revit_Core_Engine/Modify/Update.cs | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 01f290d5e..0b58eaa10 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -302,6 +302,60 @@ public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View return true; } + + [Description("Updates the existing Revit View based on the given BHoM View.")] + [Input("element", "Revit View instance to be updated.")] + [Input("bHoMObject", "BHoM View, based on which the Revit View will be updated.")] + [Input("settings", "Revit adapter settings to be used while performing the action.")] + [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] + [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] + public static bool Update(this View3D element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + { + /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ + + // Via Streams... + bHoMObject.FiltersWithOverrides + // 1. Turn Filters and Overrides into Keys and Values of a Dictionary + .ToDictionary(x => x.Filter, x => x.Overrides) + // 2. Turn the Dictionary into a List of KeyValue Pairs (to allow use of ForEach() + .ToList>() + // 3. Assign Filters to View and Set their Overrides + .ForEach(kvp => { + ParameterFilterElement pfe = kvp.Key.ToRevitParameterFilterElement(element.Document, settings); + // 3.1 Add ViewFilter to the View + element.AddFilter(pfe.Id); + // 3.2 Get the Revit FillPatternElement Objects for CutPattern and SurfacePattern + FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); + FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) + .OfClass(typeof(FillPatternElement)) + .Cast() + .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); + // 3.3 Create the OverrideGraphics by Properties + OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); + Color revitCutColor = new Color(kvp.Value.CutColor.R, kvp.Value.CutColor.G, kvp.Value.CutColor.B); + Color revitSurfaceColor = new Color(kvp.Value.SurfaceColor.R, kvp.Value.SurfaceColor.G, kvp.Value.SurfaceColor.B); + overrideGraphicsSettings.SetCutLineColor(revitLineColor); + overrideGraphicsSettings.SetProjectionLineColor(revitLineColor); + overrideGraphicsSettings.SetCutBackgroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutBackgroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetCutForegroundPatternId(revitCutPattern.Id); + overrideGraphicsSettings.SetCutForegroundPatternColor(revitCutColor); + overrideGraphicsSettings.SetSurfaceBackgroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceBackgroundPatternColor(revitSurfaceColor); + overrideGraphicsSettings.SetSurfaceForegroundPatternId(revitSurfacePattern.Id); + overrideGraphicsSettings.SetSurfaceForegroundPatternColor(revitSurfaceColor); + // 3.4 Assign Overrides to the ViewFilter + element.SetFilterOverrides(pfe.Id, overrideGraphicsSettings); + }); + + element.CopyParameters(bHoMObject, settings); + return true; + } + /***************************************************/ [Description("Updates the existing Revit ParameterFilterElement based on the given BHoM ViewFilter.")] From e236c32fef0d7db1cf5d08dce0219112538cfe01 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 14:57:14 +0100 Subject: [PATCH 118/131] Turn Update Methods for View and View3D into a single method using Generic Type Since View3D is a subclass of View in the Revit API, we can make the Update method work on a generic type T, specifying that it must be extending the revit api superclass View. --- Revit_Core_Engine/Modify/Update.cs | 56 +----------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 0b58eaa10..62b1062ee 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -257,7 +257,7 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re [Input("settings", "Revit adapter settings to be used while performing the action.")] [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] - public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) + public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) where T:Autodesk.Revit.DB.View { /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ @@ -302,60 +302,6 @@ public static bool Update(this View element, BH.oM.Adapters.Revit.Elements.View return true; } - - [Description("Updates the existing Revit View based on the given BHoM View.")] - [Input("element", "Revit View instance to be updated.")] - [Input("bHoMObject", "BHoM View, based on which the Revit View will be updated.")] - [Input("settings", "Revit adapter settings to be used while performing the action.")] - [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] - [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] - public static bool Update(this View3D element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) - { - /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ - - // Via Streams... - bHoMObject.FiltersWithOverrides - // 1. Turn Filters and Overrides into Keys and Values of a Dictionary - .ToDictionary(x => x.Filter, x => x.Overrides) - // 2. Turn the Dictionary into a List of KeyValue Pairs (to allow use of ForEach() - .ToList>() - // 3. Assign Filters to View and Set their Overrides - .ForEach(kvp => { - ParameterFilterElement pfe = kvp.Key.ToRevitParameterFilterElement(element.Document, settings); - // 3.1 Add ViewFilter to the View - element.AddFilter(pfe.Id); - // 3.2 Get the Revit FillPatternElement Objects for CutPattern and SurfacePattern - FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) - .OfClass(typeof(FillPatternElement)) - .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); - FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) - .OfClass(typeof(FillPatternElement)) - .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); - // 3.3 Create the OverrideGraphics by Properties - OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); - Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); - Color revitCutColor = new Color(kvp.Value.CutColor.R, kvp.Value.CutColor.G, kvp.Value.CutColor.B); - Color revitSurfaceColor = new Color(kvp.Value.SurfaceColor.R, kvp.Value.SurfaceColor.G, kvp.Value.SurfaceColor.B); - overrideGraphicsSettings.SetCutLineColor(revitLineColor); - overrideGraphicsSettings.SetProjectionLineColor(revitLineColor); - overrideGraphicsSettings.SetCutBackgroundPatternId(revitCutPattern.Id); - overrideGraphicsSettings.SetCutBackgroundPatternColor(revitCutColor); - overrideGraphicsSettings.SetCutForegroundPatternId(revitCutPattern.Id); - overrideGraphicsSettings.SetCutForegroundPatternColor(revitCutColor); - overrideGraphicsSettings.SetSurfaceBackgroundPatternId(revitSurfacePattern.Id); - overrideGraphicsSettings.SetSurfaceBackgroundPatternColor(revitSurfaceColor); - overrideGraphicsSettings.SetSurfaceForegroundPatternId(revitSurfacePattern.Id); - overrideGraphicsSettings.SetSurfaceForegroundPatternColor(revitSurfaceColor); - // 3.4 Assign Overrides to the ViewFilter - element.SetFilterOverrides(pfe.Id, overrideGraphicsSettings); - }); - - element.CopyParameters(bHoMObject, settings); - return true; - } - /***************************************************/ [Description("Updates the existing Revit ParameterFilterElement based on the given BHoM ViewFilter.")] From 98533680c40730d841f71f4940460246accbc448 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 15:25:50 +0100 Subject: [PATCH 119/131] Fix Fill and Line Pattern Name search turning letter case to Upper --- Revit_Core_Engine/Modify/Update.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 62b1062ee..6641c39d1 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -275,11 +275,11 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.CutPattern.ToString())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().ToUpper())); FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.Contains(kvp.Value.SurfacePattern.ToString())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().ToUpper())); // 3.3 Create the OverrideGraphics by Properties OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); From bdde33f46dfa00507ea00cdcf8cdb835dfd6d6cd Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 2 Sep 2024 16:34:06 +0100 Subject: [PATCH 120/131] Fix bug text comparison between Cut and Surface Patterns --- Revit_Core_Engine/Modify/Update.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 6641c39d1..79d25de25 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -275,11 +275,11 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().ToUpper())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().Replace("_"," ").ToUpper())); FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().ToUpper())); + .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().Replace("_", " ").ToUpper())); // 3.3 Create the OverrideGraphics by Properties OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); From d56be5bcfe00d64ccaf4be3c55475b2e0d34d2e0 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 14 Oct 2024 18:30:53 +0100 Subject: [PATCH 121/131] Incorporate PR comments from Pawel Baran - Part01 --- .../Convert/Revit/FromRevit/View.cs | 47 +- .../Convert/Revit/FromRevit/ViewFilter.cs | 30 +- .../Revit/ToRevit/ParameterFilterElement.cs | 487 +++++++++--------- Revit_Core_Engine/Modify/Update.cs | 5 +- Revit_oM/Enums/FillPattern.cs | 16 +- Revit_oM/Enums/LinePattern.cs | 8 +- Revit_oM/FilterRules/FilterLevelRule.cs | 2 +- .../FilterRules/FilterNumericValueRule.cs | 2 +- Revit_oM/FilterRules/FilterStringRule.cs | 2 +- .../FilterRules/ParameterValuePresenceRule.cs | 2 +- 10 files changed, 305 insertions(+), 296 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 09a7a94f8..03ca2e207 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -86,46 +86,47 @@ private static OverrideGraphicSettings overrideGraphicSettingsFromRevit(this Vie // Initialize BHoM OverrideGraphicsSettings object OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); + // Convert COLORS - overrideGraphicsSettings.LineColor = System.Drawing.Color.FromArgb(revitOverrides.CutLineColor.Red, revitOverrides.CutLineColor.Green, revitOverrides.CutLineColor.Blue); - overrideGraphicsSettings.CutColor = System.Drawing.Color.FromArgb(revitOverrides.CutBackgroundPatternColor.Red, revitOverrides.CutBackgroundPatternColor.Green, revitOverrides.CutBackgroundPatternColor.Blue); - overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); + if (revitOverrides.CutLineColor.IsValid) overrideGraphicsSettings.LineColor = System.Drawing.Color.FromArgb(revitOverrides.CutLineColor.Red, revitOverrides.CutLineColor.Green, revitOverrides.CutLineColor.Blue); + if (revitOverrides.CutForegroundPatternColor.IsValid) overrideGraphicsSettings.CutColor = System.Drawing.Color.FromArgb(revitOverrides.CutBackgroundPatternColor.Red, revitOverrides.CutBackgroundPatternColor.Green, revitOverrides.CutBackgroundPatternColor.Blue); + if (revitOverrides.SurfaceBackgroundPatternColor.IsValid) overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); // Convert LINE PATTERNS String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; - if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DASH; } - else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DOT; } - else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.HIDDEN; } - else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.SOLID; } + if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dash; } + else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dot; } + else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Hidden; } + else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Solid; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } // Convert CUT PATTERNS String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; - if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } - else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } - else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } - else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.STEEL; } - else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.SOLID; } - else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.VERTICAL; } + if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Steel; } + else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Solid; } + else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Vertical; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } // Convert SURFACE PATTERNS String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; - if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CROSSHATCH; } - else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_CROSSHATCH; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_DOWN; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DIAGONAL_UP; } - else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.HORIZONTAL; } - else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.STEEL; } - else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.SOLID; } - else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.VERTICAL; } + if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Steel; } + else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Solid; } + else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Vertical; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } return overrideGraphicsSettings; diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 5f7b56c28..97249a119 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -68,15 +68,13 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par // If the Filter is assigned with any rules..... if (revitViewFilter.GetElementFilter()!=null) { - //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS - //List parameterNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() - Dictionary filterAndParNames = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() - .Select(filter => ((ElementParameterFilter)filter).GetRules()) - .SelectMany(list => list) - .ToDictionary(rule => rule, rule => (GetParameterById(revitViewFilter.Document, rule.GetRuleParameter()).Definition.Name.ToString())); - //.ToList(); + //Extract the name of all the parameters affected by the rules of the Revit View Filter object (ElementParameterFilter) - via STREAMS + List filterRules = ((ElementLogicalFilter)revitViewFilter.GetElementFilter()).GetFilters() + .Select(filter => ((ElementParameterFilter)filter).GetRules()) + .SelectMany(list => list) + .ToList(); //Extract the Revit Filter Rule objects defined in the Revit View Filter object (ElementParameterFilter) - List revitFilterRules = (filterAndParNames.Keys.ToList()); + List revitFilterRules = (filterRules); //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and assign them to the BHoM ViewFilter objects viewFilter.Rules = FilterRulesFromRevit(revitViewFilter, revitFilterRules); } @@ -178,7 +176,7 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t bhomFilterStringRule = new oM.Revit.FilterRules.FilterStringRule(); bhomFilterStringRule.ParameterName = paramName; bhomFilterStringRule.Value = paramValue; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; + bhomFilterStringRule.ComparisonType = bhomTextEvaluator; return bhomFilterStringRule; } @@ -227,7 +225,7 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = paramName; bhomFilterDoubleRule.Value = paramValue; - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + bhomFilterDoubleRule.ComparisonType = bhomNumericEvaluator; return bhomFilterDoubleRule; } @@ -276,7 +274,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = paramName; bhomFilterIntegerRule.Value = paramValue; - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + bhomFilterIntegerRule.ComparisonType = bhomNumericEvaluator; return bhomFilterIntegerRule; } @@ -324,7 +322,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR bhomFilterElemIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); bhomFilterElemIdRule.ParameterName = paramName; bhomFilterElemIdRule.Value = paramValue; - bhomFilterElemIdRule.Evaluator = bhomNumericEvaluator; + bhomFilterElemIdRule.ComparisonType = bhomNumericEvaluator; return bhomFilterElemIdRule; } @@ -400,7 +398,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); bhomFilterStringRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; - bhomFilterStringRule.Evaluator = bhomTextEvaluator; + bhomFilterStringRule.ComparisonType = bhomTextEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; } // FilterDoubleRule @@ -427,7 +425,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); - bhomFilterDoubleRule.Evaluator = bhomNumericEvaluator; + bhomFilterDoubleRule.ComparisonType = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; } // FilterIntegerRule @@ -454,7 +452,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); - bhomFilterIntegerRule.Evaluator = bhomNumericEvaluator; + bhomFilterIntegerRule.ComparisonType = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; } // FilterElementIdRule @@ -481,7 +479,7 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); bhomFilterElementIdRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); - bhomFilterElementIdRule.Evaluator = bhomNumericEvaluator; + bhomFilterElementIdRule.ComparisonType = bhomNumericEvaluator; return (oM.Revit.FilterRules.FilterRule)bhomFilterElementIdRule; } default: diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index ac7711a99..34460952a 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -72,9 +72,9 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(catName => catName.ToUpper().Replace(" ", "")) // Get the corresponding BuiltInCategories .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) - .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_","")) + .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_", "")) .ToList(); - return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]);}) + return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]); }) // Get the ElementIds of the BuiltInCategories .Select(builtInCat => new ElementId(builtInCat)) // Turn the Stream into a List of ElementIds @@ -87,8 +87,8 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt // 2. BUILD THE REVIT FILTER RULES and ASSIGN THEM TO THE PARAMETERFILTERELEMENT /* Via use of Streams*/ - if (filter.Rules.Count != 0) - { + if (filter.Rules.Count != 0) + { ElementFilter elFilter = new LogicalAndFilter(filter.Rules .GroupBy(rule => rule.GetType()) .ToDictionary(grp => grp.Key, grp => grp.ToList()) @@ -148,16 +148,16 @@ public static Autodesk.Revit.DB.FilterRule filterRuleToRevit(Document document, // FilterCategoryRule if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterCategoryRule)) - { return filterCategoryRuleToRevit(document, (oM.Revit.FilterRules.FilterCategoryRule)filterRule); } + { return filterCategoryRuleToRevit(document, (oM.Revit.FilterRules.FilterCategoryRule)filterRule); } // FilterMaterialRule else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterMaterialRule)) - { return filterMaterialRuleToRevit(document, (oM.Revit.FilterRules.FilterMaterialRule)filterRule); } + { return filterMaterialRuleToRevit(document, (oM.Revit.FilterRules.FilterMaterialRule)filterRule); } // FilterLevelRule else if (filterRule.GetType() == typeof(oM.Revit.FilterRules.FilterLevelRule)) - { return filterLevelRuleToRevit(document, (oM.Revit.FilterRules.FilterLevelRule)filterRule); } + { return filterLevelRuleToRevit(document, (oM.Revit.FilterRules.FilterLevelRule)filterRule); } // FilterValueRule else if (filterRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterValueRule))) - { return filterValueRuleToRevit(document, (oM.Revit.FilterRules.FilterValueRule)filterRule); } + { return filterValueRuleToRevit(document, (oM.Revit.FilterRules.FilterValueRule)filterRule); } return null; @@ -171,10 +171,10 @@ private static Autodesk.Revit.DB.FilterRule filterCategoryRuleToRevit(Document d /* 2. EXTRACT CATEGORIES */ List categories = new List(); - foreach (Autodesk.Revit.DB.Category cat in document.Settings.Categories) { categories.Add(cat);} - + foreach (Autodesk.Revit.DB.Category cat in document.Settings.Categories) { categories.Add(cat); } + /* 2. GET THE ELEMENT IDS OF THE CATEGORIES STORED IN THE FILTERCATEGORYRULE */ - List categoryIds = categories + List categoryIds = categories // Retain only the Categories having name appearing in the filter's list (INTERMEDIATE OPERATION) .Where(elem => filterCategoryRule.CategoryNames.Contains(elem.Name)) // Cast down to Category Class Instances (INTERMEDIATE OPERATION) @@ -204,7 +204,7 @@ private static Autodesk.Revit.DB.FilterRule filterMaterialRuleToRevit(Document d //revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), filterMaterialRule.MaterialName, true); FilteredElementCollector collector = new FilteredElementCollector(document); - Element mat=collector.OfClass(typeof(Material)).Where(material => material.Name == filterMaterialRule.MaterialName).First(); + Element mat = collector.OfClass(typeof(Material)).Where(material => material.Name == filterMaterialRule.MaterialName).First(); revitFilterRule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(parameter), mat.Id); return revitFilterRule; @@ -217,7 +217,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu /* 1. INITIALIZE FILTERRULE AND BUILTINPARAMETER INSTANCES */ Autodesk.Revit.DB.FilterRule revitFilterRule = null; BuiltInParameter levParam = BuiltInParameter.SCHEDULE_LEVEL_PARAM; - ElementId levParamId=new ElementId(levParam); + ElementId levParamId = new ElementId(levParam); ElementId levelId; /* 2. GET ELEVATION OF LEVEL CORRESPONDING TO INPUT LEVEL NAME */ @@ -242,7 +242,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu /* 3. CREATE FILTERS RULE */ // Based on level's elevation and LevelComparisonType... - switch (filterLevelRule.Evaluator) + switch (filterLevelRule.ComparisonType) { case LevelComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory @@ -267,7 +267,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu case LevelComparisonType.AtOrBelow: revitFilterRule = ParameterFilterRuleFactory .CreateLessOrEqualRule(levParamId, levelId); - break; + break; default: break; } @@ -278,288 +278,301 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu /***************************************************/ + private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document, oM.Revit.FilterRules.FilterValueRule filterValueRule) { - private static Autodesk.Revit.DB.FilterRule filterValueRuleToRevit(Document document,oM.Revit.FilterRules.FilterValueRule filterValueRule) { + /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; - /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ - Autodesk.Revit.DB.FilterRule revitFilterRule = null; + /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ + ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); + Parameter parameter = GetParameterByName(document, filterValueRule.ParameterName); - /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ - ElementId parameterId = GetParameterIdByName(document, filterValueRule.ParameterName); - Parameter parameter = GetParameterByName(document, filterValueRule.ParameterName); + /* 3. CREATE FILTER-RULE */ - /* 3. CREATE FILTER-RULE */ + // Based on FilterStringRule... + if (filterValueRule.GetType() == typeof(FilterStringRule) || + filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) + { + FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; - // Based on FilterStringRule... - if (filterValueRule.GetType()==typeof(FilterStringRule)|| - filterValueRule.GetType().IsSubclassOf(typeof(FilterStringRule))) + switch (filterStringValueRule.ComparisonType) { - FilterStringRule filterStringValueRule = (FilterStringRule)filterValueRule; + case TextComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Contains: + revitFilterRule = ParameterFilterRuleFactory + .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.ContainsNot: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotContainsRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.StartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotStartsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.EndsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.NotEndsWith: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, (string)filterStringValueRule.Value, false); + break; + case TextComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + break; + default: + break; + } + + // Based on FilterNumericValueRule... + } else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterNumericValueRule) || + filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) + { + + if ((filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule))) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; + + /* 2. Convert input value to target data type */ + Double doubleValue = 0.0; + Boolean boolParam = Double.TryParse(filterDoubleRule.Value, out doubleValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); + } - switch (filterStringValueRule.Evaluator) + /* 3. Convert units of input value to internal units */ + double convertedValue = UnitUtils.ConvertToInternalUnits(doubleValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ + switch (filterDoubleRule.ComparisonType) { - case TextComparisonType.Equal: + case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateEqualsRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.NotEqual: + case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateNotEqualsRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.Contains: + case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateContainsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.ContainsNot: + case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotContainsRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterOrEqualRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.StartsWith: + case NumberComparisonType.Less: revitFilterRule = ParameterFilterRuleFactory - .CreateBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateLessRule(parameterId, convertedValue, 0.01); break; - case TextComparisonType.NotStartsWith: + case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotBeginsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateLessOrEqualRule(parameterId, convertedValue, 0.01); + break; + default: break; - case TextComparisonType.EndsWith: + } + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterIntegerRule)) + { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterIntegerRule filterIntegerRule = (oM.Revit.FilterRules.FilterIntegerRule)filterValueRule; + + /* 2. Convert input value to target data type */ + int intValue = 0; + Boolean boolParam = int.TryParse(filterIntegerRule.Value, out intValue); + + if (!boolParam) + { + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); + } + + /* 3. Convert units of input value to internal units */ + int convertedValue = (int)UnitUtils.ConvertToInternalUnits((Double)intValue, parameter.GetUnitTypeId()); + + /* 4. Convert Evaluator from Revit to BHoM */ + switch (filterIntegerRule.ComparisonType) + { + case NumberComparisonType.Equal: revitFilterRule = ParameterFilterRuleFactory - .CreateEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateEqualsRule(parameterId, convertedValue); break; - case TextComparisonType.NotEndsWith: + case NumberComparisonType.NotEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateNotEndsWithRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateNotEqualsRule(parameterId, convertedValue); break; - case TextComparisonType.Greater: + case NumberComparisonType.Greater: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterRule(parameterId, convertedValue); break; - case TextComparisonType.GreaterOrEqual: + case NumberComparisonType.GreaterOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateGreaterOrEqualRule(parameterId, convertedValue); break; - case TextComparisonType.Less: - revitFilterRule=ParameterFilterRuleFactory - .CreateLessRule(parameterId,(string)filterStringValueRule.Value, false); + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, convertedValue); break; - case TextComparisonType.LessOrEqual: + case NumberComparisonType.LessOrEqual: revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, (string)filterStringValueRule.Value, false); + .CreateLessOrEqualRule(parameterId, convertedValue); break; default: break; } - - // Based on FilterNumericValueRule... - } else if (filterValueRule.GetType()==typeof(oM.Revit.FilterRules.FilterNumericValueRule)|| - filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.FilterNumericValueRule))) + } + else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterElementIdRule)) { + /* 1. Downcast to subclass */ + oM.Revit.FilterRules.FilterElementIdRule filterElementIdRule = (oM.Revit.FilterRules.FilterElementIdRule)filterValueRule; - if ((filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterDoubleRule))) - { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterDoubleRule filterDoubleRule = (oM.Revit.FilterRules.FilterDoubleRule)filterValueRule; - - /* 2. Convert input value to target data type */ - Double doubleValue=0.0; - Boolean boolParam=Double.TryParse(filterDoubleRule.Value,out doubleValue); - - if (!boolParam) - { - BH.Engine.Base.Compute.RecordError("The Input Value of the FilterDoubleRule is not a Double Type value."); - } - - /* 3. Convert units of input value to internal units */ - double convertedValue =UnitUtils.ConvertToInternalUnits(doubleValue, parameter.GetUnitTypeId()); - - /* 4. Convert Evaluator from Revit to BHoM */ - switch (filterDoubleRule.Evaluator) - { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, convertedValue, 0.01); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, convertedValue, 0.01); - break; - default: - break; - } - } - else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterIntegerRule)) + /* 2. Convert input value to target data type */ + Boolean boolParam = int.TryParse(filterElementIdRule.Value, out int intValue); + ElementId elId = new ElementId(intValue); + + if (!boolParam) { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterIntegerRule filterIntegerRule = (oM.Revit.FilterRules.FilterIntegerRule)filterValueRule; - - /* 2. Convert input value to target data type */ - int intValue = 0; - Boolean boolParam = int.TryParse(filterIntegerRule.Value, out intValue); - - if (!boolParam) - { - BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); - } - - /* 3. Convert units of input value to internal units */ - int convertedValue = (int)UnitUtils.ConvertToInternalUnits((Double)intValue, parameter.GetUnitTypeId()); - - /* 4. Convert Evaluator from Revit to BHoM */ - switch (filterIntegerRule.Evaluator) - { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, convertedValue); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, convertedValue); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, convertedValue); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, convertedValue); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, convertedValue); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, convertedValue); - break; - default: - break; - } + BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); } - else if (filterValueRule.GetType() == typeof(oM.Revit.FilterRules.FilterElementIdRule)) + + /* 3. Convert Evaluator from Revit to BHoM */ + switch (filterElementIdRule.ComparisonType) { - /* 1. Downcast to subclass */ - oM.Revit.FilterRules.FilterElementIdRule filterElementIdRule = (oM.Revit.FilterRules.FilterElementIdRule)filterValueRule; - - /* 2. Convert input value to target data type */ - Boolean boolParam = int.TryParse(filterElementIdRule.Value, out int intValue); - ElementId elId = new ElementId(intValue); - - if (!boolParam) - { - BH.Engine.Base.Compute.RecordError("The Input Value of the FilterIntegerRule is not an Integer Type value."); - } - - /* 3. Convert Evaluator from Revit to BHoM */ - switch (filterElementIdRule.Evaluator) - { - case NumberComparisonType.Equal: - revitFilterRule = ParameterFilterRuleFactory - .CreateEqualsRule(parameterId, elId); - break; - case NumberComparisonType.NotEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateNotEqualsRule(parameterId, elId); - break; - case NumberComparisonType.Greater: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterRule(parameterId, elId); - break; - case NumberComparisonType.GreaterOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateGreaterOrEqualRule(parameterId, elId); - break; - case NumberComparisonType.Less: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessRule(parameterId, elId); - break; - case NumberComparisonType.LessOrEqual: - revitFilterRule = ParameterFilterRuleFactory - .CreateLessOrEqualRule(parameterId, elId); - break; - default: - break; - } + case NumberComparisonType.Equal: + revitFilterRule = ParameterFilterRuleFactory + .CreateEqualsRule(parameterId, elId); + break; + case NumberComparisonType.NotEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateNotEqualsRule(parameterId, elId); + break; + case NumberComparisonType.Greater: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterRule(parameterId, elId); + break; + case NumberComparisonType.GreaterOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateGreaterOrEqualRule(parameterId, elId); + break; + case NumberComparisonType.Less: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessRule(parameterId, elId); + break; + case NumberComparisonType.LessOrEqual: + revitFilterRule = ParameterFilterRuleFactory + .CreateLessOrEqualRule(parameterId, elId); + break; + default: + break; } - } - // Based on ParameterValuePresenceRule... - else if (filterValueRule.GetType()== typeof(oM.Revit.FilterRules.ParameterValuePresenceRule)|| - filterValueRule.GetType().IsSubclassOf(typeof(oM.Revit.FilterRules.ParameterValuePresenceRule))) - { - oM.Revit.FilterRules.ParameterValuePresenceRule parameterValuePresenceRule = (oM.Revit.FilterRules.ParameterValuePresenceRule)filterValueRule; - if (parameterValuePresenceRule.IsPresent) { - revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId);} - else { - revitFilterRule = ParameterFilterRuleFactory.CreateHasNoValueParameterRule(parameterId);} + } else { return null; } + return revitFilterRule; + } - } else { return null; } - return revitFilterRule; - } - private static ElementId GetParameterIdByName(Document doc, string parameterName) + /***************************************************/ + + private static Autodesk.Revit.DB.FilterRule parameterValuePresenceRuleToRevit(Document document, oM.Revit.FilterRules.ParameterValuePresenceRule paramValuePresenceRule) { - // Get all elements in the document - FilteredElementCollector collector = new FilteredElementCollector(doc); - collector.WhereElementIsNotElementType(); + /* 1. INITIALIZE FILTERRULE AND LOGICALFILTER CLASS INSTANCES */ + Autodesk.Revit.DB.FilterRule revitFilterRule = null; - // Iterate through all elements - foreach (Element element in collector) + /* 2. GET the PARAMETER OBJECT and the ELEMENT ID of the PARAMETER OBJECT */ + ElementId parameterId = GetParameterIdByName(document, paramValuePresenceRule.ParameterName); + Parameter parameter = GetParameterByName(document, paramValuePresenceRule.ParameterName); + + if (paramValuePresenceRule.IsPresent) { - // Get the parameter by name - Parameter param = element.LookupParameter(parameterName); - if (param != null) - { - // Return the ElementId of the parameter - return param.Id; - } + revitFilterRule = ParameterFilterRuleFactory.CreateHasValueParameterRule(parameterId); } + else + { + revitFilterRule = ParameterFilterRuleFactory.CreateHasNoValueParameterRule(parameterId); + } + + return revitFilterRule; - // If the parameter is not found, return InvalidElementId - return ElementId.InvalidElementId; } + private static ElementId GetParameterIdByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); - private static Parameter GetParameterByName(Document doc, string parameterName) + // Iterate through all elements + foreach (Element element in collector) { - // Get all elements in the document - FilteredElementCollector collector = new FilteredElementCollector(doc); - collector.WhereElementIsNotElementType(); - - // Iterate through all elements - foreach (Element element in collector) + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) { - // Get the parameter by name - Parameter param = element.LookupParameter(parameterName); - if (param != null) - { - // Return the ElementId of the parameter - return param; - } + // Return the ElementId of the parameter + return param.Id; } + } - // If the parameter is not found, return InvalidElementId - return null; + // If the parameter is not found, return InvalidElementId + return ElementId.InvalidElementId; + } + + + private static Parameter GetParameterByName(Document doc, string parameterName) + { + // Get all elements in the document + FilteredElementCollector collector = new FilteredElementCollector(doc); + collector.WhereElementIsNotElementType(); + + // Iterate through all elements + foreach (Element element in collector) + { + // Get the parameter by name + Parameter param = element.LookupParameter(parameterName); + if (param != null) + { + // Return the ElementId of the parameter + return param; + } } + + // If the parameter is not found, return InvalidElementId + return null; + } + } } diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index 79d25de25..d26c11f67 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -257,7 +257,7 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re [Input("settings", "Revit adapter settings to be used while performing the action.")] [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] - public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) where T:Autodesk.Revit.DB.View + public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) where T:View { /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ @@ -414,9 +414,6 @@ private static void ErrorOnCategoryChange(this FamilyInstance element, IInstance } /***************************************************/ - - - } } diff --git a/Revit_oM/Enums/FillPattern.cs b/Revit_oM/Enums/FillPattern.cs index 17efeff82..81a9e6948 100644 --- a/Revit_oM/Enums/FillPattern.cs +++ b/Revit_oM/Enums/FillPattern.cs @@ -8,13 +8,13 @@ namespace BH.oM.Revit.Enums { public enum FillPattern { - CROSSHATCH, - DIAGONAL_CROSSHATCH, - DIAGONAL_DOWN, - DIAGONAL_UP, - HORIZONTAL, - STEEL, - SOLID, - VERTICAL + CrossHatch, + DiagonalCrossHatch, + DiagonalDown, + DiagonalUp, + Horizontal, + Steel, + Solid, + Vertical } } diff --git a/Revit_oM/Enums/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs index 1da829a39..742a2e96f 100644 --- a/Revit_oM/Enums/LinePattern.cs +++ b/Revit_oM/Enums/LinePattern.cs @@ -8,9 +8,9 @@ namespace BH.oM.Revit.Enums { public enum LinePattern { - DASH, - DOT, - HIDDEN, - SOLID + Dash, + Dot, + Hidden, + Solid } } diff --git a/Revit_oM/FilterRules/FilterLevelRule.cs b/Revit_oM/FilterRules/FilterLevelRule.cs index 5745b4b1d..8f502498c 100644 --- a/Revit_oM/FilterRules/FilterLevelRule.cs +++ b/Revit_oM/FilterRules/FilterLevelRule.cs @@ -10,7 +10,7 @@ namespace BH.oM.Revit.FilterRules public class FilterLevelRule : FilterRule { public virtual string LevelName { get; set; } - public virtual LevelComparisonType Evaluator { get; set; } + public virtual LevelComparisonType ComparisonType { get; set; } } } diff --git a/Revit_oM/FilterRules/FilterNumericValueRule.cs b/Revit_oM/FilterRules/FilterNumericValueRule.cs index 3f9d3d27e..45b16d732 100644 --- a/Revit_oM/FilterRules/FilterNumericValueRule.cs +++ b/Revit_oM/FilterRules/FilterNumericValueRule.cs @@ -9,7 +9,7 @@ namespace BH.oM.Revit.FilterRules { public abstract class FilterNumericValueRule : FilterValueRule { - public virtual NumberComparisonType Evaluator { get; set; } + public virtual NumberComparisonType ComparisonType { get; set; } } diff --git a/Revit_oM/FilterRules/FilterStringRule.cs b/Revit_oM/FilterRules/FilterStringRule.cs index 39116a35c..9b65a4c26 100644 --- a/Revit_oM/FilterRules/FilterStringRule.cs +++ b/Revit_oM/FilterRules/FilterStringRule.cs @@ -9,6 +9,6 @@ namespace BH.oM.Revit.FilterRules { public class FilterStringRule : FilterValueRule { - public virtual TextComparisonType Evaluator { get; set; } + public virtual TextComparisonType ComparisonType { get; set; } } } diff --git a/Revit_oM/FilterRules/ParameterValuePresenceRule.cs b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs index 7089a6bf2..30bfe16d2 100644 --- a/Revit_oM/FilterRules/ParameterValuePresenceRule.cs +++ b/Revit_oM/FilterRules/ParameterValuePresenceRule.cs @@ -7,7 +7,7 @@ namespace BH.oM.Revit.FilterRules { - public class ParameterValuePresenceRule : FilterValueRule + public class ParameterValuePresenceRule : FilterParameterRule { public virtual bool IsPresent { get; set; } } From 4767a61d9ea00c9a759165843eb3f3596ff74e62 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Mon, 14 Oct 2024 18:31:20 +0100 Subject: [PATCH 122/131] Add new abstract class FilterParameterRule Using this abstract class it's possible to decouple the ParameterValuePresence Class from the FilterValueRule class. --- Revit_oM/FilterRules/FilterParameterRule.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Revit_oM/FilterRules/FilterParameterRule.cs diff --git a/Revit_oM/FilterRules/FilterParameterRule.cs b/Revit_oM/FilterRules/FilterParameterRule.cs new file mode 100644 index 000000000..9ba9c8021 --- /dev/null +++ b/Revit_oM/FilterRules/FilterParameterRule.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.oM.Revit.FilterRules +{ + public abstract class FilterParameterRule: FilterRule + { + public virtual string ParameterName { get; set; } + } +} From a6e0960b2195a0d282d868660c2108a3c9b46949 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 11:36:50 +0100 Subject: [PATCH 123/131] Incorporate PR comments from Pawel Baran - Part02 --- Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs | 2 +- .../Convert/Revit/ToRevit/ParameterFilterElement.cs | 2 +- Revit_Core_Engine/Modify/Update.cs | 4 ++-- Revit_oM/Elements/ViewFilter.cs | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 97249a119..36e288155 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -62,7 +62,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 2. Transfer List of CATEGORY NAMES */ List categories = new List(); foreach (Autodesk.Revit.DB.Category cat in revitViewFilter.Document.Settings.Categories) { categories.Add(cat); } - viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat=>cat.Id==catId).First().Name).ToList(); + viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat=>cat.Id==catId).First()).Cast().ToList(); /* 3. Transfer List of FILTER RULES */ // If the Filter is assigned with any rules..... diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 34460952a..1276cac21 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -69,7 +69,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt List categoryIdsList = filter.Categories // Format the string name of the categories - .Select(catName => catName.ToUpper().Replace(" ", "")) + .Select(catObj => catObj.ToString().ToUpper().Replace(" ", "")) // Get the corresponding BuiltInCategories .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_", "")) diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index d26c11f67..b85251b1b 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -313,8 +313,8 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View public static bool Update(this ParameterFilterElement element, BH.oM.Adapters.Revit.Elements.ViewFilter bHoMObject, RevitSettings settings, bool setLocationOnUpdate) { // 1. Collect the ElementIds of the filter's categories - via Streams - List builtInCategoryIds= bHoMObject.Categories.Select(catName => { BuiltInCategory builtInCat; - Enum.TryParse(catName, out builtInCat); + List builtInCategoryIds= bHoMObject.Categories.Select(catObj => { BuiltInCategory builtInCat; + Enum.TryParse(catObj.ToString(), out builtInCat); return builtInCat; }) .Select(builtInCat=> new ElementId(builtInCat)) .ToList(); diff --git a/Revit_oM/Elements/ViewFilter.cs b/Revit_oM/Elements/ViewFilter.cs index 19d833939..13959881d 100644 --- a/Revit_oM/Elements/ViewFilter.cs +++ b/Revit_oM/Elements/ViewFilter.cs @@ -6,12 +6,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using BH.oM.Revit.Enums; namespace BH.oM.Adapters.Revit.Elements { public class ViewFilter : BHoMObject { - public virtual List Categories { get; set; } + public virtual List Categories { get; set; } public virtual List Rules { get; set; } } } From a2377a6a97c5e45d70625f38b06abd5ffd6d84be Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 13:34:03 +0100 Subject: [PATCH 124/131] Incorporate comments from Pawel Baran - Part03 --- .../Convert/Revit/FromRevit/View.cs | 85 +++-- .../Convert/Revit/FromRevit/ViewFilter.cs | 335 ++++++++---------- Revit_Core_Engine/Modify/Update.cs | 4 +- Revit_oM/Enums/LinePattern.cs | 8 +- 4 files changed, 221 insertions(+), 211 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 03ca2e207..29eef3cde 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -93,41 +93,68 @@ private static OverrideGraphicSettings overrideGraphicSettingsFromRevit(this Vie if (revitOverrides.SurfaceBackgroundPatternColor.IsValid) overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); // Convert LINE PATTERNS - String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; - - if (linePatternName.ToUpper().Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dash; } - else if (linePatternName.ToUpper().Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dot; } - else if (linePatternName.ToUpper().Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Hidden; } - else if (linePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Solid; } - else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } + try + { + String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; + + if (linePatternName.Replace(" ","").ToUpper().Contains("DASHDOTDOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DashDotDot; } + else if (linePatternName.ToUpper().Replace(" ","").Contains("DASHDOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DashDot; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("DOUBLEDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DoubleDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("LONGDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.LongDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("LOOSEDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.LooseDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("TRIPLEDASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.TripleDash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("DASH")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dash; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("DOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Dot; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Hidden; } + else if (linePatternName.ToUpper().Replace(" ", "").Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Solid; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } + } + catch + { + BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); + } // Convert CUT PATTERNS - String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; - - if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CrossHatch; } - else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalDown; } - else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalUp; } - else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Horizontal; } - else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Steel; } - else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Solid; } - else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Vertical; } - else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } + try + { + String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; + + if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (cutPatternName.ToUpper().Contains("CROSSHATCH") && cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (cutPatternName.ToUpper().Contains("DIAGONAL") && cutPatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (cutPatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (cutPatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Steel; } + else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Solid; } + else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Vertical; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } + } + catch + { + BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); + } // Convert SURFACE PATTERNS - String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; - - if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CrossHatch; } - else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalDown; } - else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalUp; } - else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Horizontal; } - else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Steel; } - else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Solid; } - else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Vertical; } - else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } + try + { + String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; + + if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CrossHatch; } + else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("DOWN")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalDown; } + else if (surfacePatternName.ToUpper().Contains("DIAGONAL") && surfacePatternName.ToUpper().Contains("UP")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalUp; } + else if (surfacePatternName.ToUpper().Contains("HORIZONTAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Horizontal; } + else if (surfacePatternName.ToUpper().Contains("STEEL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Steel; } + else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Solid; } + else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Vertical; } + else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } + } + catch + { + BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); + } return overrideGraphicsSettings; } diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 36e288155..7ac50b832 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -94,21 +94,18 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par { List bhomFilterRules = revitFilterRules.Select(revitRule => { - TextComparisonType bhomTextEvaluator = 0; - NumberComparisonType bhomNumericEvaluator = 0; - // FILTER STRING RULE if (revitRule.GetType()== typeof(Autodesk.Revit.DB.FilterStringRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule); } // FILTER DOUBLE RULE else if (revitRule.GetType()==typeof(Autodesk.Revit.DB.FilterDoubleRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule); } // FILTER INTEGER RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterIntegerRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule); } // FILTER ELEMENTID RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterElementIdRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule, bhomNumericEvaluator); } + { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule); } // FILTER CATEGORY RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterCategoryRule)) { return (oM.Revit.FilterRules.FilterRule)FilterCategoryRuleFromRevit(revitViewFilter, revitRule); } @@ -117,7 +114,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par { return (oM.Revit.FilterRules.FilterRule)ParameterValuePresenceRuleFromRevit(revitViewFilter, revitRule); } // FILTER INVERSE RULE else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterInverseRule)) - { return FilterInverseRuleFromRevit(revitViewFilter, revitRule, bhomTextEvaluator, bhomNumericEvaluator); } + { return FilterInverseRuleFromRevit(revitViewFilter, revitRule); } return null; }).ToList(); @@ -126,7 +123,7 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -140,35 +137,8 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); // Convert the REVIT FilterStringEvaluator type into the BHOM TextComparisonType Enum - switch (stringEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterStringBeginsWith": - bhomTextEvaluator = TextComparisonType.StartsWith; - break; - case "Autodesk.Revit.DB.FilterStringEndsWith": - bhomTextEvaluator = TextComparisonType.EndsWith; - break; - case "Autodesk.Revit.DB.FilterStringEquals": - bhomTextEvaluator = TextComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterStringContains": - bhomTextEvaluator = TextComparisonType.Contains; - break; - case "Autodesk.Revit.DB.FilterStringGreater": - bhomTextEvaluator = TextComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterStringGreaterOrEqual": - bhomTextEvaluator = TextComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterStringLess": - bhomTextEvaluator = TextComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterStringLessOrEqual": - bhomTextEvaluator = TextComparisonType.LessOrEqual; - break; - default: - break; - } + TextComparisonType bhomTextEvaluator = TextComparisonTypeFromRevit(stringEvaluator.GetType().Name); + // 2. BUILD the BHOM FILTERRULE object @@ -183,7 +153,7 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -198,26 +168,8 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + NumberComparisonType bhomNumericEvaluator = NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); + // 2. BUILD the BHOM FILTERRULE object @@ -232,7 +184,7 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -247,26 +199,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + NumberComparisonType bhomNumericEvaluator=NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); // 2. BUILD the BHOM FILTERRULE object @@ -281,7 +214,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, NumberComparisonType bhomNumericEvaluator) + Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -295,26 +228,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum - switch (numericEvaluator.GetType().ToString()) - { - case "Autodesk.Revit.DB.FilterNumericEquals": - bhomNumericEvaluator = NumberComparisonType.Equal; - break; - case "Autodesk.Revit.DB.FilterNumericGreater": - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case "Autodesk.Revit.DB.FilterNumericGreaterOrEqual": - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - case "Autodesk.Revit.DB.FilterNumericLess": - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case "Autodesk.Revit.DB.FilterNumericLessOrEqual": - bhomNumericEvaluator = NumberComparisonType.LessOrEqual; - break; - default: - break; - } + NumberComparisonType bhomNumericEvaluator = NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); // 2. BUILD the BHOM FILTERRULE object @@ -362,8 +276,7 @@ private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePre } - private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule, TextComparisonType bhomTextEvaluator, NumberComparisonType bhomNumericEvaluator) + private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -373,28 +286,15 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); // Convert the REVIT InnerRule into the corresponding BHOM FilterRule obj - switch (innerRule.GetType().ToString()) + TextComparisonType bhomTextEvaluator = 0; + NumberComparisonType bhomNumericEvaluator = 0; + + switch (innerRule.GetType().Name) { //FilterStringRule - case ("Autodesk.Revit.DB.FilterStringRule"): + case nameof(Autodesk.Revit.DB.FilterStringRule): { - switch (((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterStringEquals"): - bhomTextEvaluator = TextComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterStringBeginsWith"): - bhomTextEvaluator = TextComparisonType.NotStartsWith; - break; - case ("Autodesk.Revit.DB.FilterStringEndsWith"): - bhomTextEvaluator = TextComparisonType.NotEndsWith; - break; - case ("Autodesk.Revit.DB.FilterStringContains"): - bhomTextEvaluator = TextComparisonType.ContainsNot; - break; - default: - break; - } + bhomTextEvaluator = InverseTextComparisonTypeFromRevit(((Autodesk.Revit.DB.FilterStringRule)innerRule).GetEvaluator().GetType().Name); oM.Revit.FilterRules.FilterStringRule bhomFilterStringRule = new BH.oM.Revit.FilterRules.FilterStringRule(); bhomFilterStringRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterStringRule.Value = ((Autodesk.Revit.DB.FilterStringRule)innerRule).RuleString; @@ -402,26 +302,9 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P return (oM.Revit.FilterRules.FilterRule)bhomFilterStringRule; } // FilterDoubleRule - case ("Autodesk.Revit.DB.FilterDoubleRule"): + case nameof(Autodesk.Revit.DB.FilterDoubleRule): { - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } + bhomNumericEvaluator = InverseNumberComparisonTypeFromRevit(((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().Name); oM.Revit.FilterRules.FilterDoubleRule bhomFilterDoubleRule = new BH.oM.Revit.FilterRules.FilterDoubleRule(); bhomFilterDoubleRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterDoubleRule.Value = ((Autodesk.Revit.DB.FilterDoubleRule)innerRule).RuleValue.ToString(); @@ -429,26 +312,9 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P return (oM.Revit.FilterRules.FilterRule)bhomFilterDoubleRule; } // FilterIntegerRule - case ("Autodesk.Revit.DB.FilterIntegerRule"): + case nameof(Autodesk.Revit.DB.FilterIntegerRule): { - switch (((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } + bhomNumericEvaluator = InverseNumberComparisonTypeFromRevit(((Autodesk.Revit.DB.FilterNumericValueRule)innerRule).GetEvaluator().GetType().Name); oM.Revit.FilterRules.FilterIntegerRule bhomFilterIntegerRule = new BH.oM.Revit.FilterRules.FilterIntegerRule(); bhomFilterIntegerRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterIntegerRule.Value = ((Autodesk.Revit.DB.FilterIntegerRule)innerRule).RuleValue.ToString(); @@ -456,26 +322,9 @@ private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this P return (oM.Revit.FilterRules.FilterRule)bhomFilterIntegerRule; } // FilterElementIdRule - case ("Autodesk.Revit.DB.FilterElementIdRule"): + case nameof(Autodesk.Revit.DB.FilterElementIdRule): { - switch (((Autodesk.Revit.DB.FilterElementIdRule)innerRule).GetEvaluator().GetType().ToString()) - { - case ("Autodesk.Revit.DB.FilterNumericEquals"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericGreater"): - bhomNumericEvaluator = NumberComparisonType.Less; - break; - case ("Autodesk.Revit.DB.FilterNumericGreaterOrEqual"): - bhomNumericEvaluator = NumberComparisonType.NotEqual; - break; - case ("Autodesk.Revit.DB.FilterNumericLess"): - bhomNumericEvaluator = NumberComparisonType.Greater; - break; - case ("Autodesk.Revit.DB.FilterNumericLessOrEqual"): - bhomNumericEvaluator = NumberComparisonType.GreaterOrEqual; - break; - } + oM.Revit.FilterRules.FilterElementIdRule bhomFilterElementIdRule = new BH.oM.Revit.FilterRules.FilterElementIdRule(); bhomFilterElementIdRule.ParameterName = GetParameterById(revitViewFilter.Document, innerRule.GetRuleParameter()).Definition.Name; bhomFilterElementIdRule.Value = ((Autodesk.Revit.DB.FilterElementIdRule)innerRule).RuleValue.ToString(); @@ -512,6 +361,134 @@ private static Parameter GetParameterById(Autodesk.Revit.DB.Document doc, Elemen return null; } + + private static NumberComparisonType NumberComparisonTypeFromRevit(string innerRuleName) + { + NumberComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterNumericEquals)): + return NumberComparisonType.Equal; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreater)): + return NumberComparisonType.Greater; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual)): + return NumberComparisonType.GreaterOrEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLess)): + return NumberComparisonType.Less; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLessOrEqual)): + return NumberComparisonType.LessOrEqual; + break; + default: + break; + } + + return (NumberComparisonType)output; + + } + + + private static NumberComparisonType InverseNumberComparisonTypeFromRevit(string innerRuleName) + { + NumberComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterNumericEquals)): + return NumberComparisonType.NotEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreater)): + return NumberComparisonType.Less; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericGreaterOrEqual)): + return NumberComparisonType.NotEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLess)): + return NumberComparisonType.Greater; + break; + case (nameof(Autodesk.Revit.DB.FilterNumericLessOrEqual)): + return NumberComparisonType.GreaterOrEqual; + break; + default: + break; + } + + return (NumberComparisonType)output; + + } + + + + private static TextComparisonType TextComparisonTypeFromRevit(string innerRuleName) + { + TextComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterStringEquals)): + return TextComparisonType.Equal; + break; + case (nameof(Autodesk.Revit.DB.FilterStringBeginsWith)): + return TextComparisonType.StartsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringEndsWith)): + return TextComparisonType.EndsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringContains)): + return TextComparisonType.Contains; + break; + case nameof(Autodesk.Revit.DB.FilterStringGreater): + return TextComparisonType.Greater; + break; + case nameof(Autodesk.Revit.DB.FilterStringGreaterOrEqual): + return TextComparisonType.GreaterOrEqual; + break; + case nameof(Autodesk.Revit.DB.FilterStringLess): + return TextComparisonType.Less; + break; + case nameof(Autodesk.Revit.DB.FilterStringLessOrEqual): + return TextComparisonType.LessOrEqual; + break; + default: + break; + } + + return (TextComparisonType)output; + + } + + + private static TextComparisonType InverseTextComparisonTypeFromRevit(string innerRuleName) + { + TextComparisonType? output = null; + + switch (innerRuleName) + { + case (nameof(Autodesk.Revit.DB.FilterStringEquals)): + return TextComparisonType.NotEqual; + break; + case (nameof(Autodesk.Revit.DB.FilterStringBeginsWith)): + return TextComparisonType.NotStartsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringEndsWith)): + return TextComparisonType.NotEndsWith; + break; + case (nameof(Autodesk.Revit.DB.FilterStringContains)): + return TextComparisonType.ContainsNot; + break; + default: + break; + } + + return (TextComparisonType)output; + + } + + } } diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index b85251b1b..e5381846d 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -275,11 +275,11 @@ public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View FillPatternElement revitCutPattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.CutPattern.ToString().Replace("_"," ").ToUpper())); + .FirstOrDefault(pattern => pattern.Name.Replace(" ", "").ToUpper().Contains(kvp.Value.CutPattern.ToString().Replace(" ","").ToUpper())); FillPatternElement revitSurfacePattern = new FilteredElementCollector(element.Document) .OfClass(typeof(FillPatternElement)) .Cast() - .FirstOrDefault(pattern => pattern.Name.ToUpper().Contains(kvp.Value.SurfacePattern.ToString().Replace("_", " ").ToUpper())); + .FirstOrDefault(pattern => pattern.Name.Replace(" ", "").ToUpper().Contains(kvp.Value.SurfacePattern.ToString().Replace(" ", "").ToUpper())); // 3.3 Create the OverrideGraphics by Properties OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); Color revitLineColor = new Color(kvp.Value.LineColor.R, kvp.Value.LineColor.G, kvp.Value.LineColor.B); diff --git a/Revit_oM/Enums/LinePattern.cs b/Revit_oM/Enums/LinePattern.cs index 742a2e96f..d0025cc17 100644 --- a/Revit_oM/Enums/LinePattern.cs +++ b/Revit_oM/Enums/LinePattern.cs @@ -9,8 +9,14 @@ namespace BH.oM.Revit.Enums public enum LinePattern { Dash, + DashDot, + DashDotDot, + DoubleDash, Dot, Hidden, - Solid + LongDash, + LooseDash, + Solid, + TripleDash } } From fbdae30236946c33550106e911b3d45c53ea3388 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 18:44:39 +0100 Subject: [PATCH 125/131] Incorporate PR Comments from Pawel Baran - Part04 --- .../Convert/Revit/FromRevit/View.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 29eef3cde..7ae2448f0 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -61,14 +61,15 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, if (view != null) return view; - /*1. Transfer ViewFilters and corresponding OverrideGraphicSettings into ViewFilterWithOverrides Objects - via STREAMS */ - List filtersWithOverrides = revitView.GetFilters().ToDictionary - (elId => Convert.ViewFilterFromRevit((ParameterFilterElement)revitView.Document.GetElement(elId)), - elId => overrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() - .Select(kvp => new ViewFilterWithOverrides { Filter = kvp.Key, Overrides = kvp.Value }).ToList(); - - /*2. Create BHoM View Object with Name and FilterWithOverrides objects */ - view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name, FiltersWithOverrides = filtersWithOverrides }; + if (revitView.AreGraphicsOverridesAllowed()) { + /*1. Transfer ViewFilters and corresponding OverrideGraphicSettings into ViewFilterWithOverrides Objects - via STREAMS */ + List filtersWithOverrides = revitView.GetFilters().ToDictionary + (elId => Convert.ViewFilterFromRevit((ParameterFilterElement)revitView.Document.GetElement(elId)), + elId => overrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() + .Select(kvp => new ViewFilterWithOverrides { Filter = kvp.Key, Overrides = kvp.Value }).ToList(); + /*2. Create BHoM View Object with Name and FilterWithOverrides objects */ + view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name, FiltersWithOverrides = filtersWithOverrides };} + else { view = new oM.Adapters.Revit.Elements.View { Name=revitView.Name };} //Set identifiers, parameters & custom data view.SetIdentifiers(revitView); From 518a274491bcac6641d04149eaa486b9c9ec0d98 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 19:09:59 +0100 Subject: [PATCH 126/131] Incorporate PR comments from Pawel Baran - Part 05 --- .../Convert/Revit/FromRevit/ViewFilter.cs | 96 ++++++------------- 1 file changed, 31 insertions(+), 65 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 7ac50b832..1e139cef2 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -92,49 +92,25 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par //Convert the Revit Filter Rule objects into corresponding BHoM FilterRule objects and store them in a List - via STREAMS private static List FilterRulesFromRevit(this ParameterFilterElement revitViewFilter, List revitFilterRules) { - List bhomFilterRules = revitFilterRules.Select(revitRule => - { - // FILTER STRING RULE - if (revitRule.GetType()== typeof(Autodesk.Revit.DB.FilterStringRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterStringRuleFromRevit(revitViewFilter, revitRule); } - // FILTER DOUBLE RULE - else if (revitRule.GetType()==typeof(Autodesk.Revit.DB.FilterDoubleRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterDoubleRuleFromRevit(revitViewFilter, revitRule); } - // FILTER INTEGER RULE - else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterIntegerRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterIntegerRuleFromRevit(revitViewFilter, revitRule); } - // FILTER ELEMENTID RULE - else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterElementIdRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterElementIdRuleFromRevit(revitViewFilter, revitRule); } - // FILTER CATEGORY RULE - else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterCategoryRule)) - { return (oM.Revit.FilterRules.FilterRule)FilterCategoryRuleFromRevit(revitViewFilter, revitRule); } - // FILTER PARAMETER VALUE PRESENCE RULE - else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.ParameterValuePresenceRule)) - { return (oM.Revit.FilterRules.FilterRule)ParameterValuePresenceRuleFromRevit(revitViewFilter, revitRule); } - // FILTER INVERSE RULE - else if (revitRule.GetType() == typeof(Autodesk.Revit.DB.FilterInverseRule)) - { return FilterInverseRuleFromRevit(revitViewFilter, revitRule); } - return null; - }).ToList(); - + List bhomFilterRules = revitFilterRules.Select(revitRule => FilterRuleFromRevit(revitViewFilter, revitRule as dynamic)) + .Cast< oM.Revit.FilterRules.FilterRule >().ToList(); return bhomFilterRules; } - private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule) + + + private static oM.Revit.FilterRules.FilterStringRule FilterRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterStringRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterStringRule obj - Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; // Extract name and value assigned to the parameter of the FilterStringRule obj - string paramName = GetParameterById(revitViewFilter.Document, revitFilterStringRule.GetRuleParameter()).Definition.Name; - string paramValue = revitFilterStringRule.RuleString; + string paramName = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).Definition.Name; + string paramValue = revitRule.RuleString; // Get the RuleEvaluator of the FilterStringRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) - FilterStringRuleEvaluator stringEvaluator = revitFilterStringRule.GetEvaluator(); + FilterStringRuleEvaluator stringEvaluator = revitRule.GetEvaluator(); // Convert the REVIT FilterStringEvaluator type into the BHOM TextComparisonType Enum TextComparisonType bhomTextEvaluator = TextComparisonTypeFromRevit(stringEvaluator.GetType().Name); @@ -152,20 +128,18 @@ private static oM.Revit.FilterRules.FilterStringRule FilterStringRuleFromRevit(t } - private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule) + private static oM.Revit.FilterRules.FilterDoubleRule FilterRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterDoubleRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterDoubleRule obj - Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; // Extract name and value assigned to the parameter of the FilterDoubleRule obj - string paramName = GetParameterById(revitViewFilter.Document,revitFilterDoubleRule.GetRuleParameter()).Definition.Name; - ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitFilterDoubleRule.GetRuleParameter()).GetUnitTypeId(); - string paramValue = UnitUtils.ConvertFromInternalUnits(revitFilterDoubleRule.RuleValue,paramTypeId).ToString(); + string paramName = GetParameterById(revitViewFilter.Document,revitRule.GetRuleParameter()).Definition.Name; + ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).GetUnitTypeId(); + string paramValue = UnitUtils.ConvertFromInternalUnits(revitRule.RuleValue,paramTypeId).ToString(); // Get the RuleEvaluator of the FilterDoubleRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) - FilterNumericRuleEvaluator numericEvaluator = revitFilterDoubleRule.GetEvaluator(); + FilterNumericRuleEvaluator numericEvaluator = revitRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum NumberComparisonType bhomNumericEvaluator = NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); @@ -183,20 +157,18 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterDoubleRuleFromRevit(t } - private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule) + private static oM.Revit.FilterRules.FilterIntegerRule FilterRuleFromRevit(this ParameterFilterElement revitViewFilter, + Autodesk.Revit.DB.FilterIntegerRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterIntegerRule obj - Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; // Extract name and value assigned to the parameter of the FilterIntegerRule obj - string paramName = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).Definition.Name; - ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitFilterIntegerRule.GetRuleParameter()).GetUnitTypeId(); - string paramValue = UnitUtils.ConvertFromInternalUnits(revitFilterIntegerRule.RuleValue, paramTypeId).ToString(); + string paramName = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).Definition.Name; + ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).GetUnitTypeId(); + string paramValue = UnitUtils.ConvertFromInternalUnits(revitRule.RuleValue, paramTypeId).ToString(); // Get the RuleEvaluator of the FilterIntegerRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) - FilterNumericRuleEvaluator numericEvaluator = revitFilterIntegerRule.GetEvaluator(); + FilterNumericRuleEvaluator numericEvaluator = revitRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum NumberComparisonType bhomNumericEvaluator=NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); @@ -214,18 +186,16 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterIntegerRuleFromRevit private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromRevit(this ParameterFilterElement revitViewFilter, - Autodesk.Revit.DB.FilterRule revitRule) + Autodesk.Revit.DB.FilterElementIdRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterElementIdRule obj - Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj - string paramName = GetParameterById(revitViewFilter.Document, revitFilterElemIdRule.GetRuleParameter()).Definition.Name; - string paramValue = revitViewFilter.Document.GetElement(revitFilterElemIdRule.RuleValue).Name.ToString(); + string paramName = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).Definition.Name; + string paramValue = revitViewFilter.Document.GetElement(revitRule.RuleValue).Name.ToString(); // Get the RuleEvaluator of the FilterElementIdRule (Class defining the way the string value // assigned to the parameter is compared with the one assigned by the filter) - FilterNumericRuleEvaluator numericEvaluator = revitFilterElemIdRule.GetEvaluator(); + FilterNumericRuleEvaluator numericEvaluator = revitRule.GetEvaluator(); // Convert the REVIT FilterNumericEvaluator type into the BHOM NumberComparisonType Enum NumberComparisonType bhomNumericEvaluator = NumberComparisonTypeFromRevit(numericEvaluator.GetType().Name); @@ -242,14 +212,12 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR } - private static oM.Revit.FilterRules.FilterCategoryRule FilterCategoryRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) + private static oM.Revit.FilterRules.FilterCategoryRule FilterCategoryRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterCategoryRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterCategoryRule obj - Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj - List categoryNames = revitFilterCategoryRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); + List categoryNames = revitRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); // 2. BUILD the BHOM FILTERRULE object @@ -261,7 +229,7 @@ private static oM.Revit.FilterRules.FilterCategoryRule FilterCategoryRuleFromRev } - private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePresenceRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) + private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePresenceRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.ParameterValuePresenceRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object oM.Revit.FilterRules.ParameterValuePresenceRule bhomParamValuePresenceRule; @@ -269,21 +237,19 @@ private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePre // 2. BUILD the BHOM FILTERRULE object - bhomParamValuePresenceRule.ParameterName = revitViewFilter.Document.GetElement(((Autodesk.Revit.DB.ParameterValuePresenceRule)revitRule).Parameter).Name; + bhomParamValuePresenceRule.ParameterName = revitViewFilter.Document.GetElement((revitRule).Parameter).Name; bhomParamValuePresenceRule.IsPresent = (revitRule.GetType() == typeof(HasValueFilterRule)) ? true : false; return bhomParamValuePresenceRule; } - private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterRule revitRule) + private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterInverseRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterInverseRule obj - Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; // Extract innerRule assigned to the Revit FilterInverseRule obj - Autodesk.Revit.DB.FilterRule innerRule = revitFilterInverseRule.GetInnerRule(); + Autodesk.Revit.DB.FilterRule innerRule = revitRule.GetInnerRule(); // Convert the REVIT InnerRule into the corresponding BHOM FilterRule obj TextComparisonType bhomTextEvaluator = 0; From a75cff001450faa8b974ed6be894e0f69b86b0cd Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Tue, 15 Oct 2024 19:18:51 +0100 Subject: [PATCH 127/131] Fix merge conflict --- Revit_Core_Engine/Convert/FromRevit.cs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/Revit_Core_Engine/Convert/FromRevit.cs b/Revit_Core_Engine/Convert/FromRevit.cs index fe79542f2..715afb7da 100644 --- a/Revit_Core_Engine/Convert/FromRevit.cs +++ b/Revit_Core_Engine/Convert/FromRevit.cs @@ -72,31 +72,6 @@ public static IGeometry IFromRevit(this Location location) [Description("Converts a Revit ParameterFilterElement to a BHoM object based on the requested engineering discipline.")] [Input("parameterFilterElement", "Revit ParameterFilterElement to be converted.")] -<<<<<<< HEAD -======= - [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] - [Input("transform", "Optional, a transform to apply to the converted object.")] - [Input("settings", "Revit adapter settings to be used while performing the convert.")] - [Input("refObjects", "Optional, a collection of objects already processed in the current adapter action, stored to avoid processing the same object more than once.")] - [Output("fromRevit", "Resulted BHoM object converted from a Revit ParameterFilterElement.")] - public static List FromRevit(this ParameterFilterElement parameterFilterElement, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary> refObjects = null) - { - if (parameterFilterElement == null) - { - BH.Engine.Base.Compute.RecordWarning("BHoM object could not be read because Revit Parameter Filter Element is null."); - return null; - } - else - { - return new List { ViewFilterFromRevit(parameterFilterElement, settings, refObjects) }; - } - } - - /***************************************************/ - - [Description("Converts a Revit EnergyAnalysisDetailModel to a BHoM object based on the requested engineering discipline.")] - [Input("energyAnalysisModel", "Revit EnergyAnalysisDetailModel to be converted.")] ->>>>>>> 3338dacd98dc725324d181979cc37e7650ccab0e [Input("discipline", "Engineering discipline based on the BHoM discipline classification.")] [Input("transform", "Optional, a transform to apply to the converted object.")] [Input("settings", "Revit adapter settings to be used while performing the convert.")] From 53b434e531e72f7dfff667e84bc84fe0fe625026 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 16 Oct 2024 12:33:32 +0100 Subject: [PATCH 128/131] Fix minor bugs with dynamic casting and conversion between Category Enum values and Revit Category Objects --- .../Convert/Revit/FromRevit/ViewFilter.cs | 20 ++++++++++++++----- .../Revit/ToRevit/ParameterFilterElement.cs | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index 199bdd880..e0417848c 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -34,6 +34,7 @@ using System; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.Creation; +using BH.oM.Revit.Enums; namespace BH.Revit.Engine.Core { @@ -62,7 +63,16 @@ public static oM.Adapters.Revit.Elements.ViewFilter ViewFilterFromRevit(this Par /* 2. Transfer List of CATEGORY NAMES */ List categories = new List(); foreach (Autodesk.Revit.DB.Category cat in revitViewFilter.Document.Settings.Categories) { categories.Add(cat); } - viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat=>cat.Id==catId).First()).Cast().ToList(); + + List values = Enum.GetValues(typeof(BH.oM.Revit.Enums.Category)).Cast().ToList(); + + viewFilter.Categories = revitViewFilter.GetCategories().Select(catId => categories.Where(cat => cat.Id == catId).First()) + .Select(cat => Enum.GetValues(typeof(BH.oM.Revit.Enums.Category)) + .Cast() + .ToList() + .Where(enumValue => ((int)enumValue).ToString()==cat.Id.ToString()) + .First()) + .ToList(); /* 3. Transfer List of FILTER RULES */ // If the Filter is assigned with any rules..... @@ -191,7 +201,7 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterRuleFromRevit(this P } - private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromRevit(this ParameterFilterElement revitViewFilter, + private static oM.Revit.FilterRules.FilterElementIdRule FilterRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterElementIdRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -220,7 +230,7 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterElementIdRuleFromR } - private static oM.Revit.FilterRules.FilterCategoryRule FilterCategoryRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterCategoryRule revitRule) + private static oM.Revit.FilterRules.FilterCategoryRule FilterRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterCategoryRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object @@ -239,7 +249,7 @@ private static oM.Revit.FilterRules.FilterCategoryRule FilterCategoryRuleFromRev } - private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePresenceRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.ParameterValuePresenceRule revitRule) + private static oM.Revit.FilterRules.ParameterValuePresenceRule FilterRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.ParameterValuePresenceRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object oM.Revit.FilterRules.ParameterValuePresenceRule bhomParamValuePresenceRule; @@ -254,7 +264,7 @@ private static oM.Revit.FilterRules.ParameterValuePresenceRule ParameterValuePre } - private static oM.Revit.FilterRules.FilterRule FilterInverseRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterInverseRule revitRule) + private static oM.Revit.FilterRules.FilterRule FilterRuleFromRevit(this ParameterFilterElement revitViewFilter, Autodesk.Revit.DB.FilterInverseRule revitRule) { // 1. EXTRACT DATA from the REVIT FILTERRULE object diff --git a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs index 1276cac21..572442b31 100644 --- a/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs +++ b/Revit_Core_Engine/Convert/Revit/ToRevit/ParameterFilterElement.cs @@ -72,7 +72,7 @@ public static ParameterFilterElement ToRevitParameterFilterElement(this oM.Adapt .Select(catObj => catObj.ToString().ToUpper().Replace(" ", "")) // Get the corresponding BuiltInCategories .Select(catName => { List builtInCatNames = Enum.GetNames(typeof(BuiltInCategory)) - .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace("OST_", "").Replace("_", "")) + .Select(builtInCategoryName => builtInCategoryName.ToUpper().Replace(" ", "")) .ToList(); return (BuiltInCategory)(((BuiltInCategory[])Enum.GetValues(typeof(BuiltInCategory)))[builtInCatNames.IndexOf(catName)]); }) // Get the ElementIds of the BuiltInCategories @@ -227,6 +227,7 @@ private static Autodesk.Revit.DB.FilterRule filterLevelRuleToRevit(Document docu { levelId = new FilteredElementCollector(document) .OfCategory(BuiltInCategory.OST_Levels) + .WhereElementIsNotElementType() .Where(level => level.Name.ToUpper() == filterLevelRule.LevelName.ToUpper()) .Cast() .Select(level => level.Id) From b36aaa2686415b3d1ac408279db3a1347631bad9 Mon Sep 17 00:00:00 2001 From: Giorgio Date: Wed, 16 Oct 2024 15:40:02 +0100 Subject: [PATCH 129/131] Update name of method OverrideGraphicSettings#fromRevit based on Pascal Casing Co-authored-by: Pawel Baran --- Revit_Core_Engine/Convert/Revit/FromRevit/View.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 7ae2448f0..c5acb8447 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -82,7 +82,7 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, /***************************************************/ - private static OverrideGraphicSettings overrideGraphicSettingsFromRevit(this View element, Autodesk.Revit.DB.OverrideGraphicSettings revitOverrides) + private static OverrideGraphicSettings OverrideGraphicSettingsFromRevit(this View element, Autodesk.Revit.DB.OverrideGraphicSettings revitOverrides) { // Initialize BHoM OverrideGraphicsSettings object OverrideGraphicSettings overrideGraphicsSettings = new OverrideGraphicSettings(); From 94b1712942e988f546a7838abbc9102b728dbfd8 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 16 Oct 2024 15:52:08 +0100 Subject: [PATCH 130/131] Remove FilterRule downcasting and use of generic T type in Update Method for Views --- Revit_Core_Engine/Convert/Revit/FromRevit/View.cs | 2 +- .../Convert/Revit/FromRevit/ViewFilter.cs | 12 ------------ Revit_Core_Engine/Modify/Update.cs | 2 +- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index c5acb8447..74260dae4 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -65,7 +65,7 @@ public static oM.Adapters.Revit.Elements.View ViewFromRevit(this View revitView, /*1. Transfer ViewFilters and corresponding OverrideGraphicSettings into ViewFilterWithOverrides Objects - via STREAMS */ List filtersWithOverrides = revitView.GetFilters().ToDictionary (elId => Convert.ViewFilterFromRevit((ParameterFilterElement)revitView.Document.GetElement(elId)), - elId => overrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() + elId => OverrideGraphicSettingsFromRevit(revitView, revitView.GetFilterOverrides(elId))).ToList() .Select(kvp => new ViewFilterWithOverrides { Filter = kvp.Key, Overrides = kvp.Value }).ToList(); /*2. Create BHoM View Object with Name and FilterWithOverrides objects */ view = new oM.Adapters.Revit.Elements.View { Name = revitView.Name, FiltersWithOverrides = filtersWithOverrides };} diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs index e0417848c..ef75eaa89 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/ViewFilter.cs @@ -115,8 +115,6 @@ private static oM.Revit.FilterRules.FilterStringRule FilterRuleFromRevit(this Pa { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterStringRule obj - Autodesk.Revit.DB.FilterStringRule revitFilterStringRule = (Autodesk.Revit.DB.FilterStringRule)revitRule; // Extract name and value assigned to the parameter of the FilterStringRule obj string paramName = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).Definition.Name; string paramValue = revitRule.RuleString; @@ -145,8 +143,6 @@ private static oM.Revit.FilterRules.FilterDoubleRule FilterRuleFromRevit(this Pa { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterDoubleRule obj - Autodesk.Revit.DB.FilterDoubleRule revitFilterDoubleRule = (Autodesk.Revit.DB.FilterDoubleRule)revitRule; // Extract name and value assigned to the parameter of the FilterDoubleRule obj string paramName = GetParameterById(revitViewFilter.Document,revitRule.GetRuleParameter()).Definition.Name; ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).GetUnitTypeId(); @@ -176,8 +172,6 @@ private static oM.Revit.FilterRules.FilterIntegerRule FilterRuleFromRevit(this P { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterIntegerRule obj - Autodesk.Revit.DB.FilterIntegerRule revitFilterIntegerRule = (Autodesk.Revit.DB.FilterIntegerRule)revitRule; // Extract name and value assigned to the parameter of the FilterIntegerRule obj string paramName = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).Definition.Name; ForgeTypeId paramTypeId = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).GetUnitTypeId(); @@ -206,8 +200,6 @@ private static oM.Revit.FilterRules.FilterElementIdRule FilterRuleFromRevit(this { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterElementIdRule obj - Autodesk.Revit.DB.FilterElementIdRule revitFilterElemIdRule = (Autodesk.Revit.DB.FilterElementIdRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj string paramName = GetParameterById(revitViewFilter.Document, revitRule.GetRuleParameter()).Definition.Name; string paramValue = revitViewFilter.Document.GetElement(revitRule.RuleValue).Name.ToString(); @@ -234,8 +226,6 @@ private static oM.Revit.FilterRules.FilterCategoryRule FilterRuleFromRevit(this { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterCategoryRule obj - Autodesk.Revit.DB.FilterCategoryRule revitFilterCategoryRule = (Autodesk.Revit.DB.FilterCategoryRule)revitRule; // Extract name and value assigned to the parameter of the FilterElementIdRule obj List categoryNames = revitRule.GetCategories().Select(elId => revitViewFilter.Document.GetElement(elId).Name).ToList(); @@ -268,8 +258,6 @@ private static oM.Revit.FilterRules.FilterRule FilterRuleFromRevit(this Paramete { // 1. EXTRACT DATA from the REVIT FILTERRULE object - // Downcast Revit FilterRule obj to Revit FilterInverseRule obj - Autodesk.Revit.DB.FilterInverseRule revitFilterInverseRule = (Autodesk.Revit.DB.FilterInverseRule)revitRule; // Extract innerRule assigned to the Revit FilterInverseRule obj Autodesk.Revit.DB.FilterRule innerRule = revitRule.GetInnerRule(); diff --git a/Revit_Core_Engine/Modify/Update.cs b/Revit_Core_Engine/Modify/Update.cs index e5381846d..8d46440b7 100644 --- a/Revit_Core_Engine/Modify/Update.cs +++ b/Revit_Core_Engine/Modify/Update.cs @@ -257,7 +257,7 @@ public static bool Update(this AssemblyInstance element, Assembly bHoMObject, Re [Input("settings", "Revit adapter settings to be used while performing the action.")] [Input("setLocationOnUpdate", "Revit View instance does not have location property, therefore this parameter is irrelevant.")] [Output("success", "True if the Revit View instance has been updated successfully based on the input BHoM View.")] - public static bool Update(this T element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) where T:View + public static bool Update (this View element, BH.oM.Adapters.Revit.Elements.View bHoMObject, RevitSettings settings, bool setLocationOnUpdate) { /* ADD FILTERS WITH OVERRIDES TO REVIT VIEW */ From 501e2c20649297356551cbccdc519b0760909d66 Mon Sep 17 00:00:00 2001 From: GCRA101 Date: Wed, 16 Oct 2024 16:01:18 +0100 Subject: [PATCH 131/131] Replace Try-catch statements with If-then statments for controlling errors in PatternId assigment --- .../Convert/Revit/FromRevit/View.cs | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs index 74260dae4..72d0ef8f3 100644 --- a/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs +++ b/Revit_Core_Engine/Convert/Revit/FromRevit/View.cs @@ -93,9 +93,11 @@ private static OverrideGraphicSettings OverrideGraphicSettingsFromRevit(this Vie if (revitOverrides.CutForegroundPatternColor.IsValid) overrideGraphicsSettings.CutColor = System.Drawing.Color.FromArgb(revitOverrides.CutBackgroundPatternColor.Red, revitOverrides.CutBackgroundPatternColor.Green, revitOverrides.CutBackgroundPatternColor.Blue); if (revitOverrides.SurfaceBackgroundPatternColor.IsValid) overrideGraphicsSettings.SurfaceColor = System.Drawing.Color.FromArgb(revitOverrides.SurfaceBackgroundPatternColor.Red, revitOverrides.SurfaceBackgroundPatternColor.Green, revitOverrides.SurfaceBackgroundPatternColor.Blue); + // Convert LINE PATTERNS - try - { + + if (revitOverrides.CutLinePatternId.IntegerValue==-1) + { String linePatternName = element.Document.GetElement(revitOverrides.CutLinePatternId).Name; if (linePatternName.Replace(" ","").ToUpper().Contains("DASHDOTDOT")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.DashDotDot; } @@ -109,16 +111,13 @@ private static OverrideGraphicSettings OverrideGraphicSettingsFromRevit(this Vie else if (linePatternName.ToUpper().Replace(" ", "").Contains("HIDDEN")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Hidden; } else if (linePatternName.ToUpper().Replace(" ", "").Contains("SOLID")) { overrideGraphicsSettings.LinePattern = oM.Revit.Enums.LinePattern.Solid; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern {linePatternName} is not implemented yet in the BHoM.\n By default, the Line Pattern {linePatternName} will be set to SOLID."); } - } - catch - { - BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); - } + } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Line Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined.");} // Convert CUT PATTERNS - try - { + + if (revitOverrides.CutBackgroundPatternId.IntegerValue == -1) + { String cutPatternName = element.Document.GetElement(revitOverrides.CutBackgroundPatternId).Name; if (cutPatternName.ToUpper().Contains("CROSSHATCH") && !cutPatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.CrossHatch; } @@ -130,17 +129,14 @@ private static OverrideGraphicSettings OverrideGraphicSettingsFromRevit(this Vie else if (cutPatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Solid; } else if (cutPatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.CutPattern = oM.Revit.Enums.FillPattern.Vertical; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {cutPatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {cutPatternName} will be set to SOLID."); } - } - catch - { - BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); - } + } else {BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined.");} // Convert SURFACE PATTERNS - try - { - String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; + + if (revitOverrides.SurfaceBackgroundPatternId.IntegerValue == -1) + { + String surfacePatternName = element.Document.GetElement(revitOverrides.SurfaceBackgroundPatternId).Name; if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && !surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.CrossHatch; } else if (surfacePatternName.ToUpper().Contains("CROSSHATCH") && surfacePatternName.ToUpper().Contains("DIAGONAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.DiagonalCrossHatch; } @@ -151,11 +147,8 @@ private static OverrideGraphicSettings OverrideGraphicSettingsFromRevit(this Vie else if (surfacePatternName.ToUpper().Contains("SOLID")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Solid; } else if (surfacePatternName.ToUpper().Contains("VERTICAL")) { overrideGraphicsSettings.SurfacePattern = oM.Revit.Enums.FillPattern.Vertical; } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern {surfacePatternName} is not implemented yet in the BHoM.\n By default, the Fill Pattern {surfacePatternName} will be set to SOLID."); } - } - catch - { - BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined."); - } + + } else { BH.Engine.Base.Compute.RecordWarning($"The Revit Fill Pattern for the Revit OverrideGraphicSettings {revitOverrides.ToString()} is not defined.");} return overrideGraphicsSettings; }