Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kike/1.x #1267

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ namespace RhinoInside.Revit.GH.Components.Families
using Convert.Geometry;
using External.DB.Extensions;
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",
Expand All @@ -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")]
Expand Down Expand Up @@ -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)
Expand All @@ -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<ARDB.Reference>().Select(x => x.ElementId).ToArray());
}
}
}
}
}

// Else we try with a DB.FreeFormElement
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace RhinoInside.Revit.GH.Components.Families
using Convert.Geometry;
using Kernel.Attributes;
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",
Expand All @@ -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")]
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
}
8 changes: 4 additions & 4 deletions src/RhinoInside.Revit.GH/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@
<data name="AddFloor" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\addfloor.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="FormByCurves" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\formbycurves.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="AddMassLoft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\addmassloft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="FormByGeometry" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\formbygeometry.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="AddForm" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\comps\addform.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="GraphicalElement" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\..\art\gh-icons\params\graphicalelement.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
Expand Down
10 changes: 5 additions & 5 deletions src/RhinoInside.Revit.GH/Types/GeometricElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -841,11 +842,10 @@ out Guid guid

return false;
}
#endregion
#endregion

#region ModelContent
#if RHINO_8

static void PeekModelAttributes(IDictionary<ARDB.ElementId, ModelContent> idMap, ModelObject.Attributes attributes, ARDB.Document document)
{
var context = GeometryDecoder.Context.Peek;
Expand Down Expand Up @@ -1032,7 +1032,7 @@ internal override ModelContent ToModelContent(IDictionary<ARDB.ElementId, ModelC
return null;
}
#endif
#endregion
#endregion

#region IHostElementAccess
GraphicalElement IHostElementAccess.HostElement => HostElement;
Expand Down
Loading