Пример #1
0
        public static Autodesk.Revit.DB.CurveLoop ToRevitType(this Autodesk.DesignScript.Geometry.PolyCurve pcrv,
                                                              bool performHostUnitConversion = true)
        {
            if (!pcrv.IsClosed)
            {
                throw new Exception("The input PolyCurve must be closed");
            }

            Autodesk.DesignScript.Geometry.Curve[] crvs = null;
            if (performHostUnitConversion)
            {
                pcrv = pcrv.InHostUnits();
                crvs = pcrv.Curves();
                pcrv.Dispose();
            }
            else
            {
                crvs = pcrv.Curves();
            }

            var cl = new CurveLoop();

            foreach (Autodesk.DesignScript.Geometry.Curve curve in crvs)
            {
                using (var nc = curve.ToNurbsCurve())
                {
                    Autodesk.Revit.DB.Curve converted = nc.ToRevitType(false);
                    cl.Append(converted);
                }
            }

            crvs.ForEach(x => x.Dispose());

            return(cl);
        }
Пример #2
0
        private static bool GetRectCorners(dg.PolyCurve crv, out rdb.XYZ corner0, out rdb.XYZ corner1)
        {
            if (crv.NumberOfCurves != 4)
            {
                corner0 = null;
                corner1 = null;
                return(false);
            }

            List <rdb.XYZ> points = new List <rdb.XYZ>();

            foreach (dg.Curve c in crv.Curves())
            {
                points.Add(c.StartPoint.ToXyz());
            }
            points.Sort((x, y) => x.Z.CompareTo(y.Z));

            corner0 = points[0];
            var vect2 = points[2] - corner0;

            if (vect2.AngleTo(rdb.XYZ.BasisZ) > 0.01)
            {
                corner1 = points[2];
                return(true);
            }

            corner1 = points[3];
            return(true);
        }
Пример #3
0
        private static bool VerifyRect(dg.PolyCurve crv)
        {
            if (crv == null)
            {
                return(false);
            }

            if (!crv.IsClosed)
            {
                return(false);
            }

            dg.Curve[] crvs = crv.Curves();
            if (crv.NumberOfCurves != 4)
            {
                return(false);
            }

            dg.Vector v0 = dg.Vector.ByTwoPoints(crvs[0].StartPoint, crvs[0].EndPoint);
            dg.Vector v1 = dg.Vector.ByTwoPoints(crvs[1].StartPoint, crvs[1].EndPoint);
            dg.Vector v2 = dg.Vector.ByTwoPoints(crvs[2].StartPoint, crvs[2].EndPoint);
            dg.Vector v3 = dg.Vector.ByTwoPoints(crvs[3].StartPoint, crvs[3].EndPoint);

            if (Math.Abs(v0.Length - crvs[0].Length) > 0.001 ||
                Math.Abs(v1.Length - crvs[1].Length) > 0.001 ||
                Math.Abs(v2.Length - crvs[2].Length) > 0.001 ||
                Math.Abs(v3.Length - crvs[3].Length) > 0.001)
            {
                return(false);
            }

            // verify the angles
            double a0    = v0.Reverse().AngleWithVector(v1);
            double a1    = v1.Reverse().AngleWithVector(v2);
            double a2    = v2.Reverse().AngleWithVector(v3);
            double a3    = v3.Reverse().AngleWithVector(v0);
            double deg90 = 90; //Math.PI * 0.5;

            if (Math.Abs(a0 - deg90) > 0.001 || Math.Abs(a1 - deg90) > 0.001 || Math.Abs(a2 - deg90) > 0.001 || Math.Abs(a3 - deg90) > 0.001)
            {
                return(false);
            }

            return(true);
        }
        public static PdfAnnotation ToPDFPolygon(this Autodesk.DesignScript.Geometry.PolyCurve polycurve, string content, PdfWriter writer)
        {
            List <float> points = new List <float>();

            foreach (var curve in polycurve.Curves())
            {
                PDFCoords coords = curve.StartPoint.ToPDFCoords();
                points.Add(coords.X);
                points.Add(coords.Y);
            }

            iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(0, 0);

            var app  = new PdfContentByte(writer);
            var anno = PdfAnnotation.CreatePolygonPolyline(writer, rect, content, false, new PdfArray(points.ToArray()));

            return(anno);
        }
Пример #5
0
        /// <summary>
        /// A PolyCurve is not a curve, this is a special extension method to convert to a Revit CurveLoop
        /// </summary>
        /// <param name="pcrv"></param>
        /// <returns></returns>
        public static Autodesk.Revit.DB.CurveLoop ToRevitType(this Autodesk.DesignScript.Geometry.PolyCurve pcrv)
        {
            if (!pcrv.IsClosed)
            {
                throw new Exception("The input PolyCurve must be closed");
            }

            var cl = new CurveLoop();

            var crvs = pcrv.Curves();

            foreach (Autodesk.DesignScript.Geometry.Curve curve in crvs)
            {
                Autodesk.Revit.DB.Curve converted = curve.ToNurbsCurve().ToRevitType();
                cl.Append(converted);
            }

            return(cl);
        }
Пример #6
0
        /// <summary>
        /// Construct a printable polyline.
        /// </summary>
        /// <param name="PolyCurve">a</param>
        /// <param name="MaterialAmount">a</param>
        /// <param name="Speed">a</param>
        /// <param name="Toolhead">a</param>
        /// <param name="MixPercentage">a</param>
        /// <returns name="PrintPolyline">A newly-constructed ZeroTouchEssentials object.</returns>

        public static V2GPrintPolyline PrintPolyline(
            Autodesk.DesignScript.Geometry.PolyCurve PolyCurve,
            double MaterialAmount = 0.033,
            double Speed          = 700.0,
            int Toolhead          = 0,
            double MixPercentage  = 0.0)
        {
            int i = 0;
            V2GPrintPolyline printPolyline = new V2GPrintPolyline();

            foreach (Curve c in PolyCurve.Curves())
            {
                if (i == 0)
                {
                    printPolyline.AddPrintPosition(V2GDesignScriptGeometry.V2GPoint(c.StartPoint));
                }
                printPolyline.AddPrintPosition(V2GDesignScriptGeometry.V2GPoint(c.EndPoint));
            }
            return(printPolyline);
        }
Пример #7
0
        /// <summary>
        /// Create an Advance Steel Weld Line By PolyCurve
        /// </summary>
        /// <param name="polyCurve"> Input Weld PolyCurve</param>
        /// <param name="objectsToConnect"> Input Weld Connected Objects</param>
        /// <param name="connectionType"> Input Weld Type - 0-OnSite or 2-InShop</param>
        /// <returns name="weldLine"> weldLine</returns>
        public static WeldLine ByPolyCurve(DynGeometry.PolyCurve polyCurve,
                                           IEnumerable <SteelDbObject> objectsToConnect,
                                           [DefaultArgument("2;")] int connectionType)
        {
            List <string> handlesList = Utils.GetSteelDbObjectsToConnect(objectsToConnect);

            var temp = polyCurve.Curves();

            SteelGeometry.Point3d[] astArr = new SteelGeometry.Point3d[temp.Length + 1];
            for (int i = 0; i < temp.Length; i++)
            {
                Point3d startPoint = Utils.ToAstPoint(temp[i].StartPoint, true);
                astArr[i] = startPoint;
            }

            Point3d endPoint = Utils.ToAstPoint(temp[temp.Length - 1].EndPoint, true);

            astArr[temp.Length] = endPoint;

            return(new WeldLine(astArr, handlesList, connectionType, polyCurve.IsClosed));
        }
Пример #8
0
        public static Autodesk.Revit.DB.CurveLoop ToRevitType(this Autodesk.DesignScript.Geometry.PolyCurve pcrv,
                                                              bool performHostUnitConversion = true)
        {
            if (!pcrv.IsClosed)
            {
                throw new Exception("The input PolyCurve must be closed");
            }

            pcrv = performHostUnitConversion ? pcrv.InHostUnits() : pcrv;

            var cl   = new CurveLoop();
            var crvs = pcrv.Curves();

            foreach (Autodesk.DesignScript.Geometry.Curve curve in crvs)
            {
                Autodesk.Revit.DB.Curve converted = curve.ToNurbsCurve().ToRevitType(false);
                cl.Append(converted);
            }

            return(cl);
        }
Пример #9
0
        public static Dictionary <string, Autodesk.DesignScript.Geometry.Curve[]> OffsetPerimeterCurves(this Autodesk.DesignScript.Geometry.Surface surface, double offset)
        {
            List <Autodesk.DesignScript.Geometry.Curve> srfPerimCrvs = surface.PerimeterCurves().ToList();

            Autodesk.DesignScript.Geometry.PolyCurve plyCrv = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(srfPerimCrvs);

            double inOffset;
            double outOffset;

            if (offset < 0)
            {
                inOffset  = offset;
                outOffset = -offset;
            }
            else
            {
                inOffset  = -offset;
                outOffset = offset;
            }

            Autodesk.DesignScript.Geometry.Curve[] inPerimCrvs;
            try
            {
                List <Autodesk.DesignScript.Geometry.Curve> inOffsetCrv = new List <Autodesk.DesignScript.Geometry.Curve>()
                {
                    (plyCrv.Offset(inOffset))
                };
                Autodesk.DesignScript.Geometry.PolyCurve    inOffsetPolyCrv = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(inOffsetCrv);
                List <Autodesk.DesignScript.Geometry.Curve> inOffsetCrvList = inOffsetPolyCrv.Curves().ToList();
                List <Autodesk.DesignScript.Geometry.Point> inPts           = new List <Autodesk.DesignScript.Geometry.Point>();
                foreach (Autodesk.DesignScript.Geometry.Curve c in inOffsetCrvList)
                {
                    inPts.Add(c.StartPoint);
                }
                Autodesk.DesignScript.Geometry.PolyCurve inOffsetPolyCrv2 = PolyCurve.ByPoints(inPts, true);
                Autodesk.DesignScript.Geometry.Surface   inOffsetSrf      = Autodesk.DesignScript.Geometry.Surface.ByPatch(inOffsetPolyCrv2);
                inPerimCrvs = inOffsetSrf.PerimeterCurves();
                inOffsetSrf.Dispose();
                inOffsetPolyCrv.Dispose();
                inOffsetPolyCrv2.Dispose();
            }
            catch (Exception)
            {
                inPerimCrvs = null;
            }

            Autodesk.DesignScript.Geometry.Curve[] outPerimCrvs;
            try
            {
                List <Autodesk.DesignScript.Geometry.Curve> outOffsetCrv = new List <Autodesk.DesignScript.Geometry.Curve>()
                {
                    (plyCrv.Offset(outOffset))
                };
                Autodesk.DesignScript.Geometry.PolyCurve    outOffsetPolyCrv = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(outOffsetCrv);
                List <Autodesk.DesignScript.Geometry.Curve> outOffsetCrvList = outOffsetPolyCrv.Curves().ToList();
                List <Autodesk.DesignScript.Geometry.Point> outPts           = new List <Autodesk.DesignScript.Geometry.Point>();
                foreach (Autodesk.DesignScript.Geometry.Curve c in outOffsetCrvList)
                {
                    outPts.Add(c.StartPoint);
                }
                Autodesk.DesignScript.Geometry.PolyCurve outOffsetPolyCrv2 = PolyCurve.ByPoints(outPts, true);
                Autodesk.DesignScript.Geometry.Surface   outOffsetSrf      = Autodesk.DesignScript.Geometry.Surface.ByPatch(outOffsetPolyCrv2);
                outPerimCrvs = outOffsetSrf.PerimeterCurves();
                outOffsetSrf.Dispose();
                outOffsetPolyCrv.Dispose();
                outOffsetPolyCrv2.Dispose();
            }
            catch (Exception)
            {
                outPerimCrvs = null;
            }


            Dictionary <string, Autodesk.DesignScript.Geometry.Curve[]> newOutput;

            newOutput = new Dictionary <string, Autodesk.DesignScript.Geometry.Curve[]>
            {
                { "insetCrvs", inPerimCrvs },
                { "outsetCrvs", outPerimCrvs }
            };

            //Dispose all redundant geometry

            plyCrv.Dispose();
            foreach (Autodesk.DesignScript.Geometry.Curve c in srfPerimCrvs)
            {
                c.Dispose();
            }

            return(newOutput);
        }
Пример #10
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;
            }
        }
Пример #11
0
        public void ToPDF(iTextSharp.text.pdf.PdfWriter w)
        {
            PdfContentByte cb = w.DirectContent;

            cb.SetLineWidth((float)Settings.Thickness);
            if (Settings.Fill != null)
            {
                cb.SetColorFill(Settings.Fill.ToPDFColor());
            }

            if (Settings.Stroke != null)
            {
                cb.SetColorStroke(Settings.Stroke.ToPDFColor());
            }

            if (Geometry.GetType() == typeof(Dyn.Arc))
            {
                Dyn.Arc arc = Geometry as Dyn.Arc;
                cb.MoveTo(arc.StartPoint.X, arc.EndPoint.Y);
                cb.CurveTo(arc.PointAtParameter(0.5).X, arc.PointAtParameter(0.5).Y, arc.EndPoint.X, arc.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Line))
            {
                Dyn.Line line = Geometry as Dyn.Line;
                cb.MoveTo(line.StartPoint.X, line.StartPoint.Y);
                cb.LineTo(line.EndPoint.X, line.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Circle))
            {
                Dyn.Circle circle = Geometry as Dyn.Circle;
                cb.Circle(circle.CenterPoint.X, circle.CenterPoint.Y, circle.Radius);
            }
            else if (Geometry.GetType() == typeof(Dyn.Ellipse))
            {
                Dyn.Ellipse ellipse = Geometry as Dyn.Ellipse;
                cb.Ellipse(ellipse.StartPoint.X, ellipse.StartPoint.Y, ellipse.EndPoint.X, ellipse.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Rectangle))
            {
                Dyn.Rectangle rect = Geometry as Dyn.Rectangle;
                cb.Rectangle(rect.Center().X, rect.Center().Y, rect.Width, rect.Height);
            }
            else if (Geometry.GetType() == typeof(Dyn.Polygon))
            {
                Dyn.Polygon p = Geometry as Dyn.Polygon;
                foreach (var curve in p.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.PolyCurve))
            {
                Dyn.PolyCurve pc = Geometry as Dyn.PolyCurve;
                foreach (var curve in pc.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.NurbsCurve))
            {
                Dyn.NurbsCurve nc = Geometry as Dyn.NurbsCurve;

                foreach (var linearc in nc.ApproximateWithArcAndLineSegments())
                {
                    CurveToPDF(linearc, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.Curve))
            {
                Dyn.Curve curve = Geometry as Dyn.Curve;
                CurveToPDF(curve, cb);
            }
            else
            {
                throw new Exception(Properties.Resources.NotSupported);
            }

            if (Settings.Fill != null && Settings.Stroke != null)
            {
                cb.FillStroke();
            }
            else
            {
                if (Settings.Stroke != null)
                {
                    cb.Stroke();
                }
                if (Settings.Fill != null)
                {
                    cb.Fill();
                }
            }
        }