// Box public Box BoxToSpeckle(BoundBlock3d bound, bool OrientToWorldXY = false) { try { Box box = null; var min = bound.GetMinimumPoint(); var max = bound.GetMaximumPoint(); // get dimension intervals var xSize = new Interval(min.X, max.X); var ySize = new Interval(min.Y, max.Y); var zSize = new Interval(min.Z, max.Z); // get box size info double area = 2 * ((xSize.Length * ySize.Length) + (xSize.Length * zSize.Length) + (ySize.Length * zSize.Length)); double volume = xSize.Length * ySize.Length * zSize.Length; if (OrientToWorldXY) { var origin = new Point3d(0, 0, 0); var normal = new Vector3d(0, 0, 1); var plane = PlaneToSpeckle(new Autodesk.AutoCAD.Geometry.Plane(origin, normal)); box = new Box(plane, xSize, ySize, zSize, ModelUnits) { area = area, volume = volume }; } else { // get base plane var corner = new Point3d(max.X, max.Y, min.Z); var origin = new Point3d((corner.X + min.X) / 2, (corner.Y + min.Y) / 2, (corner.Z + min.Z) / 2); var plane = PlaneToSpeckle(new Autodesk.AutoCAD.Geometry.Plane(min, origin, corner)); box = new Box(plane, xSize, ySize, zSize, ModelUnits) { area = area, volume = volume }; } return(box); } catch { return(null); } }
// Boxes public Box BoxToSpeckle(AcadDB.Extents3d extents, bool OrientToWorldXY = false) { try { Box box = null; // get dimension intervals var xSize = new Interval(extents.MinPoint.X, extents.MaxPoint.X); var ySize = new Interval(extents.MinPoint.Y, extents.MaxPoint.Y); var zSize = new Interval(extents.MinPoint.Z, extents.MaxPoint.Z); // get box size info double area = 2 * ((xSize.Length * ySize.Length) + (xSize.Length * zSize.Length) + (ySize.Length * zSize.Length)); double volume = xSize.Length * ySize.Length * zSize.Length; if (OrientToWorldXY) { var origin = new Point3d(0, 0, 0); var normal = new Vector3d(0, 0, 1); var plane = PlaneToSpeckle(new Autodesk.AutoCAD.Geometry.Plane(origin, normal)); box = new Box(plane, xSize, ySize, zSize, ModelUnits) { area = area, volume = volume }; } else { // get base plane var corner = new Point3d(extents.MaxPoint.X, extents.MaxPoint.Y, extents.MinPoint.Z); var origin = new Point3d((corner.X + extents.MinPoint.X) / 2, (corner.Y + extents.MinPoint.Y) / 2, (corner.Z + extents.MinPoint.Z) / 2); var plane = PlaneToSpeckle(new Autodesk.AutoCAD.Geometry.Plane(extents.MinPoint, origin, corner)); box = new Box(plane, xSize, ySize, zSize, ModelUnits) { area = area, volume = volume }; } return(box); } catch { return(null); } }