Exemple #1
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;
        }
        private void Tesselate(Autodesk.DesignScript.Geometry.Curve curve, ref List<GeometryObject> geoms)
        {
            // use the ASM tesselation of the curve
            var pkg = new RenderPackage();
            curve.Tessellate(pkg, 0.1);

            // get necessary info to enumerate and convert the lines
            var lineCount = pkg.LineStripVertices.Count - 3;
            var verts = pkg.LineStripVertices;

            // we scale the tesselation rather than the curve
            var conv = UnitConverter.DynamoToHostFactor;

            // add the revit Lines to geometry collection
            for (var i = 0; i < lineCount; i += 3)
            {
                var xyz0 = new XYZ(verts[i] * conv, verts[i + 1] * conv, verts[i + 2] * conv);
                var xyz1 = new XYZ(verts[i + 3] * conv, verts[i + 4] * conv, verts[i + 5] * conv);

                geoms.Add(Autodesk.Revit.DB.Line.CreateBound(xyz0, xyz1));
            }
        }
Exemple #3
0
        private static void DrawCurve(Autodesk.Revit.DB.Curve curve, IRenderPackage package)
        {
            var pts = curve.Tessellate().ToList();

            for (int i =0; i < pts.Count-1; i++)
            {
                var pt = pts[i];
                var pt1 = pts[i+1];
                package.PushLineStripVertex(pt.X, pt.Y, pt.Z);
                package.PushLineStripVertex(pt1.X, pt1.Y, pt1.Z);
            }
        }