Skip to content

Commit

Permalink
Minor tweaks and additions to the code base (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser Greenroyd authored Nov 21, 2023
2 parents d4c646f + 861ce23 commit 44062e2
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 26 deletions.
28 changes: 2 additions & 26 deletions Revit_Core_Engine/Convert/Revit/Internal/ToSolid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,8 @@ public static Solid ToSolid(this Element scopeBox, RevitSettings settings = null
return null;

BoundingBoxXYZ bbox = ge.GetTransformed(transform).GetBoundingBox();

XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z);
XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z);
XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z);
XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z);

Line edge0 = Line.CreateBound(pt0, pt1);
Line edge1 = Line.CreateBound(pt1, pt2);
Line edge2 = Line.CreateBound(pt2, pt3);
Line edge3 = Line.CreateBound(pt3, pt0);

List<Curve> edges = new List<Curve>();
edges.Add(edge0);
edges.Add(edge1);
edges.Add(edge2);
edges.Add(edge3);

double height = bbox.Max.Z - bbox.Min.Z;

CurveLoop baseLoop = CurveLoop.Create(edges);

List<CurveLoop> loopList = new List<CurveLoop>();
loopList.Add(baseLoop);

Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height);
return SolidUtils.CreateTransformed(solid, transform.Inverse);
bbox.Transform = transform.Inverse;
return bbox.ToSolid(settings);
}

/***************************************************/
Expand Down
44 changes: 44 additions & 0 deletions Revit_Core_Engine/Query/Bounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,50 @@ public static Outline Bounds(this List<Outline> outlines)
}

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

[Description("Returns the combined bounding box of a given collection of points.")]
[Input("points", "A collection of points to find the bounds for.")]
[Output("bounds", "Combined bounding box of the input collection of points.")]
public static BoundingBoxXYZ Bounds(this IEnumerable<XYZ> points)
{
if (points == null)
return null;

double minX = double.MaxValue;
double maxX = double.MinValue;
double minY = double.MaxValue;
double maxY = double.MinValue;
double minZ = double.MaxValue;
double maxZ = double.MinValue;

foreach (var point in points)
{
if (point.X < minX)
minX = point.X;

if (point.X > maxX)
maxX = point.X;

if (point.Y < minY)
minY = point.Y;

if (point.Y > maxY)
maxY = point.Y;

if (point.Z < minZ)
minZ = point.Z;

if (point.Z > maxZ)
maxZ = point.Z;
}

BoundingBoxXYZ result = new BoundingBoxXYZ();
result.Min = new XYZ(minX, minY, minZ);
result.Max = new XYZ(maxX, maxY, maxZ);
return result;
}

/***************************************************/
}
}

91 changes: 91 additions & 0 deletions Revit_Core_Engine/Query/TaggedElements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Mechanical;
using System.Collections.Generic;
using System.ComponentModel;

namespace BH.Revit.Engine.Core
{
public static partial class Query
{
/***************************************************/
/**** Public methods ****/
/***************************************************/

[Description("Returns ElementIds of all elements tagged by a given tag element (independent tag or spatial tag).")]
public static IEnumerable<ElementId> ITaggedElements(this Element tag)
{
if (tag == null)
return null;

return TaggedElements(tag as dynamic);
}


/***************************************************/
/**** Private methods ****/
/***************************************************/

private static IEnumerable<ElementId> TaggedElements(RoomTag tag)
{
return new List<ElementId> { tag.Room?.Id };
}

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

private static IEnumerable<ElementId> TaggedElements(AreaTag tag)
{
return new List<ElementId> { tag.Area?.Id };
}

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

private static IEnumerable<ElementId> TaggedElements(SpaceTag tag)
{
return new List<ElementId> { tag.Space?.Id };
}

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

private static IEnumerable<ElementId> TaggedElements(this IndependentTag tag)
{
#if (REVIT2020 || REVIT2021)
return new List<ElementId> { tag.TaggedLocalElementId };
#else
return tag.GetTaggedLocalElementIds();
#endif
}

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

private static IEnumerable<ElementId> TaggedElements(Element tag)
{
BH.Engine.Base.Compute.RecordError($"Type {tag.GetType().FullName} is not a valid Revit tag type.");
return null;
}

/***************************************************/
}
}

0 comments on commit 44062e2

Please sign in to comment.