IList <CurveLoop> GetCurveLoops(Document doc, Reference rf)
        {
            IList <CurveLoop> curveloop      = new List <CurveLoop>();
            GeometryObject    geometryObject = doc.GetElement(rf).GetGeometryObjectFromReference(rf);

            try
            {
                PlanarFace planarFace = geometryObject as PlanarFace;
                curveloop = planarFace.GetEdgesAsCurveLoops();
            }
            catch
            {
                HermiteFace hermiteFace = geometryObject as HermiteFace;
                if (hermiteFace == null)
                {
                    RuledFace ruledFace = geometryObject as RuledFace;
                    curveloop = ruledFace.GetEdgesAsCurveLoops();
                }
                else
                {
                    curveloop = hermiteFace.GetEdgesAsCurveLoops();
                }
            }
            return(curveloop);
        }
Ejemplo n.º 2
0
        Stream(ArrayList data, Face face)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(Face)));

            data.Add(new Snoop.Data.Double("Area", face.Area));
            ///TODO: Restore: data.Add(new Snoop.Data.Object("Material element", face.MaterialElement));
            data.Add(new Snoop.Data.Bool("Is two-sided", face.IsTwoSided));
            data.Add(new Snoop.Data.Enumerable("Edge loops", face.EdgeLoops));
            data.Add(new Snoop.Data.Object("Triangulate", face.Triangulate()));
            data.Add(new Snoop.Data.Object("Reference", face.Reference));

            ConicalFace conicalFace = face as ConicalFace;

            if (conicalFace != null)
            {
                Stream(data, conicalFace);
                return;
            }

            CylindricalFace cylFace = face as CylindricalFace;

            if (cylFace != null)
            {
                Stream(data, cylFace);
                return;
            }

            HermiteFace hermiteFace = face as HermiteFace;

            if (hermiteFace != null)
            {
                Stream(data, hermiteFace);
                return;
            }

            PlanarFace planarFace = face as PlanarFace;

            if (planarFace != null)
            {
                Stream(data, planarFace);
                return;
            }

            RevolvedFace revlFace = face as RevolvedFace;

            if (revlFace != null)
            {
                Stream(data, revlFace);
                return;
            }

            RuledFace ruledFace = face as RuledFace;

            if (ruledFace != null)
            {
                Stream(data, ruledFace);
                return;
            }
        }
Ejemplo n.º 3
0
        private void SolidProcess(Solid geomSolid, UIDocument doc, Material materialElement)
        {
            try
            {
                int icount = 0;
                fr_Progress.SetProBarFace(geomSolid.Faces.Size);
                foreach (Face geomFace in geomSolid.Faces)
                {
                    fr_Progress.AddValueProBarFace(++icount);
                    RevolvedFace revolvedFace = geomFace as RevolvedFace;
                    if (null != revolvedFace)
                    {
                    }
                    ConicalFace conicalFace = geomFace as ConicalFace;
                    if (null != conicalFace)
                    {
                    }
                    CylindricalFace cylindricalFace = geomFace as CylindricalFace;
                    if (null != cylindricalFace)
                    {
                    }
                    HermiteFace hermiteFace = geomFace as HermiteFace;
                    if (null != hermiteFace)
                    {
                    }
                    RuledFace ruledFace = geomFace as RuledFace;
                    if (null != ruledFace)
                    {
                    }
                    if (null != geomFace.Reference)
                    {
                    }
                    Material materialElementNew = materialElement;
                    if (null != geomFace.MaterialElement)
                    {
                        materialElementNew = geomFace.MaterialElement as Material;
                    }
                    Mesh geomMesh = geomFace.Triangulate();
                    AddFaceMaterial(materialElementNew, doc);
                    MeshProcess(geomMesh);

                    TextureCoord(geomFace);
                }
            }
            catch (Exception e)
            {
                string message;
                // Exception rised, report it by revit error reporting mechanism.
                message = "SolidProcess fails for Reason:" + Environment.NewLine;
                File.AppendAllText(@"C:\CadFaster\Revit\ExeWriter_log.txt", message);
                message = e.ToString();
                //File.AppendAllText(@"C:\CadFaster\Revit\ExeWriter_log.txt", message);
                //return Autodesk.Revit.UI.Result.Failed;
            }
            //End of SolidProcess
        }
        private static Autodesk.DesignScript.Geometry.Point getAveragePointFromFace(Autodesk.Revit.DB.Face f)
        {
            //the point to return
            Autodesk.DesignScript.Geometry.Point p = null;

            //if face is a ruled face
            RuledFace rf = f as RuledFace;

            if (rf != null)
            {
                //units seem to be messed up...  convert to a designscript mesh first, then pull from that
                Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(rf.Triangulate());
                var points = m.VertexPositions;


                int    numVertices = points.Count();
                double x = 0, y = 0, z = 0;
                foreach (var v in points)
                {
                    x = x + v.X;
                    y = y + v.Y;
                    z = z + v.Z;
                }
                x = x / numVertices;
                y = y / numVertices;
                z = z / numVertices;
                p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z);
            }
            else // if it isn't a ruled face, treat it as planar
            {
                PlanarFace pf = f as PlanarFace;
                if (pf != null)
                {
                    //units seem to be messed up...  convert to a designscript mesh first, then pull from that
                    Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(pf.Triangulate());
                    var points = m.VertexPositions;


                    int    numVertices = points.Count();
                    double x = 0, y = 0, z = 0;
                    foreach (var v in points)
                    {
                        x = x + v.X;
                        y = y + v.Y;
                        z = z + v.Z;
                    }
                    x = x / numVertices;
                    y = y / numVertices;
                    z = z / numVertices;
                    p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z);
                }
            }
            return(p);
        }
        /// <summary>
        /// returns the average height of a face by averaging it's points' v values (for ruled faces - origin is returned fro planar faces.
        /// </summary>
        /// <param name="f">the face</param>
        /// <returns>average height of the face, or it's origin height</returns>
        private static double GetAverageFaceHeight(Autodesk.Revit.DB.Face f)
        {
            double d = 0.0;

            //if face is a ruled face, average the z value of it's mesh vertices
            RuledFace rf = f as RuledFace;

            if (rf != null)
            {
                double total = 0.0;
                int    i     = 1;
                foreach (XYZ v in rf.Triangulate().Vertices)
                {
                    total = total + v.Z;
                    i++;
                }

                //return the average
                d = total / (double)i;
            }
            else // if it isn't a ruled face, treat it as planar and return the origin
            {
                PlanarFace pf = f as PlanarFace;
                if (pf != null)
                {
                    double total = 0.0;
                    int    i     = 1;
                    foreach (XYZ v in pf.Triangulate().Vertices)
                    {
                        total = total + v.Z;
                        i++;
                    }

                    //return the average
                    d = total / (double)i;
                }
            }

            return(d);
        }
Ejemplo n.º 6
0
 Stream(RuledFace face)
 {
     StreamFaceGeoometry(face);
 }
Ejemplo n.º 7
0
        private void Stream(ArrayList data, RuledFace face)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(RuledFace)));

            // TBD: get_Curve(int), get_Point(int) ???
        }
Ejemplo n.º 8
0
        private void DataProcess(Solid geomSolid, GeometryInstance instance)
        {
            try
            {
                uint ufaces    = 0;
                uint uVertices = 0;
                uint uPoints   = 0;
                uint iStartId  = (uint)d_VerticesList.Count;
                foreach (Face geomFace in geomSolid.Faces)
                {
                    iStartId = (uint)d_VerticesList.Count;
                    bool bNewFace = true;
                    ufaces++;
                    Mesh mesh = geomFace.Triangulate();
                    foreach (XYZ ii in mesh.Vertices)
                    {
                        uVertices++;

                        XYZ point = ii;
                        if (null != instance)
                        {
                            Transform instTransform    = instance.Transform;
                            XYZ       transformedPoint = instTransform.OfPoint(point);
                        }
                    }
                    uint iNextId = 0;
                    for (int i = 0; i < mesh.NumTriangles; i++)
                    {
                        MeshTriangle triangle = mesh.get_Triangle(i);
                        XYZ          vertex   = triangle.get_Vertex(0);
                        if (bNewFace)
                        {
                            iNextId  = iStartId / 3;
                            bNewFace = false;
                        }

                        u_IndicesList.Add(3);
                        AddVertex(iStartId, vertex, iNextId++);
                        vertex = triangle.get_Vertex(1);
                        AddVertex(iStartId, vertex, iNextId++);
                        vertex = triangle.get_Vertex(2);
                        AddVertex(iStartId, vertex, iNextId++);
                    }
                    XYZ        origin     = new XYZ(0, 0, 0);
                    XYZ        normal     = new XYZ(0, 0, 0);
                    XYZ        vector     = new XYZ(0, 0, 0);
                    PlanarFace planarFace = geomFace as PlanarFace;
                    if (null != planarFace)
                    {
                        origin = planarFace.Origin;
                        normal = planarFace.Normal;
                        vector = planarFace.get_Vector(0);
                    }
                    ConicalFace ConFace = geomFace as ConicalFace;
                    if (null != ConFace)
                    {
                        origin = ConFace.Origin;
                        normal = ConFace.Axis;
                        vector = ConFace.get_Radius(0);
                    }

                    HermiteFace HermiteFace = geomFace as HermiteFace;
                    if (null != HermiteFace)
                    {
                        origin = new XYZ(0, 0, 0); //HermiteFace.Points;
                        normal = new XYZ(0, 0, 0); //HermiteFace.TaAxis;
                        vector = new XYZ(0, 0, 0); //HermiteFace.get_Tangents(0);
                    }
                    RevolvedFace RevolFace = geomFace as RevolvedFace;
                    if (null != RevolFace)
                    {
                        origin = RevolFace.Origin;
                        normal = RevolFace.Axis;
                        vector = RevolFace.get_Radius(0);
                    }
                    RuledFace RulFace = geomFace as RuledFace;
                    if (null != RulFace)
                    {
                        origin = new XYZ(0, 0, 0);  // RulFace.get_Point;
                        normal = new XYZ(0, 0, 0);  ///RulFace.Axis;
                        vector = RulFace.get_Point(0);
                    }
                    CylindricalFace CylinFace = geomFace as CylindricalFace;
                    if (null != CylinFace)
                    {
                        origin = CylinFace.Origin;
                        normal = CylinFace.Axis;
                        vector = CylinFace.get_Radius(0);
                    }
                    uint featuresCount = 0;
                    for (int s = d_NormalsList.Count; s < d_VerticesList.Count; s += 3)
                    {
                        d_NormalsList.Add(normal.X);
                        d_NormalsList.Add(normal.Y);
                        d_NormalsList.Add(normal.Z);
                        d_TextureCoordsList.Add(normal.X);
                        d_TextureCoordsList.Add(normal.Y);
                        d_TextureCoordsList.Add(normal.Z);
                        featuresCount++;
                    }
                    u_FeaturesIndList.Add(featuresCount);
                }

                foreach (Edge edge in geomSolid.Edges)
                {
                    foreach (XYZ ii in edge.Tessellate())
                    {
                        uPoints++;
                        XYZ point = ii;
                        if (null != instance)
                        {
                            Transform instTransform    = instance.Transform;
                            XYZ       transformedPoint = instTransform.OfPoint(point);
                        }
                    }
                }//foreach (Face geomFace in geomSolid.Faces)
                 //string Osa = element.Name.ToString() + element.Id.ToString();
            }
            catch (Exception e)
            {
                string message;
                // Exception rised, report it by revit error reporting mechanism.
                message = e.ToString();
                File.AppendAllText(@"C:\CadFaster\Revit\ExeWriter_log.txt", message);
                //return Autodesk.Revit.UI.Result.Failed;
            }
            //End of DataProcess
        }
Ejemplo n.º 9
0
 public virtual void Stream(RuledFace face)
 {
     StreamFaceGeoometry(face);
 }
Ejemplo n.º 10
0
        Stream(ArrayList data, RuledFace face)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(RuledFace)));

            // TBD: get_Curve(int), get_Point(int) ???
        }
Ejemplo n.º 11
0
 Stream(RuledFace face)
 {
     StreamFaceGeoometry(face);
 }
Ejemplo n.º 12
0
 public Surface FaceToSpeckle(RuledFace ruledFace, double tolerance)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 轮廓嵌套分层
        /// </summary>
        /// <param name="levelFloor"></param>
        /// <returns></returns>
        public LevelOutLines GetLeveledOutLines(LevelFloor levelFloor)
        {
            var leveledOutLines = new LevelOutLines();
            var option          = new Options()
            {
                View = Document.ActiveView
            };
            var geometry         = levelFloor.Floor.get_Geometry(option);
            var geometryElements = geometry as GeometryElement;

            foreach (Solid geometryElement in geometryElements)
            {
                var         faces    = geometryElement.Faces;
                List <Face> addFaces = new List <Face>();
                foreach (Face face in faces)
                {
                    //矩形面
                    var planarFace = face as PlanarFace;
                    if (planarFace != null)
                    {
                        if (Model.AlignType == AlignType.BeamTopToFloorTop && planarFace.FaceNormal.Z > 0)
                        {
                            addFaces.Add(face);
                        }
                        else if (Model.AlignType == AlignType.BeamTopToFloorBottom && planarFace.FaceNormal.Z < 0)
                        {
                            addFaces.Add(face);
                        }
                    }
                    ////圆面
                    //var cylindricalFace = face as CylindricalFace;
                    //if (cylindricalFace != null)
                    //{
                    //    if (cylindricalFace.Axis.Z > 0)
                    //    {
                    //        addFaces.Add(cylindricalFace);
                    //    }
                    //}
                }
                if (addFaces.Count == 0)
                {
                    double    area        = -1;
                    RuledFace currentFace = null;
                    foreach (Face face in faces)
                    {
                        //定制面
                        var ruledFace = face as RuledFace;
                        if (ruledFace != null)
                        {
                            if (area < ruledFace.Area)
                            {
                                area        = ruledFace.Area;
                                currentFace = ruledFace;
                            }
                        }
                    }
                    if (currentFace != null)
                    {
                        addFaces.Add(currentFace);
                    }
                }
                foreach (var addFace in addFaces.OrderByDescending(c => c.Area))
                {
                    leveledOutLines.Add(addFace, Model);
                }
            }
            return(leveledOutLines);
        }
Ejemplo n.º 14
0
 public virtual void Stream(RuledFace face)
 {
     StreamFaceGeometry(face);
 }