From ea668fb22668481a7e1a011053ec872a0c3a9d7b Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Sat, 28 Dec 2024 20:28:07 +0100 Subject: [PATCH 1/3] Revit already tries to convert the form to an extrusion. --- .../Family/Element/Form/ByCurves.cs | 22 +++++- .../Family/Element/Form/ByGeometry.cs | 77 +++++++------------ .../Types/GeometricElement.cs | 10 +-- 3 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs index 3f7caf7a6..d628a563d 100644 --- a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs +++ b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs @@ -9,6 +9,7 @@ namespace RhinoInside.Revit.GH.Components.Families using Convert.Geometry; using Kernel.Attributes; using External.DB.Extensions; + using ERDB = External.DB; public class FormByCurves : ReconstructElementComponent { @@ -25,6 +26,16 @@ public FormByCurves() : base ) { } + static readonly ARDB.BuiltInParameter[] ExcludeUniqueProperties = + { + ARDB.BuiltInParameter.IS_VISIBLE_PARAM, + ARDB.BuiltInParameter.GEOM_VISIBILITY_PARAM, + ARDB.BuiltInParameter.MATERIAL_ID_PARAM, + ARDB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY, + ARDB.BuiltInParameter.ELEMENT_IS_CUTTING, + ARDB.BuiltInParameter.OFFSETFACES_SHOW_SHAPE_HANDLES, + }; + void ReconstructFormByCurves ( [Optional, NickName("DOC")] @@ -60,7 +71,7 @@ void ReconstructFormByCurves foreach (var curve in profile.ToCurveMany()) referenceArray.Append(new ARDB.Reference(document.FamilyCreate.NewModelCurve(curve, sketchPlane))); - ReplaceElement(ref form, document.FamilyCreate.NewFormByCap(true, referenceArray)); + ReplaceElement(ref form, document.FamilyCreate.NewFormByCap(true, referenceArray), ExcludeUniqueProperties); } } else @@ -81,9 +92,16 @@ void ReconstructFormByCurves } } - ReplaceElement(ref form, document.FamilyCreate.NewLoftForm(true, referenceArrayArray)); + ReplaceElement(ref form, document.FamilyCreate.NewLoftForm(true, referenceArrayArray), ExcludeUniqueProperties); } } + + form.get_Parameter(ARDB.BuiltInParameter.IS_VISIBLE_PARAM)?.Update(true); + form.get_Parameter(ARDB.BuiltInParameter.GEOM_VISIBILITY_PARAM).Update(ERDB.FamilyElementVisibility.DefaultModel); + form.get_Parameter(ARDB.BuiltInParameter.MATERIAL_ID_PARAM)?.Update(ElementIdExtension.Invalid); + form.get_Parameter(ARDB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY)?.Update(ElementIdExtension.Invalid); + form.get_Parameter(ARDB.BuiltInParameter.ELEMENT_IS_CUTTING)?.Update(0); + form.get_Parameter(ARDB.BuiltInParameter.OFFSETFACES_SHOW_SHAPE_HANDLES)?.Update(true); } } } diff --git a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs index f8ac3b312..29213e180 100644 --- a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs +++ b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs @@ -10,6 +10,7 @@ namespace RhinoInside.Revit.GH.Components.Families using Convert.Geometry; using External.DB.Extensions; using Kernel.Attributes; + using ERDB = External.DB; public class FormByGeometry : ReconstructElementComponent { @@ -26,6 +27,16 @@ public FormByGeometry() : base ) { } + static readonly ARDB.BuiltInParameter[] ExcludeUniqueProperties = + { + ARDB.BuiltInParameter.IS_VISIBLE_PARAM, + ARDB.BuiltInParameter.GEOM_VISIBILITY_PARAM, + ARDB.BuiltInParameter.MATERIAL_ID_PARAM, + ARDB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY, + ARDB.BuiltInParameter.ELEMENT_IS_CUTTING, + ARDB.BuiltInParameter.OFFSETFACES_SHOW_SHAPE_HANDLES, + }; + void ReconstructFormByGeometry ( [Optional, NickName("DOC")] @@ -55,16 +66,14 @@ Brep brep foreach (var curve in brep.Faces[0].OuterLoop.To3dCurve().ToCurveMany()) referenceArray.Append(new ARDB.Reference(document.FamilyCreate.NewModelCurve(curve, sketchPlane))); - ReplaceElement - ( - ref form, - document.FamilyCreate.NewFormByCap - ( - !cutting, - referenceArray - ) - ); + ReplaceElement(ref form, document.FamilyCreate.NewFormByCap(!cutting, referenceArray), ExcludeUniqueProperties); + form.get_Parameter(ARDB.BuiltInParameter.IS_VISIBLE_PARAM)?.Update(true); + form.get_Parameter(ARDB.BuiltInParameter.GEOM_VISIBILITY_PARAM).Update(ERDB.FamilyElementVisibility.DefaultModel); + form.get_Parameter(ARDB.BuiltInParameter.MATERIAL_ID_PARAM)?.Update(ElementIdExtension.Invalid); + form.get_Parameter(ARDB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY)?.Update(ElementIdExtension.Invalid); + form.get_Parameter(ARDB.BuiltInParameter.ELEMENT_IS_CUTTING)?.Update(0); + form.get_Parameter(ARDB.BuiltInParameter.OFFSETFACES_SHOW_SHAPE_HANDLES)?.Update(true); return; } catch (Autodesk.Revit.Exceptions.InvalidOperationException) @@ -73,37 +82,6 @@ Brep brep } } } - else if (document.OwnerFamily.IsConceptualMassFamily) - { - if (brep.TryGetExtrusion(out var extrusion) && (extrusion.CapCount == 2 || !extrusion.IsClosed(0))) - { - using (var sketchPlane = ARDB.SketchPlane.Create(document, extrusion.GetProfilePlane(0.0).ToPlane())) - using (var referenceArray = new ARDB.ReferenceArray()) - { - try - { - foreach (var curve in extrusion.Profile3d(new ComponentIndex(ComponentIndexType.ExtrusionBottomProfile, 0)).ToCurveMany()) - referenceArray.Append(new ARDB.Reference(document.FamilyCreate.NewModelCurve(curve, sketchPlane))); - - ReplaceElement - ( - ref form, - document.FamilyCreate.NewExtrusionForm - ( - !cutting, - referenceArray, - extrusion.PathLineCurve().Line.Direction.ToXYZ(GeometryEncoder.ModelScaleFactor) - ) - ); - return; - } - catch (Autodesk.Revit.Exceptions.InvalidOperationException) - { - document.Delete(referenceArray.OfType().Select(x => x.ElementId).ToArray()); - } - } - } - } } // Else we try with a DB.FreeFormElement @@ -112,22 +90,19 @@ Brep brep ctx.RuntimeMessage = (severity, message, invalidGeometry) => AddGeometryConversionError((GH_RuntimeMessageLevel) severity, message, invalidGeometry); - var solid = brep.ToSolid(); - if (solid != null) + if (brep.ToSolid() is ARDB.Solid solid) { if (form is ARDB.FreeFormElement freeFormElement) - { freeFormElement.UpdateSolidGeometry(solid); - } else - { - ReplaceElement(ref form, ARDB.FreeFormElement.Create(document, solid)); - - if (document.OwnerFamily.IsConceptualMassFamily) - form.get_Parameter(ARDB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY).Update(new ARDB.ElementId(ARDB.BuiltInCategory.OST_MassForm)); - } + ReplaceElement(ref form, ARDB.FreeFormElement.Create(document, solid), ExcludeUniqueProperties); - form.get_Parameter(ARDB.BuiltInParameter.ELEMENT_IS_CUTTING)?.Update(cutting ? 1 : 0); + form.get_Parameter(ARDB.BuiltInParameter.IS_VISIBLE_PARAM)?.Update(true); + form.get_Parameter(ARDB.BuiltInParameter.GEOM_VISIBILITY_PARAM).Update(ERDB.FamilyElementVisibility.DefaultModel); + form.get_Parameter(ARDB.BuiltInParameter.MATERIAL_ID_PARAM)?.Update(ElementIdExtension.Invalid); + form.get_Parameter(ARDB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY)?.Update(ElementIdExtension.Invalid); + form.get_Parameter(ARDB.BuiltInParameter.ELEMENT_IS_CUTTING)?.Update(0); + form.get_Parameter(ARDB.BuiltInParameter.OFFSETFACES_SHOW_SHAPE_HANDLES)?.Update(true); } else AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Failed to convert Brep to Form"); } diff --git a/src/RhinoInside.Revit.GH/Types/GeometricElement.cs b/src/RhinoInside.Revit.GH/Types/GeometricElement.cs index 41a3ca1b4..b8b97f2dc 100644 --- a/src/RhinoInside.Revit.GH/Types/GeometricElement.cs +++ b/src/RhinoInside.Revit.GH/Types/GeometricElement.cs @@ -752,12 +752,13 @@ geometryElementContent[0] is ARDB.GeometryInstance geometryInstance && geoAtt.ColorSource = ObjectColorSource.ColorFromObject; geoAtt.ObjectColor = NoBlack(faceMaterial.ObjectColor); #endif - if ((geo as Brep)?.TryGetExtrusion(out var extrusion) is true) geo = extrusion; + if ((geo as Brep)?.TryGetExtrusion(out var extrusion) is true) + geo = extrusion; } } else { - if (geo is Brep brepFrom && brepFrom.TryGetExtrusion(out var extrusion)) + if ((geo as Brep)?.TryGetExtrusion(out var extrusion) is true) geo = extrusion; } } @@ -841,11 +842,10 @@ out Guid guid return false; } -#endregion + #endregion #region ModelContent #if RHINO_8 - static void PeekModelAttributes(IDictionary idMap, ModelObject.Attributes attributes, ARDB.Document document) { var context = GeometryDecoder.Context.Peek; @@ -1032,7 +1032,7 @@ internal override ModelContent ToModelContent(IDictionary HostElement; From 9b7b7d931231fa63ef1a4f2f8e467c45fec4abcb Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Sat, 28 Dec 2024 20:32:57 +0100 Subject: [PATCH 2/3] Some renaming. --- .../comps/{FormByGeometry.png => AddForm.png} | Bin .../comps/{FormByCurves.png => AddMassLoft.png} | Bin .../Components/Family/Element/Form/ByCurves.cs | 4 ++-- .../Components/Family/Element/Form/ByGeometry.cs | 4 ++-- src/RhinoInside.Revit.GH/Properties/Resources.resx | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) rename art/gh-icons/comps/{FormByGeometry.png => AddForm.png} (100%) rename art/gh-icons/comps/{FormByCurves.png => AddMassLoft.png} (100%) diff --git a/art/gh-icons/comps/FormByGeometry.png b/art/gh-icons/comps/AddForm.png similarity index 100% rename from art/gh-icons/comps/FormByGeometry.png rename to art/gh-icons/comps/AddForm.png diff --git a/art/gh-icons/comps/FormByCurves.png b/art/gh-icons/comps/AddMassLoft.png similarity index 100% rename from art/gh-icons/comps/FormByCurves.png rename to art/gh-icons/comps/AddMassLoft.png diff --git a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs index d628a563d..098a74d1b 100644 --- a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs +++ b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs @@ -11,12 +11,12 @@ namespace RhinoInside.Revit.GH.Components.Families using External.DB.Extensions; using ERDB = External.DB; - public class FormByCurves : ReconstructElementComponent + public class AddMassLoft : ReconstructElementComponent { public override Guid ComponentGuid => new Guid("42631B6E-505E-4091-981A-E7605AE5A1FF"); public override GH_Exposure Exposure => GH_Exposure.quarternary; - public FormByCurves() : base + public AddMassLoft() : base ( name: "Add Mass Loft", nickname: "MassLoft", diff --git a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs index 29213e180..845d5f621 100644 --- a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs +++ b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs @@ -12,12 +12,12 @@ namespace RhinoInside.Revit.GH.Components.Families using Kernel.Attributes; using ERDB = External.DB; - public class FormByGeometry : ReconstructElementComponent + public class AddForm : ReconstructElementComponent { public override Guid ComponentGuid => new Guid("D2FDF2A0-1E48-4075-814A-685D91A6CD94"); public override GH_Exposure Exposure => GH_Exposure.quarternary; - public FormByGeometry() : base + public AddForm() : base ( name: "Add Form", nickname: "Form", diff --git a/src/RhinoInside.Revit.GH/Properties/Resources.resx b/src/RhinoInside.Revit.GH/Properties/Resources.resx index 3dde8a4cf..33f9613a4 100755 --- a/src/RhinoInside.Revit.GH/Properties/Resources.resx +++ b/src/RhinoInside.Revit.GH/Properties/Resources.resx @@ -544,11 +544,11 @@ ..\..\..\art\gh-icons\comps\addfloor.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\..\..\art\gh-icons\comps\formbycurves.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\..\..\art\gh-icons\comps\addmassloft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\..\..\art\gh-icons\comps\formbygeometry.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\..\..\art\gh-icons\comps\addform.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\..\..\art\gh-icons\params\graphicalelement.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a From d05b19889ec3c46e02c31d0c11ed33974aab64f1 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Sat, 28 Dec 2024 20:34:28 +0100 Subject: [PATCH 3/3] Some renaming --- .../Components/Family/Element/Form/{ByGeometry.cs => AddForm.cs} | 0 .../Family/Element/Form/{ByCurves.cs => AddMassLoft.cs} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/RhinoInside.Revit.GH/Components/Family/Element/Form/{ByGeometry.cs => AddForm.cs} (100%) rename src/RhinoInside.Revit.GH/Components/Family/Element/Form/{ByCurves.cs => AddMassLoft.cs} (100%) diff --git a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/AddForm.cs similarity index 100% rename from src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByGeometry.cs rename to src/RhinoInside.Revit.GH/Components/Family/Element/Form/AddForm.cs diff --git a/src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs b/src/RhinoInside.Revit.GH/Components/Family/Element/Form/AddMassLoft.cs similarity index 100% rename from src/RhinoInside.Revit.GH/Components/Family/Element/Form/ByCurves.cs rename to src/RhinoInside.Revit.GH/Components/Family/Element/Form/AddMassLoft.cs