Example #1
0
        public bool PasteAllSurfaces(Autodesk.Civil.DatabaseServices.Surface sHole)
        {
            ObjectId objectId = ObjectId.Null;

            try
            {
                foreach (KeyValuePair <ObjectId, string> id in m_polylinesurfaces)
                {
                    objectId = id.Key;
                    try
                    {
                        TestPasteSurface(sHole, CivilTinSurface.FindSurfaceBySurfaceId(objectId));
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
                return(true);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e);
            }
            return(false);
        }
Example #2
0
        private void showGeneralProperties(CivilSurface surface)
        {
            _editor.WriteMessage("\nSurface name: " + surface.Name);
            GeneralSurfaceProperties properties =
                surface.GetGeneralProperties();

            _editor.WriteMessage("\n- Max elevation: " +
                                 properties.MaximumElevation);
            _editor.WriteMessage("\n- Min elevation: " +
                                 properties.MinimumElevation);
        }
Example #3
0
        public static string FindSurfaceNameById(ObjectId surfaceId)
        {
            CivilDocument doc = CivilApplicationManager.ActiveCivilDocument;

            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                C3DLandDb.Surface surface = surfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.Surface;

                return(surface.Name);
            }
        }
        public FeatureLine GetFeatureLine(ObjectId curve, CivSurface targetSurface)
        {
            Database    acCurDb = _hostDocument.Database;
            Transaction acTrans = acCurDb.TransactionManager.TopTransaction;

            ObjectId    perimId = FeatureLine.Create(Guid.NewGuid().ToString(), curve);
            FeatureLine perim   = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;

            perim.AssignElevationsFromSurface(targetSurface.Id, true);

            return(perim);
        }
        private CivilSurface getSurface()
        {
            ObjectId surfaceId = promptForSurface();

            if (surfaceId.IsNull)
            {
                return(null);
            }
            CivilSurface surface = surfaceId.GetObject(OpenMode.ForRead)
                                   as CivilSurface;

            return(surface);
        }
        // TODO: Revoew this method

        /*private SurfaceProperties? ExtractSurfaceInformation(CivSurface targetSurface)
         * {
         *  Document acDoc = Application.DocumentManager.MdiActiveDocument;
         *  Database acCurDb = acDoc.Database;
         *  Transaction acTrans = acCurDb.TransactionManager.TopTransaction;
         *  Polyline boundary = (Polyline) acTrans.GetObject(this.BaseObject, OpenMode.ForRead);
         *
         *  Point2dCollection points = new Point2dCollection();
         *  for (int i = 0, size = boundary.NumberOfVertices; i < size; i++)
         *      points.Add(boundary.GetPoint2dAt(i));
         *
         *  SurfaceProperties result = new SurfaceProperties();
         *
         *  using (Database destDb = new Database(true, true))
         *  {
         *      using (Transaction transDest = destDb.TransactionManager.StartTransaction())
         *      {
         *
         *          Database db = Application.DocumentManager.MdiActiveDocument.Database;
         *          HostApplicationServices.WorkingDatabase = destDb;
         *
         *          // TODO: Review if exception handling is the answer
         *          ObjectId newSurfaceId;
         *          try
         *          {
         *              // This errors out when surface has ben copied
         *              newSurfaceId = TinSurface.CreateByCropping(destDb, "Surface<[Next Counter(CP)]>",
         *                  targetSurface.ObjectId, points);
         *
         *              TinSurface newSurface = transDest.GetObject(newSurfaceId, OpenMode.ForRead) as TinSurface;
         *              GeneralSurfaceProperties genProps = newSurface.GetGeneralProperties();
         *              result.MaxElevation = genProps.MaximumElevation;
         *              result.MinElevation = genProps.MinimumElevation;
         *          }
         *          catch (SurfaceException e)
         *          {
         *              return null;
         *          }
         *          finally
         *          {
         *              HostApplicationServices.WorkingDatabase = db;
         *          }
         *      }
         *  }
         *
         *  return result;
         * }*/

        public FeatureLine GetPerim(CivSurface targetSurface)
        {
            Document    acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database    acCurDb = acDoc.Database;
            Transaction acTrans = acCurDb.TransactionManager.TopTransaction;
            //Polyline boundary = (Polyline) acTrans.GetObject(this.BaseObject, OpenMode.ForRead);

            ObjectId    perimId = FeatureLine.Create(Guid.NewGuid().ToString(), this.BaseObject);
            FeatureLine perim   = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;

            perim.AssignElevationsFromSurface(targetSurface.Id, true);

            return(perim);
        }
Example #7
0
        private Autodesk.Civil.DatabaseServices.Surface EGSurface()
        {
            ObjectIdCollection SurfaceIds = civDoc.GetSurfaceIds();

            foreach (ObjectId surfaceId in SurfaceIds)
            {
                Autodesk.Civil.DatabaseServices.Surface CivSurface = surfaceId.GetObject(OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Surface;
                if (CivSurface.Name == "EG")
                {
                    return(CivSurface);
                }
            }

            return(null);
        }
Example #8
0
        private bool elevationInSurfaceRange(double elevation,
                                             CivilSurface surface)
        {
            GeneralSurfaceProperties properties =
                surface.GetGeneralProperties();

            if (elevation < properties.MinimumElevation ||
                elevation > properties.MaximumElevation)
            {
                _editor.WriteMessage(
                    "\nSpecified elevation not in surface range.");
                return(false);
            }
            return(true);
        }
Example #9
0
        public static Profile ByAlignmentAndSurface(Autodesk.AutoCAD.DynamoNodes.Document document, Alignment parentAlignment, Surface parentSurface, string name, Styles.ProfileStyle profileStyle, ProfileLabelSet profileLabelSet)
        {
            Autodesk.Civil.DatabaseServices.Profile newProfile = null;
            AcadApp.Document curDoc = document.AcDocument;
            Database         db     = curDoc.Database;

            Autodesk.Civil.DatabaseServices.Surface civilSurface = (Autodesk.Civil.DatabaseServices.Surface)parentSurface.InternalDBObject;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                string oName = name;
                // need to assign these values based on the string inputs
                LayerTable lyrTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);
                //ObjectId layerId = Utilities.GetLayerByName(db, layer.Name); // id of layer to add profile to
                // get the layer name defined in the settings
                ObjectId           layerId       = Utilities.GetLayerByName(db, CivilDynamoTools.Settings.Settings.GetLayerName(document, Autodesk.Civil.Settings.SettingsObjectLayerType.Profile, name));
                ObjectId           styleId       = profileStyle.InternalObjectId;    // id of style to assign the profile
                ObjectId           labelSetId    = profileLabelSet.InternalObjectId; // id of label set to assign
                CivilDocument      civilDocument = Autodesk.Civil.ApplicationServices.CivilDocument.GetCivilDocument(document.AcDocument.Database);
                ObjectIdCollection alignIds      = civilDocument.GetAlignmentIds();
                // make sure the name doesn't already exist for any profile
                int copy = 1;
                foreach (ObjectId aId in alignIds)
                {
                    Autodesk.Civil.DatabaseServices.Alignment civilAlignment = (Autodesk.Civil.DatabaseServices.Alignment)trans.GetObject(aId, OpenMode.ForRead);
                    ObjectIdCollection profIds = civilAlignment.GetProfileIds();
                    foreach (ObjectId pId in profIds)
                    {
                        Autodesk.Civil.DatabaseServices.Profile civilProfile = (Autodesk.Civil.DatabaseServices.Profile)trans.GetObject(pId, OpenMode.ForRead);
                        if (civilProfile.Name == name)
                        {
                            name  = oName + " - " + copy;
                            copy += 1;
                        }
                    }
                }
                ObjectId newProfileId = Autodesk.Civil.DatabaseServices.Profile.CreateFromSurface(name, parentAlignment.InternalObjectId, parentSurface.InternalObjectId, layerId, styleId, labelSetId);
                newProfile = (Autodesk.Civil.DatabaseServices.Profile)trans.GetObject(newProfileId, OpenMode.ForRead);
                trans.Commit();
            }
            if (newProfile == null)
            {
                return(null);
            }
            else
            {
                return(new Profile(newProfile, true));
            }
        }
        public bool EstimateFoundationLevel(CivSurface existing, CivSurface proposed, SoilProperties properties)
        {
            if (!SetFoundationInputs(existing, proposed, properties))
            {
                return(false);
            }

            _depth.Run();
            if (_depth.Calculated)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #11
0
        private static void extractContours(Surface surf)
        {
            if (surf is TinSurface)
            {
                if (surf.IsReferenceObject)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Surface {0} is from {1}", surf.Name, surf.OwnerId.ToString()));
                    return;
                }
                TinSurface   tinSurf  = (TinSurface)surf;
                string       nameSurf = tinSurf.Name;
                ObjectId     idStyle  = tinSurf.StyleId;
                SurfaceStyle style    = Surf_Styles.getSurfaceStyle(idStyle);

                double majorInt = style.ContourStyle.MajorContourInterval;
                double minorInt = style.ContourStyle.MinorContourInterval;

                DisplayStyle planDispStyle = style.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour);
                string       majorLay      = planDispStyle.Layer;

                planDispStyle = style.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour);
                string minorLay = planDispStyle.Layer;

                ObjectIdCollection idsContours = tinSurf.ExtractContours(minorInt);

                Color color = new Color();
                color = Color.FromColorIndex(ColorMethod.ByLayer, 256);

                using (Transaction tr = BaseObjs.startTransactionDb()) {
                    foreach (ObjectId id in idsContours)
                    {
                        Polyline poly = (Polyline)tr.GetObject(id, OpenMode.ForRead);
                        double   elev = System.Math.Round(poly.Elevation, 2);
                        if ((elev / majorInt).mantissa() == 0)
                        {
                            id.changeProp(color, majorLay, LineWeight.LineWeight030);
                        }
                        else
                        {
                            id.changeProp(color, minorLay, LineWeight.LineWeight020);
                        }
                    }
                    tr.Commit();
                }
            }
        }
Example #12
0
        public void TestPasteSurface(Autodesk.Civil.DatabaseServices.Surface srcSurface, Autodesk.Civil.DatabaseServices.TinSurface destSurface)
        {
            if (srcSurface == null)
            {
                throw new ArgumentNullException("srcSurface");
            }
            if (destSurface == null)
            {
                throw new ArgumentNullException("destSurface");
            }

            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                destSurface.PasteSurface(srcSurface.Id);
                tr.Commit();
            }
        }
        public static IEnumerable <Polyline3d> GetBoundariesDefinitions(this CivilSurface surface)
        {
            List <Polyline3d> res = new List <Polyline3d>();

            if (surface.BoundariesDefinition.Count == 0)
            {
                return(res);
            }

            for (int i = 0; i < surface.BoundariesDefinition.Count; i++)
            {
                SurfaceBoundary   sboundary = surface.BoundariesDefinition[i][0];
                Point3dCollection points    = sboundary.Vertices;
                Polyline3d        pline     = new Polyline3d(Poly3dType.SimplePoly, points, true);
                res.Add(pline);
            }
            return(res);
        }
Example #14
0
        public ObjectId findSurface(string surfaceName)
        {
            CivilDocument doc = CivilApplicationManager.ActiveCivilDocument;

            using (Transaction tr = CivilApplicationManager.StartTransaction())
            {
                foreach (ObjectId surfaceId in doc.GetSurfaceIds())
                {
                    C3DLandDb.Surface surface = surfaceId.GetObject(OpenMode.ForRead) as C3DLandDb.Surface;
                    if (surface.Name == surfaceName)
                    {
                        return(surfaceId);
                    }
                }
            }

            return(ObjectId.Null);
        }
Example #15
0
        CreateElevationRegions(Surface surface, int steps, short[] colors)
        {
            GeneralSurfaceProperties props = surface.GetGeneralProperties();
            double minElevation            = props.MinimumElevation;
            double maxElevation            = props.MaximumElevation;
            double increment = (maxElevation - minElevation) / steps;

            SurfaceAnalysisElevationData[] newData = new SurfaceAnalysisElevationData[steps];

            for (int i = 0; i < steps; i++)
            {
                Color color = Color.FromColorIndex(ColorMethod.ByLayer, colors[i]);
                newData[i] = new SurfaceAnalysisElevationData(
                    minElevation + (increment * i),
                    minElevation + (increment * (i + 1)),
                    color);
            }
            return(newData);
        }
        private bool SetFoundationInputs(CivSurface existing, CivSurface proposed, SoilProperties properties)
        {
            /*SurfaceProperties? existingProps = ExtractSurfaceInformation(existing);
             * if (existingProps.HasValue)
             * {
             *  _depth.ExistingGroundLevel = existingProps.Value.MinElevation;
             * }
             * else
             * {
             *  return false;
             * }*/
            FeatureLine existingLine = GetPerim(existing);

            _depth.ExistingGroundLevel = existingLine.MinElevation;

            if (proposed != null)
            {
                /*SurfaceProperties? proposedProps = ExtractSurfaceInformation(proposed);
                 * if (proposedProps.HasValue)
                 * {
                 *  _depth.ProposedGroundLevel = proposedProps.Value.MinElevation;
                 * }*/
                FeatureLine proposedLine = GetPerim(proposed);
                _depth.ProposedGroundLevel = proposedLine.MinElevation;
            }

            switch (properties.SoilShrinkability)
            {
            case Shrinkage.High:
                _depth.SoilPlasticity = VolumeChangePotential.High;
                break;

            case Shrinkage.Medium:
                _depth.SoilPlasticity = VolumeChangePotential.Medium;
                break;

            case Shrinkage.Low:
                _depth.SoilPlasticity = VolumeChangePotential.Low;
                break;
            }

            return(true);
        }
        private void GetSurfaces()
        {
            //Get the target surface
            ObjectIdCollection SurfaceIds = CivilApplication.ActiveDocument.GetSurfaceIds();

            foreach (ObjectId surfaceId in SurfaceIds)
            {
                // Direct cast is safe as collection is filtered down to surfaces by Autocad
                CivSurface temp = (CivSurface)surfaceId.GetObject(OpenMode.ForRead);

                // Continue is not used, incase user has set the same surface as both
                if (temp.Name == SoilProperties.ProposedGroundSurfaceName)
                {
                    ProposedGround = temp;
                }
                if (temp.Name == SoilProperties.ExistingGroundSurfaceName)
                {
                    ExistingGround = temp;
                }
            }
        }
Example #18
0
        RBA()
        {
            Surface surface = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDoc())
                {
                    ObjectIdCollection ids = BaseObjs._civDoc.GetSurfaceIds();
                    if (ids.Count == 0)
                    {
                        return;
                    }
                    foreach (ObjectId id in ids)
                    {
                        try
                        {
                            surface = (Surface)tr.GetObject(id, OpenMode.ForRead);
                            if (surface is TinSurface)
                            {
                                TinSurface tinSurface = (TinSurface)surface;
                                tinSurface.UpgradeOpen();
                                tinSurface.Rebuild();
                                tinSurface.DowngradeOpen();
                            }
                        }
                        catch (System.Exception ex)
                        {
                            BaseObjs.writeDebug(ex.Message + " cmdRB.cs: line: 71");
                        }
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " cmdRB.cs: line: 79");
            }
        }
Example #19
0
        addTinSurface(string nameSurf, out bool exists)
        {
            TinSurface surfTin = null;
            Surface    surf    = null;

            exists = false;
            try
            {
                using (Transaction tr = BaseObjs.startTransactionDoc())
                {
                    ObjectIdCollection ids = BaseObjs._civDoc.GetSurfaceIds();
                    foreach (ObjectId id in ids)
                    {
                        surf = (Surface)tr.GetObject(id, OpenMode.ForRead);
                        if (surf is TinSurface)
                        {
                            surfTin = (TinSurface)surf;
                            if (surfTin.Name == nameSurf)
                            {
                                exists = true;
                                break;
                            }
                        }
                    }
                    if (!exists)
                    {
                        ObjectId idSurf = TinSurface.Create(BaseObjs._db, nameSurf);
                        surfTin       = (TinSurface)tr.GetObject(idSurf, OpenMode.ForWrite);
                        surfTin.Layer = string.Format("{0}-SURFACE", nameSurf);
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 32", ex.Message));
            }
            return(surfTin);
        }
        // TODO: Port of existing code, requires refactoring immininently
        public void EstimateFFLFromSurface(CivSurface proposed)
        {
            Document acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBObject obj = acTrans.GetObject(this.BaseObject, OpenMode.ForWrite);

                //Need to add the temp line to create feature line from it
                BlockTable       acBlkTbl    = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec =
                    acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                ObjectId    perimId = FeatureLine.Create("plot" + PlotId, obj.ObjectId);
                FeatureLine perim   = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;
                perim.AssignElevationsFromSurface(proposed.Id, false);
                var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint);

                // TODO: Move to settings
                double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15;

                // TODO: Move to generation code
                //Ad the FFL Label
                // Create a multiline text object
                using (MText acMText = new MText())
                {
                    Solid3d            Solid = new Solid3d();
                    DBObjectCollection coll  = new DBObjectCollection();
                    coll.Add(obj);
                    Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0);
                    Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0);
                    Solid.Dispose();

                    acMText.Location = centroid;
                    acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3");

                    //acMText.Rotation = Rotation;
                    acMText.Height     = 8;
                    acMText.Attachment = AttachmentPoint.MiddleCenter;

                    acBlkTblRec.AppendEntity(acMText);
                    acTrans.AddNewlyCreatedDBObject(acMText, true);
                }

                // TODO: Move to generation code
                foreach (Point3d p in points)
                {
                    using (MText acMText = new MText())
                    {
                        Point3d insert = new Point3d(p.X, p.Y, 0);
                        acMText.Location = insert;

                        //Number of course
                        int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f)));

                        if (courses > 0)
                        {
                            acMText.Contents   = courses + " Courses";
                            acMText.Height     = 4;
                            acMText.Attachment = AttachmentPoint.TopRight;

                            acBlkTblRec.AppendEntity(acMText);
                            acTrans.AddNewlyCreatedDBObject(acMText, true);
                        }
                    }
                }

                //perim.Erase();
                //obj.Erase();
                acTrans.Commit();
            }
        }
Example #21
0
 private static void deleteSurface(Surface surf)
 {
     Surf.removeSurface(surf.Name);
 }
Example #22
0
        public Corridor IzradaPera(Alignment alig, Profile profi)
        {
            if (alig != null && profi != null)
            {
                Transaction tr  = doc.TransactionManager.StartTransaction();
                string      ime = "Okomito pero " + brojPera.ToString();

                Alignment os   = alig;
                ObjectId  osId = os.ObjectId;

                Profile  niveleta   = profi;
                ObjectId niveletaId = niveleta.ObjectId;

                Assembly tijeloPera   = TijeloPera();
                ObjectId tijeloPeraId = tijeloPera.ObjectId;

                Assembly zerro   = NultiAss();
                ObjectId zerroId = zerro.ObjectId;

                Assembly glavaPera   = GlavaPera();
                ObjectId glavaPeraId = glavaPera.ObjectId;

                Autodesk.Civil.DatabaseServices.Surface targetSurface = EGSurface();
                ObjectId targetSurfaceId = targetSurface.ObjectId;

                ObjectId novoPeroId = civDoc.CorridorCollection.Add(ime, "Niveleta " + ime, osId, niveletaId);
                Corridor novoPero   = tr.GetObject(novoPeroId, OpenMode.ForWrite) as Corridor;

                BaselineRegionCollection blRegColl     = novoPero.Baselines[0].BaselineRegions;
                BaselineRegion           regTijeloPera = blRegColl.Add("Tijelo pera", tijeloPeraId, alig.StartingStation, DuljinaPera);
                BaselineRegion           regGlavaPera  = blRegColl.Add("GlavaPera", glavaPeraId, DuljinaPera, DuljinaPera + Math.PI * SirinaKrune / 2);
                BaselineRegion           reg0          = blRegColl.Add("0", zerroId, regGlavaPera.EndStation, alig.EndingStation);

                // corridor frequency nije otvoren u API dokumentaciji
                // jedini način da malo progustim izradu
                for (int i = 10; i < DuljinaPera; i += 10)
                {
                    regTijeloPera.AddStation(i, "Stacionaza " + i.ToString());
                }

                for (double i = 0.1; i < (Math.PI * SirinaKrune / 2); i += 0.3)
                {
                    regGlavaPera.AddStation(DuljinaPera + i, "Stacionaza " + i.ToString());
                }

                BaselineRegionCollection blRColl = novoPero.Baselines[0].BaselineRegions;
                foreach (BaselineRegion blReg in blRColl)
                {
                    SubassemblyTargetInfoCollection targets = blReg.GetTargets();
                    foreach (SubassemblyTargetInfo target in targets)
                    {
                        if (target.TargetType == SubassemblyLogicalNameType.Surface)
                        {
                            var ids = new ObjectIdCollection();
                            ids.Add(targetSurfaceId);
                            target.TargetIds = ids;
                        }
                    }

                    blReg.SetTargets(targets);
                }

                novoPero.Rebuild();

                tr.Commit();

                return(novoPero);
            }

            else
            {
                ed.WriteMessage($"Na stacionazi {0} nije moguća izgradnja pera", Stacionaza);
                return(null);
            }
        }
Example #23
0
        doLabels()
        {
            Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable("CMDECHO", 0);
            object osMode = SnapMode.getOSnap();

            SnapMode.setOSnap(512);

            ObjectId idSurface = ObjectId.Null;

            using (BaseObjs._acadDoc.LockDocument())
            {
                try
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        ObjectIdCollection ids = BaseObjs._civDoc.GetSurfaceIds();
                        switch (ids.Count)
                        {
                        case 0:
                            Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog("There are Zero surfaces in this drawing.  Exiting....");
                            return;

                        case 1:
                            idSurface = ids[0];
                            break;

                        default:
                            idSurface = getSurface();
                            break;
                        }
                        tr.Abort();
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(string.Format("{0} ContourLabels.cs: line: 58", ex.Message));
                }

                if (!idSurface.IsNull)
                {
                    try
                    {
                        using (Transaction tr = BaseObjs.startTransactionDb())
                        {
                            ObjectId idStyleMajor = Surf_Styles.getSurfaceContourLabelStyleId("Thienes_Major");
                            ObjectId idStyleMinor = Surf_Styles.getSurfaceContourLabelStyleId("Thienes_Minor");

                            PromptPointResult ppr;
                            do
                            {
                                PromptPointOptions ppo = new PromptPointOptions("\nPick contour line.");
                                ppr = BaseObjs._editor.GetPoint(ppo);
                                if (ppr.Status == PromptStatus.OK)
                                {
                                    Point3d pnt3d = ppr.Value;

                                    Surface surf = (Surface)idSurface.GetObject(OpenMode.ForWrite);
                                    double  dir  = surf.FindDirectionAtXY(pnt3d.X, pnt3d.Y);

                                    Point3d pnt3dTar1 = Geom.traverse_pnt3d(pnt3d, dir + System.Math.PI, 0.5);

                                    Point3d           pnt3dTar2 = Geom.traverse_pnt3d(pnt3d, dir, 0.5);
                                    Point2dCollection pnts2d    = new Point2dCollection();

                                    pnts2d.Add(new Point2d(pnt3dTar1.X, pnt3dTar1.Y));
                                    pnts2d.Add(new Point2d(pnt3dTar2.X, pnt3dTar2.Y));

                                    doLabel(idSurface, pnts2d, idStyleMajor, idStyleMinor);
                                    //sclg.Annotative = AnnotativeStates.True;
                                }
                                else
                                {
                                    break;
                                }
                            }while (ppr.Status == PromptStatus.OK);

                            tr.Commit();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        BaseObjs.writeDebug(string.Format("{0} ContourLabels.cs: line: 97", ex.Message));
                    }
                    finally
                    {
                        SnapMode.setOSnap((int)osMode);
                    }
                }
            }
        }
Example #24
0
        public void GetFFLfromSurface()
        {
            Database acCurDb;

            acCurDb = Application.DocumentManager.MdiActiveDocument.Database;

            Transaction acTrans = acCurDb.TransactionManager.TopTransaction;

            BlockReference     newBlockRef   = acTrans.GetObject(BlockRef, OpenMode.ForWrite) as BlockReference;//(BlockReference)BlockRef.GetObject(OpenMode.ForWrite);
            DBObjectCollection explodedBlock = new DBObjectCollection();

            newBlockRef.Explode(explodedBlock);

            ObjectIdCollection SurfaceIds     = CivilApplication.ActiveDocument.GetSurfaceIds();
            CivSurface         proposedGround = null;

            foreach (ObjectId surfaceId in SurfaceIds)
            {
                CivSurface oSurface = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;
                if (oSurface.Name == Civils.Constants.ProposedGroundName)
                {
                    proposedGround = oSurface;
                }
            }

            double maxLevel = double.NegativeInfinity;

            if (proposedGround != null)
            {
                try
                {
                    foreach (WallJoint wj in Joints)
                    {
                        wj.ExternalLevel = Math.Round(proposedGround.FindElevationAtXY(wj.Point.X, wj.Point.Y) * 1000) / 1000;
                        if (wj.ExternalLevel > maxLevel)
                        {
                            maxLevel = wj.ExternalLevel;
                        }
                    }
                }
                catch (PointNotOnEntityException e)
                {
                    maxLevel           = -0.15;
                    this.Status        = PlotStatus.Error;
                    this.StatusMessage = "Plot has points not on proposed ground model";
                }

                if (maxLevel == double.NegativeInfinity)
                {
                    maxLevel           = -0.15;
                    this.Status        = PlotStatus.Error;
                    this.StatusMessage = "Surface elevations not found correctly";
                }
            }
            else
            {
                maxLevel           = -0.15;
                this.Status        = PlotStatus.Error;
                this.StatusMessage = "Proposed Ground model not found";
            }

            this.FinishedFloorLevel = Math.Round(maxLevel * 1000) / 1000 + 0.15;
        }
        public void PlineToPlots()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            PromptSelectionOptions pso = new PromptSelectionOptions();

            pso.SingleOnly = true;
            pso.RejectObjectsOnLockedLayers = true;
            PromptSelectionResult psr = acDoc.Editor.GetSelection(pso);

            if (psr.Status == PromptStatus.OK)
            {
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    CivSurface oSurface = null;

                    //Get the target surface
                    ObjectIdCollection SurfaceIds = CivilApplication.ActiveDocument.GetSurfaceIds();
                    foreach (ObjectId surfaceId in SurfaceIds)
                    {
                        CivSurface temp = surfaceId.GetObject(OpenMode.ForRead) as CivSurface;
                        if (temp.Name == Civils.Constants.ProposedGroundName)
                        {
                            oSurface = temp;
                        }
                    }

                    int plotCount = 0;


                    foreach (SelectedObject so in psr.Value)
                    {
                        try
                        {
                            DBObject obj = acTrans.GetObject(so.ObjectId, OpenMode.ForWrite);

                            if (obj is Curve)
                            {
                                plotCount++;

                                //Polyline acPline = obj as Polyline;

                                //Need to add the temp line to create feature line from it
                                BlockTable       acBlkTbl    = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                                BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                                ObjectId perimId = FeatureLine.Create("plot" + plotCount, obj.ObjectId);

                                FeatureLine perim = acTrans.GetObject(perimId, OpenMode.ForWrite) as FeatureLine;
                                perim.AssignElevationsFromSurface(oSurface.Id, false);
                                var points = perim.GetPoints(Autodesk.Civil.FeatureLinePointType.PIPoint);

                                double FinishedFloorLevel = Math.Ceiling(perim.MaxElevation * 20) / 20 + 0.15;

                                //Ad the FFL Label
                                // Create a multiline text object
                                using (MText acMText = new MText())
                                {
                                    Solid3d            Solid = new Solid3d();
                                    DBObjectCollection coll  = new DBObjectCollection();
                                    coll.Add(obj);
                                    Solid.Extrude(((Region)Region.CreateFromCurves(coll)[0]), 1, 0);
                                    Point3d centroid = new Point3d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y, 0);
                                    Solid.Dispose();

                                    acMText.Location = centroid;
                                    acMText.Contents = "FFL = " + FinishedFloorLevel.ToString("F3");
                                    //acMText.Rotation = Rotation;
                                    acMText.Height     = 8;
                                    acMText.Attachment = AttachmentPoint.MiddleCenter;

                                    acBlkTblRec.AppendEntity(acMText);
                                    acTrans.AddNewlyCreatedDBObject(acMText, true);
                                }

                                foreach (Point3d p in points)
                                {
                                    using (MText acMText = new MText())
                                    {
                                        Point3d insert = new Point3d(p.X, p.Y, 0);
                                        acMText.Location = insert;
                                        //Number of course
                                        int courses = (int)Math.Ceiling((double)(((FinishedFloorLevel - 0.15f - p.Z) / 0.075f)));

                                        if (courses > 0)
                                        {
                                            acMText.Contents   = courses + " Courses";
                                            acMText.Height     = 4;
                                            acMText.Attachment = AttachmentPoint.TopRight;

                                            acBlkTblRec.AppendEntity(acMText);
                                            acTrans.AddNewlyCreatedDBObject(acMText, true);
                                        }
                                    }
                                }

                                //perim.Erase();
                                obj.Erase();
                            }
                            else
                            {
                                acDoc.Editor.WriteMessage("Object is not a polyline\n");
                            }
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception e)
                        {
                            acDoc.Editor.WriteMessage(e.Message + "\n");
                        }
                        catch (System.Exception e)
                        {
                            acDoc.Editor.WriteMessage(e.Message + "\n");
                        }
                    }
                    acTrans.Commit();
                }
            }
        }