Beispiel #1
0
        public Mesh SurfaceToSpeckle(CivilDB.GridSurface surface)
        {
            Mesh mesh = null;

            // output vars
            var _vertices = new List <Acad.Point3d>();
            var faces     = new List <int>();

            foreach (var cell in surface.GetCells(false))
            {
                // get vertices
                var faceIndices = new List <int>();
                foreach (var vertex in new List <CivilDB.GridSurfaceVertex>()
                {
                    cell.BottomLeftVertex, cell.BottomRightVertex, cell.TopLeftVertex, cell.TopRightVertex
                })
                {
                    if (!_vertices.Contains(vertex.Location))
                    {
                        faceIndices.Add(_vertices.Count);
                        _vertices.Add(vertex.Location);
                    }
                    else
                    {
                        faceIndices.Add(_vertices.IndexOf(vertex.Location));
                    }
                    vertex.Dispose();
                }

                // get face
                faces.AddRange(new List <int> {
                    1, faceIndices[0], faceIndices[1], faceIndices[2], faceIndices[3]
                });

                cell.Dispose();
            }

            var vertices = PointsToFlatList(_vertices);

            mesh       = new Mesh(vertices, faces);
            mesh.units = ModelUnits;
            mesh.bbox  = BoxToSpeckle(surface.GeometricExtents);

            // add grid surface props
            try{
                mesh["name"]        = surface.DisplayName;
                mesh["description"] = surface.Description;
            }
            catch {}

            return(mesh);
        }
Beispiel #2
0
        [CommandMethod("expsurfpts")] //Comanda pentru exportarea intr-un fisier PENZD.csv a punctelor unei suprafete
        public void ExpSurfPts()
        {
            CivilDocument      civDoc  = CivilApplication.ActiveDocument;
            Document           acadDoc = Application.DocumentManager.MdiActiveDocument;
            Database           db      = HostApplicationServices.WorkingDatabase;
            Editor             ed      = acadDoc.Editor;
            ObjectIdCollection surfIds = civDoc.GetSurfaceIds();

            //Verificarea existentei a cel putin unei suprafete
            if (surfIds.Count == 0)
            {
                ed.WriteMessage("\nNo Surfaces found!");
                return;
            }

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //Selectarea suprafetei
                Autodesk.Civil.DatabaseServices.Surface suprafata;
                if (surfIds.Count == 1)
                {
                    suprafata = (Autodesk.Civil.DatabaseServices.Surface)trans.GetObject(surfIds[0], OpenMode.ForRead);
                }
                else
                {
                    PromptEntityOptions PrEntOpt = new PromptEntityOptions("\nSelect Surface: ");
                    PrEntOpt.AllowNone = false;
                    PrEntOpt.SetRejectMessage("\nSelected object is not a Civil3D surface!");
                    PrEntOpt.AddAllowedClass(typeof(Autodesk.Civil.DatabaseServices.Surface), false);
                    PromptEntityResult PrEntRes = ed.GetEntity(PrEntOpt);
                    if (PrEntRes.Status != PromptStatus.OK)
                    {
                        ed.WriteMessage("\nAborting!");
                        return;
                    }
                    suprafata = (Autodesk.Civil.DatabaseServices.Surface)trans.GetObject(PrEntRes.ObjectId, OpenMode.ForRead);
                }

                //Obtinerea punctelor suprafetei
                List <string> puncte = new List <string>();
                int           nr     = 0;
                if (suprafata is Autodesk.Civil.DatabaseServices.TinSurface)
                {
                    Autodesk.Civil.DatabaseServices.TinSurface suprafTIN = (Autodesk.Civil.DatabaseServices.TinSurface)suprafata;
                    //Autodesk.Civil.DatabaseServices.TinSurfaceVertexCollection vertecsiTIN = suprafTIN.Vertices;
                    foreach (Autodesk.Civil.DatabaseServices.TinSurfaceVertex V in suprafTIN.Vertices)
                    {
                        nr = nr + 1;
                        puncte.Add(nr.ToString() + "," + V.Location.ToString().Replace("(", "").Replace(")", "") + "," + suprafata.Name);
                    }
                }
                else if (suprafata is Autodesk.Civil.DatabaseServices.GridSurface)
                {
                    Autodesk.Civil.DatabaseServices.GridSurface suprafGRID = (Autodesk.Civil.DatabaseServices.GridSurface)suprafata;
                    foreach (Autodesk.Civil.DatabaseServices.GridSurfaceVertex V in suprafGRID.Vertices)
                    {
                        nr = nr + 1;
                        puncte.Add(nr.ToString() + "," + V.Location.ToString().Replace("(", "").Replace(")", "") + "," + suprafata.Name);
                    }
                }
                else
                {
                    ed.WriteMessage("\nSurface type not supported! Aborting.");
                    return;
                }

                ////TEST: se listeaza punctele
                //foreach(string p in puncte) ed.WriteMessage(p);

                //Selectia fisierului .csv si scrierea punctelor
                PromptSaveFileOptions PrFileOpt = new PromptSaveFileOptions("\nSelect file for point export: ");
                PrFileOpt.Filter = ("CSV file (*.csv)|*.csv");
                string caleDocAcad = HostApplicationServices.Current.FindFile(acadDoc.Name, acadDoc.Database, FindFileHint.Default);
                //PrFileOpt.InitialDirectory = caleDocAcad.Remove(caleDocAcad.LastIndexOf("\\");
                PrFileOpt.InitialFileName = caleDocAcad.Replace(caleDocAcad.Substring(caleDocAcad.LastIndexOf('.')), ".csv");
                ed.WriteMessage(PrFileOpt.InitialDirectory);

                PromptFileNameResult PrFileRes = ed.GetFileNameForSave(PrFileOpt);
                if (PrFileRes.Status != PromptStatus.OK)
                {
                    ed.WriteMessage("\nPoint export unsuccessful!");
                    return;
                }
                StreamWriter scriitor = new StreamWriter(PrFileRes.StringResult);
                foreach (string p in puncte)
                {
                    scriitor.WriteLine(p);
                }
                scriitor.Dispose();
            }
        }