예제 #1
0
        getTinVolumeSurface(string nameSurf)
        {
            TinVolumeSurface objSurface = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDoc())
                {
                    ObjectIdCollection idsSurface = BaseObjs._civDoc.GetSurfaceIds();

                    foreach (ObjectId idSurface in idsSurface)
                    {
                        Autodesk.Civil.DatabaseServices.Surface surf = (Autodesk.Civil.DatabaseServices.Surface)tr.GetObject(idSurface, OpenMode.ForRead);
                        if (surf is TinVolumeSurface)
                        {
                            Autodesk.Civil.DatabaseServices.TinVolumeSurface objTinSurface = (TinVolumeSurface)surf;
                            if (objTinSurface.Name == nameSurf)
                            {
                                objSurface = objTinSurface;
                            }
                        }
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 189", ex.Message));
            }
            return(objSurface);
        }
        public static Polyline3d ExtractBorders(this Autodesk.Civil.DatabaseServices.TinVolumeSurface surface)
        {
            var defBoundaries = surface.GetBoundariesDefinitions();

            if (defBoundaries.Count() > 0)
            {
                return(defBoundaries.Last());
            }
            else
            {
                bool displayBoundariesChanged = false;
                Autodesk.Civil.DatabaseServices.Styles.SurfaceStyle style = surface.StyleId.GetObjectForRead <Autodesk.Civil.DatabaseServices.Styles.SurfaceStyle>();
                var displayStyle = style.GetDisplayStylePlan(Autodesk.Civil.DatabaseServices.Styles.SurfaceDisplayStyleType.Boundary);
                if (!displayStyle.Visible)
                {
                    style.UpgradeOpen();
                    displayStyle.Visible = true;
                    style.DowngradeOpen();
                    displayBoundariesChanged = true;
                }

                Polyline3d         res    = null;
                DBObjectCollection dbcoll = new DBObjectCollection();
                surface.Explode(dbcoll);
                foreach (var dbobj in dbcoll)
                {
                    if (dbobj is BlockReference)
                    {
                        dbcoll.Clear();
                        ((BlockReference)dbobj).Explode(dbcoll);
                        List <Polyline3d> lines = new List <Polyline3d>();
                        foreach (var ent in dbcoll)
                        {
                            if (ent is Polyline3d)
                            {
                                Polyline3d pline = ent as Polyline3d;
                                if (pline.Closed)
                                {
                                    lines.Add(pline);
                                }
                            }
                        }



                        //lines.Sort((l1, l2) => Comparer<double>.Default.Compare(l1.Area, l2.Area));
                        res = lines.LastOrDefault();
                        break;
                    }
                }

                if (displayBoundariesChanged)
                {
                    style.UpgradeOpen();
                    displayStyle.Visible = false;
                    style.DowngradeOpen();
                }

                return(res);
            }
        }