Exemple #1
0
        /// <summary>
        /// Create geometry by linearly extruding a closed curve
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="direction"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static Solid ByExtrusion(Autodesk.DesignScript.Geometry.Curve[] closedProfileCurves, Vector direction, double distance)
        {
            if (closedProfileCurves == null)
            {
                throw new ArgumentNullException("closedProfileCurves");
            }

            if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }

            var loop = new Autodesk.Revit.DB.CurveLoop();
            closedProfileCurves.ForEach(x => loop.Append( x.ToRevitType()));

            return new Solid(new List<CurveLoop>() { loop }, direction.ToXyz(), distance);
        }
Exemple #2
0
        private static Autodesk.Revit.DB.Face BuildFaceOnPlaneByCurveExtensions(Autodesk.Revit.DB.Curve crv, Autodesk.Revit.DB.Plane thisPlane)
        {
            Autodesk.Revit.DB.Face face = null;
            // tesselate curve and find uv envelope in projection to the plane
            IList<XYZ> tessCurve = crv.Tessellate();
            var curvePointEnum = tessCurve.GetEnumerator();
            var corner1 = new XYZ();
            var corner2 = new XYZ();
            bool cornersSet = false;
            for (; curvePointEnum.MoveNext(); )
            {
                if (!cornersSet)
                {
                    corner1 = curvePointEnum.Current;
                    corner2 = curvePointEnum.Current;
                    cornersSet = true;
                }
                else
                {
                    for (int coord = 0; coord < 3; coord++)
                    {
                        if (corner1[coord] > curvePointEnum.Current[coord])
                            corner1 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner1[coord],
                                            coord == 1 ? curvePointEnum.Current[coord] : corner1[coord],
                                            coord == 2 ? curvePointEnum.Current[coord] : corner1[coord]);
                        if (corner2[coord] < curvePointEnum.Current[coord])
                            corner2 = new XYZ(coord == 0 ? curvePointEnum.Current[coord] : corner2[coord],
                                           coord == 1 ? curvePointEnum.Current[coord] : corner2[coord],
                                           coord == 2 ? curvePointEnum.Current[coord] : corner2[coord]);
                    }
                }
            }

            double dist1 = thisPlane.Origin.DistanceTo(corner1);
            double dist2 = thisPlane.Origin.DistanceTo(corner2);
            double sizeRect = 2.0 * (dist1 + dist2) + 100.0;

            var cLoop = new Autodesk.Revit.DB.CurveLoop();
            for (int index = 0; index < 4; index++)
            {
                double coord0 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
                double coord1 = (index < 2) ? -sizeRect : sizeRect;
                XYZ pnt0 = thisPlane.Origin + coord0 * thisPlane.XVec + coord1 * thisPlane.YVec;

                double coord3 = (index < 2) ? sizeRect : -sizeRect;
                double coord4 = (index == 0 || index == 3) ? -sizeRect : sizeRect;
                XYZ pnt1 = thisPlane.Origin + coord3 * thisPlane.XVec + coord4 * thisPlane.YVec;
                //Line cLine = DocumentManager.GetInstance().CurrentUIApplication.Application.Create.NewLineBound(pnt0, pnt1);
                var cLine = Autodesk.Revit.DB.Line.CreateBound(pnt0, pnt1);
                cLoop.Append(cLine);
            }
            var listCLoops = new List<Autodesk.Revit.DB.CurveLoop> { cLoop };

            var tempSolid = GeometryCreationUtilities.CreateExtrusionGeometry(listCLoops, thisPlane.Normal, 100.0);

            //find right face

            var facesOfExtrusion = tempSolid.Faces;
            for (int indexFace = 0; indexFace < facesOfExtrusion.Size; indexFace++)
            {
                var faceAtIndex = facesOfExtrusion.get_Item(indexFace);
                if (faceAtIndex is PlanarFace)
                {
                    var pFace = faceAtIndex as Autodesk.Revit.DB.PlanarFace;
                    if (System.Math.Abs(thisPlane.Normal.DotProduct(pFace.Normal)) < 0.99)
                        continue;
                    if (System.Math.Abs(thisPlane.Normal.DotProduct(thisPlane.Origin - pFace.Origin)) > 0.1)
                        continue;
                    face = faceAtIndex;
                    break;
                }
            }
            if (face == null)
                throw new Exception("Curve Face Intersection could not process supplied Plane.");

            return face;
        }
Exemple #3
0
        /// <summary>
        /// Create a box by minimum and maximum points.
        /// </summary>
        /// <returns></returns>
        public static Solid BoxByTwoCorners(Point minimum, Point maximum)
        {
            if ((maximum.Z-minimum.Z)<1e-6)
            {
                throw new ArgumentException("The minimum and maximum points specify a box with zero height.");
            }

            var bottomInput = minimum.ToXyz();
            var topInput = maximum.ToXyz();

            XYZ top, bottom;
            if (bottomInput.Z > topInput.Z)
            {
                top = bottomInput;
                bottom = topInput;
            }
            else
            {
                top = topInput;
                bottom = bottomInput;
            }

            // obtain coordinates of base rectangle
            var p0 = bottom;
            var p1 = p0 + new XYZ(top.X - bottom.X, 0, 0);
            var p2 = p1 + new XYZ(0, top.Y - bottom.Y, 0);
            var p3 = p2 - new XYZ(top.X - bottom.X, 0, 0);

            // form edges of base rect
            var l1 = Autodesk.Revit.DB.Line.CreateBound(p0, p1);
            var l2 = Autodesk.Revit.DB.Line.CreateBound(p1, p2);
            var l3 = Autodesk.Revit.DB.Line.CreateBound(p2, p3);
            var l4 = Autodesk.Revit.DB.Line.CreateBound(p3, p0);

            // form curve loop from lines of base rect
            var cl = new Autodesk.Revit.DB.CurveLoop();
            cl.Append(l1);
            cl.Append(l2);
            cl.Append(l3);
            cl.Append(l4);

            // get height of box
            var height = top.Z - bottom.Z;

            return new Solid(new List<CurveLoop>{ cl },XYZ.BasisZ,height);
        }