Exemple #1
0
        //**METHODS**ACTIONS

        public bool addSurface(int color, Surface surface)
        {
            PolyCurve border = PolyCurve.ByJoinedCurves(surface.PerimeterCurves());

            if (!border.IsPlanar)
            {
                int     n      = border.NumberOfCurves;
                Point[] points = border.PointsAtEqualSegmentLength(3 * n);
                Plane   plane  = Plane.ByBestFitThroughPoints(points);
                border = (PolyCurve)border.PullOntoPlane(plane);
                //dispose
                points.ForEach(p => p.Dispose());
                plane.Dispose();
            }

            ///TODO: implemnt space filling curve based on offset
            List <Curve> fillCurves = new List <Curve>();
            PolyCurve    fillPath   = PolyCurve.ByJoinedCurves(fillCurves);

            this[color].Add(fillPath);
            fillCurves.ForEach(c => c.Dispose());

            border.Dispose();
            return(true);
        }
Exemple #2
0
        public static Autodesk.DesignScript.Geometry.PolyCurve ToProtoType(this Autodesk.Revit.DB.CurveArray revitCurves,
                                                                           bool performHostUnitConversion = true)
        {
            if (revitCurves == null)
            {
                throw new ArgumentNullException("revitCurves");
            }

            var protoCurves = revitCurves.Cast <Autodesk.Revit.DB.Curve>().Select(x => x.ToProtoType(false));
            var converted   = PolyCurve.ByJoinedCurves(protoCurves.ToArray());

            foreach (var curve in protoCurves)
            {
                curve.Dispose();
            }

            if (converted == null)
            {
                throw new Exception("An unexpected failure occurred when attempting to convert the curve");
            }

            if (performHostUnitConversion)
            {
                UnitConverter.ConvertToDynamoUnits(ref converted);
            }

            return(converted);
        }
Exemple #3
0
        /// <exclude />
        private Element ToHorizontalFloor(FloorType floorType, Level level)
        {
            Utils.Log(string.Format("MultiPoint.ToHorizontalFloor started...", ""));

            try
            {
                if (!SessionVariables.ParametersCreated)
                {
                    UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
                }

                PolyCurve outline = PolyCurve.ByPoints(this.ShapePoints.Points.Select(p => p.RevitPoint).ToList(), true);

                outline = PolyCurve.ByJoinedCurves(outline.PullOntoPlane(Plane.XY()).Explode().Cast <Curve>().ToList());

                var output = Floor.ByOutlineTypeAndLevel(outline, floorType, level);

                output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, SerializeJSON());

                Utils.Log(string.Format("MultiPoint.ToHorizontalFloor completed.", ""));

                return(output);
            }
            catch (Exception ex)
            {
                Utils.Log(string.Format("ERROR: MultiPoint.ToHorizontalFloor {0}", ex.Message));
                throw ex;
            }
        }
 public static List <PolyCurve> GetEdgeLoopsFromRevitFaceAsPolyCurves(Autodesk.Revit.DB.Face face)
 {
     return(face.EdgeLoops.Cast <EdgeArray>()
            .Select(x => x.Cast <Autodesk.Revit.DB.Edge>())
            .Select(x => x.Select(t => t.AsCurveFollowingFace(face).ToProtoType(false)))
            .Select(x => PolyCurve.ByJoinedCurves(x))
            .ToList());
 }
Exemple #5
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outlineCurves"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(Curve[] outlineCurves, FloorType floorType, Level level)
        {
            if (outlineCurves == null)
            {
                throw new ArgumentNullException("outlineCurves");
            }

            return(ByOutlineTypeAndLevel(PolyCurve.ByJoinedCurves(outlineCurves), floorType, level));
        }
Exemple #6
0
        /// <summary>
        /// Create a Revit Floor given its curve outline and Level
        /// </summary>
        /// <param name="outlineCurves"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(Curve[] outlineCurves, FloorType floorType, Level level)
        {
            if (outlineCurves == null)
            {
                throw new ArgumentNullException("outlineCurves");
            }

            var floor = ByOutlineTypeAndLevel(PolyCurve.ByJoinedCurves(outlineCurves), floorType, level);
            DocumentManager.Regenerate();
            return floor;
        }
Exemple #7
0
        public static Autodesk.DesignScript.Geometry.PolyCurve ToProtoType(this Autodesk.Revit.DB.CurveArray revitCurves)
        {
            if (revitCurves == null)
            {
                throw new ArgumentNullException("revitCurves");
            }

            var protoCurves = revitCurves.Cast <Autodesk.Revit.DB.Curve>().Select(x => x.ToProtoType());

            return(PolyCurve.ByJoinedCurves(protoCurves.ToArray()));
        }
Exemple #8
0
        /// <summary>
        /// Create a Revit Ceiling given its curve outline and Level
        /// </summary>
        /// <param name="outlineCurves"></param>
        /// <param name="ceilingType"></param>
        /// <param name="level"></param>
        /// <returns>The ceiling</returns>
        public static Ceiling ByOutlineTypeAndLevel(Curve[] outlineCurves, CeilingType ceilingType, Level level)
        {
            if (outlineCurves == null)
            {
                throw new ArgumentNullException("outlineCurves");
            }

            var ceiling = ByOutlineTypeAndLevel(PolyCurve.ByJoinedCurves(outlineCurves), ceilingType, level);

            DocumentManager.Regenerate();
            return(ceiling);
        }
        public PolyCurve PolycurveToNative(Polycurve polycurve)
        {
            DS.Curve[] curves = new DS.Curve[polycurve.segments.Count];
            for (var i = 0; i < polycurve.segments.Count; i++)
            {
                switch (polycurve.segments[i])
                {
                case Line curve:
                    curves[i] = LineToNative(curve);
                    break;

                case Arc curve:
                    curves[i] = ArcToNative(curve);
                    break;

                case Circle curve:
                    curves[i] = CircleToNative(curve);
                    break;

                case Ellipse curve:
                    curves[i] = EllipseToNative(curve);
                    break;

                case Spiral curve:
                    curves[i] = PolylineToNative(curve.displayValue);
                    break;

                case Polycurve curve:
                    curves[i] = PolycurveToNative(curve);
                    break;

                case Polyline curve:
                    curves[i] = PolylineToNative(curve);
                    break;

                case Curve curve:
                    curves[i] = CurveToNative(curve);
                    break;
                }
            }

            PolyCurve polyCrv = null;

            if (curves.Any())
            {
                polyCrv = PolyCurve.ByJoinedCurves(curves);
                polyCrv = polyCrv.SetDynamoProperties <PolyCurve>(GetDynamicMembersFromBase(polycurve));
            }

            return(polyCrv);
        }
Exemple #10
0
        /// <summary>
        /// Create a Revit Roof given its curve outline and Level
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="RoofType"></param>
        /// <param name="level"></param>
        /// <returns>The Roof</returns>
        public static Roof ByOutlineTypeAndLevel(Curve[] outline, RoofType roofType, Level level)
        {
            var polycurve = PolyCurve.ByJoinedCurves(outline);

            if (!polycurve.IsClosed)
            {
                throw new ArgumentException(Properties.Resources.OpenInputPolyCurveError);
            }

            var ca = new CurveArray();

            polycurve.Curves().ForEach(x => ca.Append(x.ToRevitType()));

            var roof = new Roof(ca, level.InternalLevel, roofType.InternalRoofType);

            DocumentManager.Regenerate();
            return(roof);
        }
        private static List <PolyCurve> CurveLoopsAsPolyCurves(Face face,
                                                               IEnumerable <IEnumerable <Autodesk.Revit.DB.Curve> > curveLoops)
        {
            List <PolyCurve> result = new List <PolyCurve>();

            foreach (var curveLoop in curveLoops)
            {
                List <Autodesk.DesignScript.Geometry.Curve> curves =
                    new List <Autodesk.DesignScript.Geometry.Curve>();
                foreach (var curve in curveLoop)
                {
                    curves.Add(curve.ToProtoType(false));
                }
                result.Add(PolyCurve.ByJoinedCurves(curves));
                curves.ForEach(x => x.Dispose());
                curves.Clear();
            }
            return(result);
        }
Exemple #12
0
        /// <summary>
        /// Creates a simplified version of the curve by creating lines with a maximum length defined.
        /// </summary>
        /// <param name="curve">Curve to polygonize</param>
        /// <param name="maxLength">Maximum length of subdivisions</param>
        /// <param name="asPolycurve">If true returns a Polycurve or a list of lines otherwise.</param>
        /// <returns></returns>
        public static object Polygonize(DSCurve curve, double maxLength, bool asPolycurve = false)
        {
            //TODO : Look into http://www.antigrain.com/research/adaptive_bezier/index.html
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }
            List <DSCurve> lines      = new List <DSCurve>();
            bool           isStraight = curve.Length.AlmostEqualTo(curve.StartPoint.DistanceTo(curve.EndPoint));

            if (isStraight)
            {
                lines.Add(curve);
            }
            else
            {
                int divisions = (int)Math.Ceiling(curve.Length / maxLength);
                if (divisions > 1)
                {
                    var points = curve.PointsAtEqualSegmentLength(divisions);
                    lines.Add(Line.ByStartPointEndPoint(curve.StartPoint, points.First()));
                    for (var i = 0; i < points.Count() - 1; i++)
                    {
                        lines.Add(Line.ByStartPointEndPoint(points[i], points[i + 1]));
                    }
                    lines.Add(Line.ByStartPointEndPoint(points.Last(), curve.EndPoint));
                }
                else
                {
                    lines.Add(Line.ByStartPointEndPoint(curve.StartPoint, curve.EndPoint));
                }
            }

            if (asPolycurve)
            {
                return(PolyCurve.ByJoinedCurves(lines));
            }
            else
            {
                return(lines);
            }
        }
        private static List <PolyCurve> EdgeLoopsAsPolyCurves(Face face,
                                                              IEnumerable <IEnumerable <Edge> > edgeLoops)
        {
            List <PolyCurve> result = new List <PolyCurve>();

            foreach (var edgeLoop in edgeLoops)
            {
                List <Autodesk.DesignScript.Geometry.Curve> curves =
                    new List <Autodesk.DesignScript.Geometry.Curve>();
                foreach (var edge in edgeLoop)
                {
                    var dbCurve = edge.AsCurveFollowingFace(face);
                    curves.Add(dbCurve.ToProtoType(false));
                }
                result.Add(PolyCurve.ByJoinedCurves(curves));
                curves.ForEach(x => x.Dispose());
                curves.Clear();
            }
            return(result);
        }
Exemple #14
0
        public void ByOutlineTypeAndLevel_PolyCurveFloorTypeLevel_ProducesFloorWithCorrectArea()
        {
            var elevation = 100;
            var level     = Level.ByElevation(elevation);

            var outline = new[]
            {
                Line.ByStartPointEndPoint(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(100, 0, 0)),
                Line.ByStartPointEndPoint(Point.ByCoordinates(100, 0, 0), Point.ByCoordinates(100, 100, 0)),
                Line.ByStartPointEndPoint(Point.ByCoordinates(100, 100, 0), Point.ByCoordinates(0, 100, 0)),
                Line.ByStartPointEndPoint(Point.ByCoordinates(0, 100, 0), Point.ByCoordinates(0, 0, 0))
            };

            var polyCurveOutline = PolyCurve.ByJoinedCurves(outline);

            var floorType = FloorType.ByName("Generic - 12\"");

            var floor = Floor.ByOutlineTypeAndLevel(polyCurveOutline, floorType, level);

            BoundingBoxVolume(floor.BoundingBox).ShouldBeApproximately(100 * 100 * 0.3048, 1e-3);
        }
Exemple #15
0
        public static PolyCurve ToNative(this SpecklePolycurve polycurve)
        {
            Curve[] curves = new Curve[polycurve.Segments.Count];
            for (var i = 0; i < polycurve.Segments.Count; i++)
            {
                switch (polycurve.Segments[i])
                {
                case SpeckleLine curve:
                    curves[i] = curve.ToNative();
                    break;

                case SpeckleArc curve:
                    curves[i] = curve.ToNative();
                    break;

                case SpeckleCircle curve:
                    curves[i] = curve.ToNative();
                    break;

                case SpeckleEllipse curve:
                    curves[i] = curve.ToNative();
                    break;

                case SpecklePolycurve curve:
                    curves[i] = curve.ToNative();
                    break;

                case SpecklePolyline curve:
                    curves[i] = curve.ToNative();
                    break;

                case SpeckleCurve curve:
                    curves[i] = curve.ToNative();
                    break;
                }
            }
            var polyCrv = PolyCurve.ByJoinedCurves(curves);

            return(polyCrv.SetSpeckleProperties <PolyCurve>(polycurve.Properties));
        }
        public void AddToMatchingCurve(Curve curve)
        {
            // Prepare a curve list to create a polycurve from
            List <Curve> curvesTojoin = new List <Curve>();

            curvesTojoin.Add(curve);

            // If the curve is connected to Curve 1
            if (Curve1.StartPoint.IsAlmostEqualTo(curve.EndPoint) || Curve1.EndPoint.IsAlmostEqualTo(curve.StartPoint))
            {
                // Add curve1 to the list and create a polycurve
                curvesTojoin.Add(Curve1);
                Curve newCurve = PolyCurve.ByJoinedCurves(curvesTojoin);
                this.Curve1 = newCurve;
            }
            // If the curve is connected to curve 2
            else if (Curve2 != null && (Curve2.StartPoint.IsAlmostEqualTo(curve.EndPoint) || Curve2.EndPoint.IsAlmostEqualTo(curve.StartPoint)))
            {
                // Add curve 2 to the list and create a polycurve from them
                curvesTojoin.Add(Curve2);
                Curve newCurve = PolyCurve.ByJoinedCurves(curvesTojoin);
                this.Curve2 = newCurve;
            }
            else
            {
                // If the curve doesnt connect and curve 2 hasnt been defined yet
                // take is as curve 2 otherwise add the unconnectable curve to the undefined list and throw an error
                if (this.Curve2 == null)
                {
                    this.Curve2 = curve;
                }
                else
                {
                    Undefined.Add(curve);
                    throw new ArgumentNullException("Cannot parametrize surface, try increasing the tolerance.");
                }
            }
        }
        public static Dictionary <string, object> ConvertSiteOutlineToPolygon2d(List <Geometry> geomList, double inset = 5)// Geometry
        {
            string         type      = geomList[0].GetType().ToString();
            List <Point2d> pointList = new List <Point2d>();
            //Trace.WriteLine("list found is + " + type);
            List <NurbsCurve> nurbList = new List <NurbsCurve>();

            if (type.IndexOf("Line") != -1)
            {
                List <Line> lineList = new List <Line>();
                for (int i = 0; i < geomList.Count; i++)
                {
                    lineList.Add((Line)geomList[i]);
                }
                for (int i = 0; i < lineList.Count; i++)
                {
                    Point2d pointPerCurve = Point2d.ByCoordinates(lineList[i].StartPoint.X, lineList[i].StartPoint.Y);
                    pointList.Add(pointPerCurve);
                    if (i == lineList.Count)
                    {
                        pointList.Add(Point2d.ByCoordinates(lineList[i].EndPoint.X, lineList[i].EndPoint.Y));
                    }
                }
            }
            else if (type.IndexOf("NurbsCurve") != -1)
            {
                nurbList = new List <NurbsCurve>();
                for (int i = 0; i < geomList.Count; i++)
                {
                    nurbList.Add((NurbsCurve)geomList[i]);
                }

                /*
                 * for (int i = 0; i < nurbList.Count; i++)
                 * {
                 *  Point2d pointPerCurve = Point2d.ByCoordinates(nurbList[i].StartPoint.X, nurbList[i].StartPoint.Y);
                 *  pointList.Add(pointPerCurve);
                 *  if (i == nurbList.Count) pointList.Add(Point2d.ByCoordinates(nurbList[i].EndPoint.X, nurbList[i].EndPoint.Y));
                 * }
                 */
            }
            else
            {
                return(null);
            }

            PolyCurve pCrv = PolyCurve.ByJoinedCurves((Curve[])nurbList.ToArray());


            Curve   cInsetA = pCrv.Offset(inset);
            Curve   cInsetB = pCrv.Offset(inset * -1);
            Curve   cInset;
            Surface srfA = Surface.ByPatch(cInsetA), srfB = Surface.ByPatch(cInsetB);

            if (srfA.Area > srfB.Area)
            {
                cInset = cInsetB;
            }
            else
            {
                cInset = cInsetA;
            }

            srfA.Dispose(); srfB.Dispose();
            List <Curve> curvList = new List <Curve>();

            geomList = cInset.Explode().ToList();
            for (int i = 0; i < geomList.Count; i++)
            {
                curvList.Add((Curve)geomList[i]);
            }
            for (int i = 0; i < curvList.Count; i++)
            {
                Point2d pointPerCurve = Point2d.ByCoordinates(curvList[i].StartPoint.X, curvList[i].StartPoint.Y);
                pointList.Add(pointPerCurve);
                if (i == curvList.Count)
                {
                    pointList.Add(Point2d.ByCoordinates(curvList[i].EndPoint.X, curvList[i].EndPoint.Y));
                }
            }
            //return new Polygon2d(pointList);
            return(new Dictionary <string, object>
            {
                { "InsetSiteOutline", (new Polygon2d(pointList)) }
            });
        }
Exemple #18
0
        protected override (Curve boundary, List <Curve> holes) CreateBaseCurves()
        {
            // The D is pointing "down" so that it matches with the U.

            var holes          = new List <Curve>();
            var boundaryCurves = new List <Curve>();

            var arcHeight = Math.Min(
                Length - (UsesDepth ? Depth : 0),
                Width / 2);

            Point[] points;

            if (IsCurved)
            {
                Plane arcCenter = null;

                using (var point = Point.ByCoordinates(Width / 2, arcHeight))
                    using (var zAxis = Vector.ZAxis())
                    {
                        arcCenter = Plane.ByOriginNormal(point, zAxis);
                    }

                boundaryCurves.Add(EllipseArc.ByPlaneRadiiAngles(arcCenter, Width / 2, arcHeight, 180, 180));

                if (arcHeight < Length)
                {
                    points = new[]
                    {
                        Point.ByCoordinates(Width, arcHeight),
                        Point.ByCoordinates(Width, Length),
                        Point.ByCoordinates(0, Length),
                        Point.ByCoordinates(0, arcHeight)
                    };

                    // Outside of D has a square back.
                    boundaryCurves.Add(PolyCurve.ByPoints(points));

                    points.ForEach(p => p.Dispose());
                }
                else
                {
                    points = new[]
                    {
                        Point.ByCoordinates(Width, Length),
                        Point.ByCoordinates(0, Length)
                    };

                    // Outside of D is half an ellipse (or circle).
                    boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1]));

                    points.ForEach(p => p.Dispose());
                }

                if (UsesDepth)
                {
                    var curves = new List <Curve>
                    {
                        EllipseArc.ByPlaneRadiiAngles(arcCenter, (Width / 2) - Depth, arcHeight - Depth, 0, -180)
                    };

                    if (arcHeight < Length - Depth)
                    {
                        points = new[]
                        {
                            Point.ByCoordinates(Depth, arcHeight),
                            Point.ByCoordinates(Depth, Length - Depth),
                            Point.ByCoordinates(Width - Depth, Length - Depth),
                            Point.ByCoordinates(Width - Depth, arcHeight)
                        };

                        curves.Add(PolyCurve.ByPoints(points));

                        points.ForEach(p => p.Dispose());
                    }
                    else
                    {
                        points = new[]
                        {
                            Point.ByCoordinates(Depth, arcHeight),
                            Point.ByCoordinates(Width - Depth, arcHeight)
                        };

                        curves.Add(Line.ByStartPointEndPoint(points[0], points[1]));

                        points.ForEach(p => p.Dispose());
                    }

                    holes.Add(PolyCurve.ByJoinedCurves(curves));

                    curves.ForEach(x => x.Dispose());
                }

                arcCenter.Dispose();
            }
            else
            {
                // Faceted D.

                double baseWidth = Width * Math.Tan(Math.PI / 8);
                double sideWidth = baseWidth * arcHeight / (2 * Width);

                points = new[]
                {
                    Point.ByCoordinates(Width, Length),
                    Point.ByCoordinates(0, Length),
                    Point.ByCoordinates(0, arcHeight - sideWidth),
                    Point.ByCoordinates((Width - baseWidth) / 2, 0),
                    Point.ByCoordinates((Width + baseWidth) / 2, 0),
                    Point.ByCoordinates(Width, arcHeight - sideWidth)
                };

                boundaryCurves.Add(PolyCurve.ByPoints(points, connectLastToFirst: true));

                points.ForEach(p => p.Dispose());

                if (UsesDepth)
                {
                    double angleA          = Math.Atan2(2 * (arcHeight - sideWidth), Width - baseWidth);
                    double offsetBaseWidth = baseWidth - (2 * Depth / Math.Tan((Math.PI - angleA) / 2));
                    double offsetSideWidth = sideWidth - (Depth / Math.Tan((angleA / 2) + (Math.PI / 4)));

                    points = new[]
                    {
                        Point.ByCoordinates(Width - Depth, Length - Depth),
                        Point.ByCoordinates(Width - Depth, arcHeight - offsetSideWidth),
                        Point.ByCoordinates((Width + offsetBaseWidth) / 2, Depth),
                        Point.ByCoordinates((Width - offsetBaseWidth) / 2, Depth),
                        Point.ByCoordinates(Depth, arcHeight - offsetSideWidth),
                        Point.ByCoordinates(Depth, Length - Depth)
                    };

                    holes.Add(PolyCurve.ByPoints(points, connectLastToFirst: true));

                    points.ForEach(p => p.Dispose());
                }
            }

            var boundary = PolyCurve.ByJoinedCurves(boundaryCurves);

            return(boundary, holes);
        }
Exemple #19
0
        protected override (Curve boundary, List <Curve> holes) CreateBaseCurves()
        {
            Curve boundary = null;

            Point[] points;

            if (IsCurved)
            {
                var holes          = new List <Curve>();
                var boundaryCurves = new List <Curve>();

                var arcHeight = Math.Min(Length, Width / 2);

                using (Plane arcCenter = Plane.ByOriginNormal(
                           Point.ByCoordinates(Width / 2, arcHeight),
                           Vector.ZAxis()))
                {
                    boundaryCurves.Add(EllipseArc.ByPlaneRadiiAngles(arcCenter, Width / 2, arcHeight, 180, 180));

                    if (UsesDepth)
                    {
                        if (arcHeight < Length)
                        {
                            // Top of U has straight parts.
                            points = new[]
                            {
                                Point.ByCoordinates(Width, arcHeight),
                                Point.ByCoordinates(Width, Length),
                                Point.ByCoordinates(Width - Depth, Length),
                                Point.ByCoordinates(Width - Depth, arcHeight)
                            };

                            boundaryCurves.Add(PolyCurve.ByPoints(points));

                            points.ForEach(p => p.Dispose());
                        }
                        else
                        {
                            points = new[]
                            {
                                Point.ByCoordinates(Width, Length),
                                Point.ByCoordinates(Width - Depth, Length)
                            };

                            // Top of U has no straight parts.
                            boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1]));

                            points.ForEach(p => p.Dispose());
                        }

                        boundaryCurves.Add(EllipseArc.ByPlaneRadiiAngles(arcCenter, (Width / 2) - Depth, arcHeight - Depth, 0, -180));

                        if (arcHeight < Length)
                        {
                            // Top of U has straight parts.

                            points = new[]
                            {
                                Point.ByCoordinates(Depth, arcHeight),
                                Point.ByCoordinates(Depth, Length),
                                Point.ByCoordinates(0, Length),
                                Point.ByCoordinates(0, arcHeight)
                            };

                            boundaryCurves.Add(PolyCurve.ByPoints(points));

                            points.ForEach(p => p.Dispose());
                        }
                        else
                        {
                            // Top of U has no straight parts.

                            points = new[]
                            {
                                Point.ByCoordinates(Depth, Length),
                                Point.ByCoordinates(0, Length)
                            };

                            boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1]));

                            points.ForEach(p => p.Dispose());
                        }
                    }
                    else
                    {
                        // U has no interior.

                        if (arcHeight < Length)
                        {
                            points = new[]
                            {
                                Point.ByCoordinates(Width, arcHeight),
                                Point.ByCoordinates(Width, Length),
                                Point.ByCoordinates(0, Length),
                                Point.ByCoordinates(0, arcHeight)
                            };

                            boundaryCurves.Add(PolyCurve.ByPoints(points));

                            points.ForEach(p => p.Dispose());
                        }
                        else
                        {
                            points = new[]
                            {
                                Point.ByCoordinates(Width, Length),
                                Point.ByCoordinates(0, Length)
                            };

                            boundaryCurves.Add(Line.ByStartPointEndPoint(points[0], points[1]));

                            points.ForEach(p => p.Dispose());
                        }
                    }
                }

                boundary = PolyCurve.ByJoinedCurves(boundaryCurves);
            }
            else
            {
                // Straight U

                if (UsesDepth)
                {
                    points = new[]
                    {
                        Point.ByCoordinates(0, 0),
                        Point.ByCoordinates(Width, 0),
                        Point.ByCoordinates(Width, Length),
                        Point.ByCoordinates(Width - Depth, Length),
                        Point.ByCoordinates(Width - Depth, Depth),
                        Point.ByCoordinates(Depth, Depth),
                        Point.ByCoordinates(Depth, Length),
                        Point.ByCoordinates(0, Length)
                    };

                    boundary = PolyCurve.ByPoints(points, connectLastToFirst: true);

                    points.ForEach(p => p.Dispose());
                }
                else
                {
                    // Solid straight U (rectangle)

                    points = new[]
                    {
                        Point.ByCoordinates(0, 0),
                        Point.ByCoordinates(Width, 0),
                        Point.ByCoordinates(Width, Length),
                        Point.ByCoordinates(0, Length)
                    };

                    boundary = PolyCurve.ByPoints(points, connectLastToFirst: true);

                    points.ForEach(p => p.Dispose());
                }
            }

            return(boundary, default);
        }
Exemple #20
0
        /// <summary>
        /// Gets a list of closed polycurve edges of surface. First list item is outside boundary.
        /// </summary>
        /// <param name="surface">The surface.</param>
        /// <returns name="edgeCrvList">Edges of surface.</returns>
        /// <exception cref="ArgumentNullException">Surface</exception>
        public static PolyCurve[] GetSurfaceLoops(Surface surface)
        {
            if (surface == null)
            {
                throw new ArgumentNullException(nameof(surface));
            }

            var curves = surface.PerimeterCurves();

            var loops = new List <PolyCurve>();

            foreach (var curve in curves)
            {
                var added = false;

                for (var i = 0; i < loops.Count; i++)
                {
                    var loop = loops[i];

                    if (loop.IsClosed)
                    {
                        continue;
                    }

                    if (loop.StartPoint.IsAlmostEqualTo(curve.StartPoint) ||
                        loop.StartPoint.IsAlmostEqualTo(curve.EndPoint) ||
                        loop.EndPoint.IsAlmostEqualTo(curve.StartPoint) ||
                        loop.EndPoint.IsAlmostEqualTo(curve.EndPoint))
                    {
                        try
                        {
                            loops[i] = loop.Join(new[] { curve });

                            added = true;
                            break;
                        }
                        catch (ApplicationException)
                        {
                            continue;
                        }
                    }
                }

                if (!added)
                {
                    loops.Add(PolyCurve.ByJoinedCurves(new[] { curve }));
                }

                curve.Dispose();
            }

            if (loops.Any(loop => !loop.IsClosed))
            {
                throw new ArgumentException("Created non-closed polycurve.");
            }

            return(loops.OrderByDescending(c =>
            {
                using (var s = Surface.ByPatch(c))
                {
                    return s.Area;
                }
            }).ToArray());
        }
Exemple #21
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outline">The outline.</param>
        /// <param name="floorType">Type of the floor.</param>
        /// <param name="level">The level.</param>
        /// <param name="structural">if set to <c>true</c> [structural].</param>
        /// <returns>
        /// The floor
        /// </returns>
        public static SlopedFloor ByOutlineTypeAndLevel(Autodesk.DesignScript.Geometry.PolyCurve outline, Revit.Elements.FloorType floorType, Revit.Elements.Level level, bool structural)
        {
            Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel started...", ""));

            try
            {
                var profile = new CurveArray();

                Autodesk.DesignScript.Geometry.Plane plane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(
                    outline.Curves().Cast <Autodesk.DesignScript.Geometry.Curve>().Select(x => x.StartPoint));

                Vector normal = plane.Normal;
                if (normal.Dot(Vector.ZAxis()) <= 0)
                {
                    normal = normal.Reverse();
                }

                Autodesk.DesignScript.Geometry.Point origin     = plane.Origin;
                Autodesk.DesignScript.Geometry.Point end        = origin.Add(normal);
                Autodesk.DesignScript.Geometry.Point projection = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, -1000);
                end = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, end.Z + 1000);
                Autodesk.DesignScript.Geometry.Point intersection = null;
                var result = plane.Intersect(Autodesk.DesignScript.Geometry
                                             .Line.ByStartPointEndPoint(end, projection));

                if (result.Length > 0)
                {
                    intersection = result[0] as Autodesk.DesignScript.Geometry.Point;
                }
                else
                {
                    var message = "Couldn't find intersection";

                    Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", message));

                    throw new Exception(message);
                }

                Autodesk.DesignScript.Geometry.Curve temp = Autodesk.DesignScript.Geometry.Line.ByBestFitThroughPoints(new Autodesk.DesignScript.Geometry.Point[] { origin, intersection });

                PolyCurve flat = PolyCurve.ByJoinedCurves(outline.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY()
                                                                                .Offset(temp.StartPoint.Z)).Explode().Cast <Autodesk.DesignScript.Geometry.Curve>().ToList());

                Autodesk.DesignScript.Geometry.Curve flatLine = temp.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY().Offset(temp.StartPoint.Z));

                if (Math.Abs(Math.Abs(plane.Normal.Dot(Vector.ZAxis())) - 1) < 0.00001)
                {
                    var f = Revit.Elements.Floor.ByOutlineTypeAndLevel(flat, floorType, level);
                    f.InternalElement.Parameters.Cast <Autodesk.Revit.DB.Parameter>()
                    .First(x => x.Id.IntegerValue.Equals(Autodesk.Revit.DB.BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL))
                    .Set(structural ? 1 : 0);

                    plane.Dispose();
                    flatLine.Dispose();
                    flat.Dispose();
                    origin.Dispose();
                    end.Dispose();
                    projection.Dispose();
                    intersection.Dispose();
                    temp.Dispose();

                    return(new SlopedFloor(f.InternalElement as Autodesk.Revit.DB.Floor));
                }

                double slope = (temp.EndPoint.Z - temp.StartPoint.Z) / flatLine.Length;

                foreach (Autodesk.DesignScript.Geometry.Curve c in flat.Curves())
                {
                    profile.Append(c.ToRevitType());
                }

                Autodesk.Revit.DB.Line slopeArrow = flatLine.ToRevitType() as Autodesk.Revit.DB.Line;

                var ft  = floorType.InternalElement as Autodesk.Revit.DB.FloorType;
                var lvl = level.InternalElement as Autodesk.Revit.DB.Level;

                var floor = new SlopedFloor(profile, slopeArrow, slope, ft, lvl, structural);

                floor.Level      = level;
                floor.Floortype  = floorType;
                floor.Structural = structural;

                //DocumentManager.Regenerate();

                plane.Dispose();
                flatLine.Dispose();
                flat.Dispose();
                origin.Dispose();
                end.Dispose();
                projection.Dispose();
                intersection.Dispose();
                temp.Dispose();

                Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel completed.", ""));

                return(floor);
            }
            catch (Exception ex)
            {
                Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", ex.Message));

                throw ex;
            }
        }
Exemple #22
0
        public static Dictionary <string, Autodesk.DesignScript.Geometry.Surface> Create(
            Autodesk.DesignScript.Geometry.Surface surface,
            double offset,
            double depth)
        {
            // offset perimeter curves by the specified offset and create new surface.
            // makes sure there are space between outer perimeter and the amenity space
            List <Curve> inCrvs = surface.OffsetPerimeterCurves(offset)["insetCrvs"].ToList();
            Surface      inSrf  = Surface.ByPatch(PolyCurve.ByJoinedCurves(inCrvs));

            // get longest curve of the inSrf
            Curve        max;
            List <Curve> others;
            Dictionary <string, dynamic> dict = inCrvs.MaximumLength();

            if (dict["maxCrv"].Count < 1)
            {
                max = dict["otherCrvs"][0] as Curve;
                int          count = dict["otherCrvs"].Count;
                List <Curve> rest  = dict["otherCrvs"];
                others = rest.GetRange(1, (count - 1));
            }
            else
            {
                max    = dict["maxCrv"][0] as Curve;
                others = dict["otherCrvs"];
            }

            // get perimeter curves of input surface
            List <Curve> perimCrvs = surface.PerimeterCurves().ToList();
            List <Curve> matchCrvs = max.FindMatchingVectorCurves(perimCrvs);

            // get longest curve
            Curve max2;
            Dictionary <string, dynamic> dict2 = matchCrvs.MaximumLength();

            if (dict2["maxCrv"].Count < 1)
            {
                max2 = dict2["otherCrvs"][0] as Curve;
            }
            else
            {
                max2 = dict2["maxCrv"][0] as Curve;
            }

            Vector vec = max2.ByTwoCurves(max);

            Curve transLine  = max.Translate(vec, depth) as Curve;
            Line  extendLine = transLine.ExtendAtBothEnds(1);


            List <Curve> crvList = new List <Curve>()
            {
                max, extendLine
            };
            Surface loftSrf = Surface.ByLoft(crvList);

            List <bool> boolLst = new List <bool>();

            foreach (var crv in others)
            {
                bool b = max.DoesIntersect(crv);
                boolLst.Add(b);
            }

            List <Curve> intersectingCurves = others
                                              .Zip(boolLst, (name, filter) => new { name, filter, })
                                              .Where(item => item.filter == true)
                                              .Select(item => item.name)
                                              .ToList();
            List <Curve> extendCurves = new List <Curve>();

            foreach (Curve crv in intersectingCurves)
            {
                var l = crv.ExtendAtBothEnds(1);
                extendCurves.Add(l);
            }

            List <Surface> split = loftSrf
                                   .SplitPlanarSurfaceByMultipleCurves(extendCurves)
                                   .OfType <Surface>()
                                   .ToList();

            Surface amenitySurf = split.MaximumArea()["maxSrf"] as Surface;

            Surface remainSurf = inSrf.Split(amenitySurf)[0] as Surface;

            Dictionary <string, Surface> newOutput;

            newOutput = new Dictionary <string, Surface>
            {
                { amenitySurfaceOutputPort, amenitySurf },
                { remainingSurfaceOutputPort, remainSurf }
            };

            //Dispose redundant geometry
            inCrvs.ForEach(crv => crv.Dispose());
            inSrf.Dispose();
            max.Dispose();
            perimCrvs.ForEach(crv => crv.Dispose());
            matchCrvs.ForEach(crv => crv.Dispose());
            max2.Dispose();
            vec.Dispose();
            transLine.Dispose();
            extendLine.Dispose();
            crvList.ForEach(crv => crv.Dispose());
            loftSrf.Dispose();
            intersectingCurves.ForEach(crv => crv.Dispose());
            extendCurves.ForEach(crv => crv.Dispose());

            return(newOutput);
        }
Exemple #23
0
        public static Dictionary <string, object> GroupCurves(List <DSCurve> curves)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("lines");
            }
            if (curves.Count < 2)
            {
                throw new ArgumentException("Needs 2 or more lines", "lines");
            }

            Dictionary <gVertex, List <DSCurve> > graph    = CurvesDependency(curves);
            Dictionary <int, List <DSCurve> >     grouped  = new Dictionary <int, List <DSCurve> >();
            Dictionary <gVertex, int>             vertices = new Dictionary <gVertex, int>();

            foreach (gVertex v in graph.Keys)
            {
                // If already belongs to a polygon or is not a polygon vertex or already computed
                if (vertices.ContainsKey(v) || graph[v].Count > 2)
                {
                    continue;
                }

                // grouped.Count() translates to the number of different groups created
                vertices.Add(v, grouped.Count());
                grouped.Add(vertices[v], new List <DSCurve>());

                foreach (DSCurve curve in graph[v])
                {
                    var     startVertex = Points.ToVertex(curve.StartPoint);
                    var     endVertex   = Points.ToVertex(curve.EndPoint);
                    DSCurve nextCurve   = curve;
                    gVertex nextVertex  = (startVertex.Equals(v)) ? endVertex : startVertex;

                    while (!vertices.ContainsKey(nextVertex))
                    {
                        vertices.Add(nextVertex, vertices[v]);
                        grouped[vertices[v]].Add(nextCurve);

                        // Next vertex doesn't have any other curve connected.
                        if (graph[nextVertex].Count < 2)
                        {
                            break;
                        }

                        nextCurve   = graph[nextVertex].Where(c => !c.Equals(nextCurve)).First();
                        startVertex = Points.ToVertex(nextCurve.StartPoint);
                        endVertex   = Points.ToVertex(nextCurve.EndPoint);
                        nextVertex  = (startVertex.Equals(nextVertex)) ? endVertex : startVertex;
                    }
                    if (!grouped[vertices[v]].Last().Equals(nextCurve))
                    {
                        grouped[vertices[v]].Add(nextCurve);
                    }
                }
            }

            List <PolyCurve> polyCurves = new List <PolyCurve>();
            List <DSCurve>   ungrouped  = new List <DSCurve>();

            foreach (var group in grouped.Values)
            {
                if (group.Count > 1)
                {
                    polyCurves.Add(PolyCurve.ByJoinedCurves(group));
                }
                else
                {
                    ungrouped.Add(group.First());
                }
            }

            return(new Dictionary <string, object>()
            {
                { "polycurves", polyCurves },
                { "ungrouped", ungrouped }
            });
        }