Skip to content
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
19 changes: 5 additions & 14 deletions Revit_Core_Engine/Compute/GeneratePadFoundationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private static FamilySymbol GenerateFreeformType(PadFoundation padFoundation, Do
{
List<int> takenIndices = freeformFamilies.Select(x => Regex.Match(x.Name, $"{Regex.Escape(prefix)}(\\d+)$")).Select(x => int.Parse(x.Groups[1].Value)).ToList();
int newIndex = takenIndices.Count > 0 ? takenIndices.Max() + 1 : 1;
family = GenerateFreeFormPadFamilyFromTemplate(document, orientedOutline, thickness, newIndex, padFoundation, settings);
family = GenerateFreeFormPadFamilyFromTemplate(document, orientedOutline, thickness, newIndex, settings);
}

if (family == null)
Expand All @@ -177,7 +177,7 @@ private static FamilySymbol GenerateFreeformType(PadFoundation padFoundation, Do

/***************************************************/

private static Family GenerateFreeFormPadFamilyFromTemplate(this Document document, Polyline orientedOutline, double thickness, int index, PadFoundation padFoundation, RevitSettings settings = null)
private static Family GenerateFreeFormPadFamilyFromTemplate(this Document document, Polyline orientedOutline, double thickness, int index, RevitSettings settings = null)
{
string templateFamilyName = "StructuralFoundations_Pad-Freeform";
string templatePath = Directory.GetFiles(m_FamilyDirectory, $"*{templateFamilyName}.rfa").FirstOrDefault();
Expand All @@ -188,7 +188,7 @@ private static Family GenerateFreeFormPadFamilyFromTemplate(this Document docume

try
{
if (!ReplaceFreeFormExtrusion(familyDocument, orientedOutline, padFoundation))
if (!ReplaceFreeFormExtrusion(familyDocument, orientedOutline, thickness))
return null;

return SaveAndLoadFamily(document, familyDocument, $"{Path.GetFileNameWithoutExtension(templatePath)}_{index}");
Expand All @@ -205,17 +205,8 @@ private static Family GenerateFreeFormPadFamilyFromTemplate(this Document docume
}

/***************************************************/
private static double FreeformExtrusionDepth(PadFoundation padFoundation)
{
double depth = padFoundation.PadFoundationThickness();
double h = double.IsNaN(depth) ? double.NaN : depth.FromSI(SpecTypeId.Length);
if (double.IsNaN(h) || h <= 1e-6)
h = 0.5.FromSI(SpecTypeId.Length);
return h;
}

/***************************************************/
private static bool ReplaceFreeFormExtrusion(Document familyDocument, Polyline orientedOutline, PadFoundation padFoundation)
private static bool ReplaceFreeFormExtrusion(Document familyDocument, Polyline orientedOutline, double thickness)
{
try
{
Expand All @@ -226,7 +217,7 @@ private static bool ReplaceFreeFormExtrusion(Document familyDocument, Polyline o
using (Transaction t = new Transaction(familyDocument, "Update Freeform Pad Foundation Footprint"))
{
t.Start();
familyDocument.FamilyCreate.NewExtrusion(true, profile, extrusion.Sketch.SketchPlane, -FreeformExtrusionDepth(padFoundation));
familyDocument.FamilyCreate.NewExtrusion(true, profile, extrusion.Sketch.SketchPlane, -FreeformExtrusionDepth(thickness));
familyDocument.Delete(extrusion.Id);
t.Commit();
}
Expand Down
395 changes: 395 additions & 0 deletions Revit_Core_Engine/Compute/GeneratePileFoundationType.cs

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions Revit_Core_Engine/Convert/Physical/ToRevit/FamilyInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,61 @@ public static FamilyInstance ToRevitFamilyInstance(this PadFoundation padFoundat

/***************************************************/

[Description("Converts BH.oM.Physical.Elements.PileFoundation to a Revit FamilyInstance.")]
[Input("pileFoundation", "BH.oM.Physical.Elements.PileFoundation 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("instance", "Revit FamilyInstance resulting from converting the input BH.oM.Physical.Elements.PileFoundation.")]
public static FamilyInstance ToRevitFamilyInstance(this PileFoundation pileFoundation, Document document, RevitSettings settings = null, Dictionary<Guid, List<long>> refObjects = null)
{
if (pileFoundation == null || document == null)
return null;

FamilyInstance familyInstance = refObjects.GetValue<FamilyInstance>(document, pileFoundation.BHoM_Guid);
if (familyInstance != null)
return familyInstance;

settings = settings.DefaultIfNull();

if (pileFoundation.PileCap == null)
{
BH.Engine.Base.Compute.RecordError($"PileFoundation has no PileCap. BHoM_Guid: {pileFoundation.BHoM_Guid}");
return null;
}

FamilySymbol familySymbol = pileFoundation.ElementType(document, settings) as FamilySymbol;
if (familySymbol == null)
{
Compute.ElementTypeNotFoundWarning(pileFoundation);
return null;
}

BH.oM.Geometry.Point origin = pileFoundation.PileCap.PadFoundationCentroid();

Level level = document.LevelAbove(origin.Z, settings);

familyInstance = document.Create.NewFamilyInstance(origin.ToRevit(), familySymbol, level, StructuralType.Footing);
document.Regenerate();

double pileDepth = pileFoundation.PileFoundationDepth(settings);
if (!double.IsNaN(pileDepth))
familyInstance.SetParameter("Pile Depth", pileDepth);

familyInstance.SetLocation(pileFoundation, settings);
refObjects.AddOrReplace(pileFoundation, familyInstance);

if (pileFoundation.Piles != null)
{
foreach (Pile pile in pileFoundation.Piles)
refObjects.AddOrReplace(pile, familyInstance);
}

return familyInstance;
}

/***************************************************/

[Description("Converts BH.oM.Physical.Elements.IFramingElement to a Revit FamilyInstance.")]
[Input("framingElement", "BH.oM.Physical.Elements.IFramingElement to be converted.")]
[Input("document", "Revit document, in which the output of the convert will be created.")]
Expand Down
13 changes: 13 additions & 0 deletions Revit_Core_Engine/Convert/ToRevit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ public static Element ToRevit(this BH.oM.Physical.Elements.PadFoundation foundat

/***************************************************/

[Description("Converts BH.oM.Physical.Elements.PileFoundation to a Revit FamilyInstance.")]
[Input("foundation", "BH.oM.Physical.Elements.PileFoundation 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("instance", "Revit FamilyInstance resulting from converting the input BH.oM.Physical.Elements.PileFoundation.")]
public static Element ToRevit(this BH.oM.Physical.Elements.PileFoundation foundation, Document document, RevitSettings settings = null, Dictionary<Guid, List<long>> refObjects = null)
{
return foundation.ToRevitFamilyInstance(document, settings, refObjects);
}

/***************************************************/

[Description("Converts BH.oM.MEP.System.MaterialFragments.PipeMaterial to a Revit PipeSegment.")]
[Input("pipeMaterial", "BH.oM.MEP.System.MaterialFragments.PipeMaterial to be converted.")]
[Input("document", "Revit document, in which the output of the convert will be created.")]
Expand Down
Binary file not shown.
16 changes: 15 additions & 1 deletion Revit_Core_Engine/Modify/SetLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,20 @@ public static bool SetLocation(this FamilyInstance element, Pile pile, RevitSett

/***************************************************/

[Description("Sets the location of a given Revit FamilyInstance based on a given BHoM PileFoundation.")]
[Input("element", "Revit FamilyInstance to be modified.")]
[Input("pileFoundation", "BHoM PileFoundation acting as a source of information about the new location.")]
[Input("settings", "Revit adapter settings to be used while performing the operation.")]
[Output("success", "True if location of the input Revit FamilyInstance has been successfully set.")]
public static bool SetLocation(this FamilyInstance element, PileFoundation pileFoundation, RevitSettings settings)
{
if (element == null || pileFoundation?.PileCap == null)
return false;
return element.SetLocation(pileFoundation.PileCap, settings);
}

/***************************************************/

[Description("Sets the location of a given Revit FamilyInstance based on a given BHoM PadFoundation.")]
[Input("element", "Revit FamilyInstance to be modified.")]
[Input("padFoundation", "BHoM PadFoundation acting as a source of information about the new location.")]
Expand Down Expand Up @@ -939,7 +953,7 @@ private static bool SetLocation(this FamilyInstance element, BH.oM.Geometry.Poin

return success;
}

/***************************************************/
private static bool UpdateRotationOfVerticalElement(this FamilyInstance element, IFramingElement bhomElement, RevitSettings settings)
{
Expand Down
21 changes: 21 additions & 0 deletions Revit_Core_Engine/Modify/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ public static bool Update(this FamilyInstance element, PadFoundation bHoMObject,

/***************************************************/

[Description("Updates a Revit pile foundation FamilyInstance from the BHoM PileFoundation using the standard element update, then sets instance Pile Depth.")]
[Input("element", "Revit FamilyInstance representing the pile foundation to update.")]
[Input("bHoMObject", "BHoM PileFoundation whose properties (and optionally location) should be applied to the Revit instance.")]
[Input("settings", "Revit adapter settings used for the underlying element update.")]
[Input("setLocationOnUpdate", "If false, only parameters and properties are updated; if true, the instance location is updated as well.")]
[Output("success", "True if the underlying Element.Update succeeded.")]
public static bool Update(this FamilyInstance element, PileFoundation bHoMObject, RevitSettings settings, bool setLocationOnUpdate)
{
settings = settings.DefaultIfNull();

bool result = ((Element)element).Update((IBHoMObject)bHoMObject, settings, setLocationOnUpdate);

double pileDepth = bHoMObject.PileFoundationDepth(settings);
if (!double.IsNaN(pileDepth))
element.SetParameter("Pile Depth", pileDepth);

return result;
}

/***************************************************/

[Description("Updates the existing Revit FamilyInstance based on the given BHoM builders work Opening.")]
[Input("element", "Revit FamilyInstance to be updated.")]
[Input("bHoMObject", "BHoM builders work Opening, based on which the Revit element will be updated.")]
Expand Down
21 changes: 21 additions & 0 deletions Revit_Core_Engine/Query/ElementType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ public static FamilySymbol ElementType(this BH.oM.Physical.Elements.PadFoundatio

/***************************************************/

[Description("Returns the Revit FamilySymbol to use when converting a BHoM PileFoundation.")]
[Input("pileFoundation", "BHoM pile foundation to find or generate a correspondent Revit family type for.")]
[Input("document", "Revit document to search for the element type or host generated types.")]
[Input("settings", "Revit adapter settings to be used while performing the query.")]
[Output("familySymbol", "Revit FamilySymbol to be used when converting the input pile foundation to Revit.")]
public static FamilySymbol ElementType(this BH.oM.Physical.Elements.PileFoundation pileFoundation, Document document, RevitSettings settings = null)
{
FamilySymbol result = pileFoundation.GeneratePileFoundationType(document, settings);
pileFoundation.FamilyAndTypeNames(out string familyName, out string familyTypeName);

if (!string.IsNullOrWhiteSpace(familyName) && result.FamilyName != familyName)
BH.Engine.Base.Compute.RecordWarning($"BHoM PileFoundation's name does not match Revit family name derived from its geometry. BHoM_Guid: {pileFoundation.BHoM_Guid}");

if (!string.IsNullOrWhiteSpace(familyTypeName) && result.Name != familyTypeName)
BH.Engine.Base.Compute.RecordWarning($"BHoM PileFoundation's name does not match Revit type name derived from its geometry. BHoM_Guid: {pileFoundation.BHoM_Guid}");

return result;
}

/***************************************************/

[Description("Returns the Revit element type to be used when converting a given BHoM IInstance to Revit.")]
[Input("instance", "BHoM IInstance to find a correspondent Revit element type for.")]
[Input("document", "Revit document to parse in search for the element type.")]
Expand Down
Loading
Loading