Example #1
0
        /// <summary>
        /// Gets the rough outline.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <returns>Acaddb.Polyline.</returns>
        private static Acaddb.Polyline GetRoughOutline(Acaddb.ObjectIdCollection collection)
        {
            try
            {
                var theClass = RXObject.GetClass(typeof(Acaddb.Polyline));

                foreach (Acaddb.ObjectId oid in collection)
                {
                    if (!oid.ObjectClass.IsDerivedFrom(theClass))
                    {
                        continue;
                    }

                    var polyline = GetObject(oid);
                    if (polyline == null)
                    {
                        continue;
                    }
                    if (polyline.Layer.Length < 8)
                    {
                        if (polyline.Layer.Equals("ORO") ||
                            polyline.Layer.Contains("ROUGH-OUTLINE"))
                        {
                            return(polyline);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                COMS.MessengerManager.LogException(ex);
            }
            return(null);
        }
Example #2
0
        public static void ExportSurfaceObjects()
        {
            PasteSurfaces surfaceManager = new PasteSurfaces();

            global::Autodesk.AutoCAD.DatabaseServices.Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                ObjectIdCollection surfaces = surfaceManager.GetAllSurfaces();

                foreach (ObjectId surfaceId in surfaces)
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;

                        surface.GetTriangles(true);


                        trans.Commit();
                    }
                }
            }
            catch (Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
        }
Example #3
0
 /// <summary>
 /// Deletes the polys.
 /// </summary>
 /// <param name="oids">The oids.</param>
 /// <exception cref="System.ArgumentNullException">p</exception>
 public static void DeletePolys(Acaddb.ObjectIdCollection oids)
 {
     using (var db = Active.WorkingDatabase)
     {
         foreach (Acaddb.ObjectId objectId in oids)
         {
             try
             {
                 using (var tr = Active.StartTransaction())
                 {
                     var p = tr.GetObject(objectId, Acaddb.OpenMode.ForRead) as Acaddb.Polyline;
                     if (p == null)
                     {
                         throw new ArgumentNullException(nameof(p));
                     }
                     if (p.Layer == "OGR")
                     {
                         continue;
                     }
                     p.UpgradeOpen();
                     p.Erase();
                     tr.Commit();
                 }
             }
             catch (Exception ex)
             {
                 COMS.MessengerManager.LogException(ex);
             }
         }
     }
 }
Example #4
0
        public static void ScaleWaterObject()
        {
            // Get the current document and database

            try
            {
                Document        acDoc   = Application.DocumentManager.MdiActiveDocument;
                Acaddb.Database acCurDb = acDoc.Database;

                var pids         = GetAllPolylines();
                var pidsToDelete = new Acaddb.ObjectIdCollection();

                var offset = -0.001;

                foreach (Acaddb.ObjectId oid in pids)
                {
                    offset = -0.001;

                    using (acDoc.LockDocument())
                    {
                        using (var acTrans = Application.DocumentManager.MdiActiveDocument
                                             .TransactionManager.StartTransaction())
                        {
                            Acaddb.DBObject obj =
                                acTrans.GetObject(oid, Acaddb.OpenMode.ForWrite);

                            Acaddb.Polyline polyline = obj as Acaddb.Polyline;

                            if (polyline != null)
                            {
                                if (polyline.Closed)
                                {
                                    if (polyline.Layer != "OWA")
                                    {
                                        continue;
                                    }
                                    var centroid   = GetCentroidOfOuterBoundary(GetPolylinePoints(oid));
                                    var centroid3d = new Point3d(centroid.X, centroid.Y, 0.0);
                                    var closepnt   = polyline.GetClosestPointTo(centroid3d, true);
                                    var radius     = polyline.GetDistAtPoint(closepnt);
                                    var scaleFac   = 1 + offset / Math.Abs(radius);

                                    polyline.TransformBy(Matrix3d.Scaling(scaleFac,
                                                                          new Point3d(centroid.X, centroid.Y, 0)));
                                }
                            }


                            acTrans.Commit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }
        }
Example #5
0
        public static void SimplifyPolylinesTest()
        {
            // Get the document
            var doc = Application.DocumentManager.MdiActiveDocument;
            IList <Point2dCollection> point2DCollections = new List <Point2dCollection>();
            IList <Point2dCollection> reducedCollection  = new List <Point2dCollection>();
            Point2dCollection         sortedCollection   = new Point2dCollection();
            double tolerance = 0.001;

            try
            {
                //Select Polyline Objects
                ObjectIdCollection collection = GetIdsByTypeTypeValue("POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3D");

                if (collection == null || collection.Count == 0)
                {
                    return;
                }

                using (DocumentLock doclock = doc.LockDocument())
                {
                    //Get Point Collection of Polylines
                    foreach (ObjectId obj in collection)
                    {
                        point2DCollections.Add(GetPoint2dFromPolylines(obj));

                        //Log Original Information
                        GetPolylineName(obj, collection.IndexOf(obj));
                    }

                    foreach (Point2dCollection pnt2DCol in point2DCollections)
                    {
                        int            index = point2DCollections.IndexOf(pnt2DCol);
                        Point2d[]      reducedPoints;
                        List <Point2d> list = new List <Point2d>(pnt2DCol.ToArray());

                        //Reduce Polylines
                        reducedPoints = DouglasPeuckerImplementation.DouglasPeuckerReduction(list, tolerance);
                        reducedCollection.Add(ConvertCollections(reducedPoints));


                        sortedCollection = SortModified(list, ConvertCollections(reducedPoints));
                        // Add Reduced Polylines to Database
                        //CreateNewPolyliness(null, sortedCollection);
                        ModifyPolylineVertices(sortedCollection, collection[index]);
                        //Store Polyline Information

                        //Log Polyline Information
                        GetPolylineName(sortedCollection, point2DCollections.IndexOf(pnt2DCol));
                        index++;
                    }
                }
            }
            catch (System.Exception ex)
            {
                DatabaseLogs.FormatLogs("SimplifyPolylines: " + ex.Message);
            }
        }
        /// <summary>
        /// Adds to pick set.
        /// </summary>
        /// <param name="oids">The oids.</param>
        /// <returns></returns>
        public static bool AddToPickSet(Acaddb.ObjectIdCollection oids)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start AddToPickSet");
            bool retVal = false;

            try
            {
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

                bool isPickSetModified = false;
                Acaddb.ObjectIdCollection pickedOids = new Acaddb.ObjectIdCollection();

                //Access the current PickSet
                PromptSelectionResult resBuf = ed.SelectImplied();
                if (resBuf.Status != PromptStatus.Error)
                {
                    //Load into a selection set object
                    SelectionSet ssPickSet = resBuf.Value;
                    //Get the object ID's
                    pickedOids = new Acaddb.ObjectIdCollection(ssPickSet.GetObjectIds());
                }
                foreach (Acaddb.ObjectId oid in oids)
                {
                    if (!pickedOids.Contains(oid))
                    {
                        //Adding object to pickSet selection
                        pickedOids.Add(oid);
                        isPickSetModified = true;
                    }
                }
                if (isPickSetModified == true)
                {
                    List <Acaddb.ObjectId> pickedOidList = new List <Acaddb.ObjectId>();
                    foreach (Acaddb.ObjectId oid in pickedOids)
                    {
                        pickedOidList.Add(oid);
                    }
                    ed.SetImpliedSelection(pickedOidList.ToArray());
                    retVal = true;
                }
            }
            catch (System.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.AddLog("Error in AddToPickSet", ex);
                throw;
            }
            PGA.MessengerManager.MessengerManager.AddLog("End AddToPickSet");
            return(retVal);
        }
Example #7
0
        /// <summary>
        /// Deletes the old polylines.
        /// </summary>
        /// <param name="collection">The collection.</param>
        private static void DeleteOldPolylines(ObjectIdCollection collection)
        {
            // Get the current document and database
            var acDoc   = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var acCurDb = acDoc.Database;
            var ed      = acDoc.Editor;

            using (acDoc.LockDocument())
            {
                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // Open the Block table for read
                    BlockTable acBlkTbl;
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                 OpenMode.ForRead) as BlockTable;

                    // Open the Block table record Model space for write
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                    OpenMode.ForWrite) as BlockTableRecord;

                    PGA.AcadUtilities.AcadUtilities.DeleteObjects(collection);
                    //foreach (ObjectId selectedObjectId in collection)
                    //{
                    //    var obj = acTrans.GetObject(selectedObjectId, OpenMode.ForWrite);

                    //    var p2d = obj as Polyline2d;

                    //    if (p2d != null && p2d.Color == Color.FromColorIndex(ColorMethod.ByAci, 0))
                    //    {
                    //        p2d.Erase(true);
                    //    }
                    //    else
                    //    {
                    //        var lwp = obj as Polyline;

                    //        if (lwp != null && lwp.Color == Color.FromColorIndex(ColorMethod.ByAci, 0))
                    //        {
                    //            lwp.Erase(true);
                    //        }
                    //    }
                    //}
                    acTrans.Commit();
                }
            }
        }
        /// <summary>
        /// Gets the object ids from previous selection.
        /// </summary>
        /// <returns></returns>
        public static Acaddb.ObjectIdCollection GetObjectIdsFromPreviousSelection()
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start GetObjectIdsFromPreviousSelection");
            SelectionSet selectionSet = null;

            Acaddb.ObjectIdCollection oids = null;

            Editor editor = Active.Editor;
            PromptSelectionResult promptResult;

            promptResult = editor.SelectPrevious();
            if (promptResult.Status == PromptStatus.OK)
            {
                selectionSet = promptResult.Value;
                oids         = new Acaddb.ObjectIdCollection(selectionSet.GetObjectIds());
            }
            PGA.MessengerManager.MessengerManager.AddLog("End GetObjectIdsFromPreviousSelection");
            return(oids);
        }
Example #9
0
        public void RebuildAllSurfaces()
        {
            try
            {
                var polylines =
                    new ObjectIdCollection();
                Dictionary <ObjectId, ObjectIdCollection> m_dict;

                var surfaceManager = new PasteSurfaces();
                m_dict = new Dictionary <ObjectId, ObjectIdCollection>();

                if (CivilTinSurface.FindCivilTinSurface("All"))
                {
                    #region get polylines and generate surfaces and boundaries

                    polylines = surfaceManager.GetAllPolyLines();

                    #endregion

                    ObjectIdCollection internalPLines = null;
                    foreach (ObjectId baseObj in polylines)
                    {
                        #region store the internal boundaries for the selected base object in dict
                        if (GetPolyFromObjId(baseObj) == null)
                        {
                            continue;
                        }

                        internalPLines = surfaceManager.GetAllInternalPolyLinesToSelected(baseObj, polylines);

                        m_dict.Add(baseObj, internalPLines);

                        #endregion
                    }

                    #region Iterate through inner boundaries

                    CivilTinSurface lsurface = null;
                    foreach (KeyValuePair <ObjectId, ObjectIdCollection> innerbdy in m_dict)
                    {
                        #region Removed

                        //#region Create Surface for that Base Polyline and Add outer boundary

                        //if ((lsurface = (surfaceManager.CreateSelectedSurface(baseObj))) == null)
                        //    throw new Exception("CreateSelectedSurface Failed!");

                        //lsurface.AddStandardBoundary(baseObj, "OuterBoundary");
                        //#endregion

                        #endregion

                        if (innerbdy.Value == null)
                        {
                            continue;
                        }

                        ObjectId           outerPline        = innerbdy.Key;
                        ObjectIdCollection innerIdCollection = innerbdy.Value;


                        lsurface = PasteSurfaces.FindSurfaceIdForPolylineV2(outerPline);

                        if (lsurface == null)
                        {
                            continue;
                        }

                        #region Interate Internal Polylines to add breaklines and boundaries

                        if (innerIdCollection != null)
                        {
                            foreach (ObjectId pLines in innerIdCollection)
                            {
                                try
                                {
                                    #region Breaklines Deprecated
                                    //Breaklines removed due to overlapping
                                    //lsurface.AddStandardBreakline
                                    //    (PasteSurfaces.GetPolyPointsByObjectId(pLines), "Breakline-");
                                    #endregion
                                    var layer = PGA.SurfaceManager.SurfaceManager.GetPolylineLayer(pLines);

                                    lsurface.AddStandardInnerBoundary(pLines, "Boundary-" + layer);
                                }
                                catch (NullReferenceException e)
                                {
                                    PGA.MessengerManager.MessengerManager.AddLog("AddAsInnerBoundary Failed: " + e.Message);
                                    //throw new Exception(e.Message);
                                }
                                internalPLines = null;
                            }
                        }

                        #endregion
                        #region Rebuild Surfaces
                        if (lsurface != null)
                        {
                            CivilTinSurface.RebuildSurfaceBySurfaceName(lsurface.Name);
                        }
                        #endregion
                        #region Regenerate Graphics
                        EditorUtils.Regen();
                        #endregion
                    }

                    #endregion


                    internalPLines = null;
                }
                else
                {
                    throw new FileNotFoundException(
                              "Did not find the surface ALL!");
                }

                EditorUtils.Write("\nRebuild Surfaces Complete!\n");
            }
            catch (NullReferenceException e)
            {
                EditorUtils.Write(e.StackTrace);
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
            catch (global::Autodesk.AutoCAD.Runtime.Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
            catch (Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
        }
Example #10
0
        public void CreateSingleSurface()
        {
            try
            {
                Dictionary <ObjectId, ObjectIdCollection> m_dict;
                var surfaceManager = new PasteSurfaces();
                m_dict = new Dictionary <ObjectId, ObjectIdCollection>();
                #region Steps
                //1 Create Overall Surface
                //2 Create new Surface with Defaults
                //3 Open new Surface to Paste Overall Surface
                //4 Select Surface to Paste Overall Surface Into
                //5 Add Boundary to New Surface
                //1 Select All Polylines
                //2 Determine if boundaries are needed to be type inner or outer
                //3 Filter Polylines based on layer name. May be able to know the type.
                #endregion


                if (CivilTinSurface.FindCivilTinSurface("All"))
                {
                    #region Insert Point Cloud into Overall Surface

                    ///TODO///

                    #endregion

                    #region get polylines and generate surfaces and boundaries

                    //Get Selected Polylines
                    Editor ed = Active.Editor;

                    try

                    {
                        PromptSelectionResult selectionRes =

                            ed.SelectImplied();

                        // If there's no pickfirst set available...

                        if (selectionRes.Status == PromptStatus.Error)

                        {
                            // ... ask the user to select entities

                            PromptSelectionOptions selectionOpts =

                                new PromptSelectionOptions();

                            selectionOpts.MessageForAdding =

                                "\nSelect polylines to create a surface: ";

                            selectionRes =

                                ed.GetSelection(selectionOpts);
                        }

                        else

                        {
                            // If there was a pickfirst set, clear it

                            ed.SetImpliedSelection(new ObjectId[0]);
                        }

                        // If the user has not cancelled...

                        if (selectionRes.Status == PromptStatus.OK)

                        {
                            var selectedObjects  = selectionRes.Value.GetObjectIds();
                            var selectedpolyline = new ObjectIdCollection(selectedObjects);
                            var polylines        = surfaceManager.GetIdsByTypeCollection();

                            if (!surfaceManager.CreateSurfaceForPolylines(selectedpolyline))
                            {
                                throw new SystemException("Create surface for polylines failed!");
                            }
                            if (!surfaceManager.PasteAllSurfaces(CivilTinSurface.GetCivilSurfaceBySurfaceName("All")))
                            {
                                throw new SystemException("Pasting Surfaces failed!");
                            }
                            if (!surfaceManager.AddBoundariesForSurfaces(selectedpolyline))
                            {
                                throw new SystemException("Add overall Boundaries for surfaces failed!");
                            }

                            #endregion

                            ObjectIdCollection internalPLines = null;

                            foreach (ObjectId selected in selectedpolyline)
                            {
                                //Create a surface hive to generate a TIN surface
                                //Disabled min poly separation distance in backend 2/3/2018

                                #region store the internal boundaries for the selected base object in dict

                                if (GetPolyFromObjId(selected) == null)
                                {
                                    continue;
                                }

                                internalPLines = surfaceManager.GetAllInternalPolyLinesToSelected(selected, polylines);

                                m_dict.Add(selected, internalPLines);


                                #endregion
                            }

                            #region Iterate through inner boundaries

                            CivilTinSurface lsurface = null;

                            foreach (KeyValuePair <ObjectId, ObjectIdCollection> boundary in m_dict)
                            {
                                #region Removed

                                //#region Create Surface for that Base Polyline and Add outer boundary

                                //if ((lsurface = (surfaceManager.CreateSelectedSurface(baseObj))) == null)
                                //    throw new Exception("CreateSelectedSurface Failed!");

                                //lsurface.AddStandardBoundary(baseObj, "OuterBoundary");
                                //#endregion

                                #endregion

                                lsurface = PasteSurfaces.FindSurfaceIdForPolylineV2(boundary.Key);

                                if (boundary.Value == null)
                                {
                                    continue;
                                }


                                #region Interate Internal Polylines to add breaklines and boundaries

                                if (boundary.Value != null)
                                {
                                    foreach (ObjectId innnerId in boundary.Value)
                                    {
                                        try
                                        {
                                            #region Breaklines Deprecated

                                            //Breaklines removed due to overlapping
                                            //lsurface.AddStandardBreakline
                                            //    (PasteSurfaces.GetPolyPointsByObjectId(pLines), "Breakline-");

                                            #endregion

                                            var currentPoly  = GetPolyFromObjId(innnerId);
                                            var selectedPoly = GetPolyFromObjId(boundary.Key);
                                            if (currentPoly != null && currentPoly.Layer == selectedPoly.Layer)
                                            {
                                                if (lsurface != null)
                                                {
                                                    lsurface.AddStandardInnerBoundary(innnerId, "Boundary-" + currentPoly.Layer);
                                                }
                                            }
                                        }



                                        catch (NullReferenceException e)
                                        {
                                            PGA.MessengerManager.MessengerManager.AddLog(
                                                "AddAsInnerBoundary Failed: " +
                                                e.Message);
                                        }
                                        catch (Exception e)
                                        {
                                            PGA.MessengerManager.MessengerManager.AddLog(
                                                "AddAsInnerBoundary Failed: " +
                                                e.Message);
                                        }
                                    }
                                }
                                internalPLines = null;

                                #endregion
                            }

                            #region Rebuild Surfaces

                            if (lsurface != null)
                            {
                                CivilTinSurface.RebuildSurfaceBySurfaceName(lsurface.Name);
                            }

                            #endregion

                            ed.Regen();
                            #endregion


                            internalPLines = null;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        PGA.MessengerManager.MessengerManager.LogException(ex);
                        return;
                    }
                }
                else
                {
                    throw new FileNotFoundException(
                              "Did not find the surface ALL!");
                }

                EditorUtils.Write("Create Surfaces Complete!");
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.StackTrace);
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
            catch (global::Autodesk.AutoCAD.Runtime.Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
            catch (Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
        }
Example #11
0
        public void CreateAllSurfaces()
        {
            try
            {
                var polylines      = new ObjectIdCollection();
                var surfaceManager = new PasteSurfaces();
                var m_dict         = new Dictionary <ObjectId, ObjectIdCollection>();
                #region Steps
                //1 Create Overall Surface
                //2 Create new Surface with Defaults
                //3 Open new Surface to Paste Overall Surface
                //4 Select Surface to Paste Overall Surface Into
                //5 Add Boundary to New Surface
                //1 Select All Polylines
                //2 Determine if boundaries are needed to be type inner or outer
                //3 Filter Polylines based on layer name. May be able to know the type.
                #endregion


                if (CivilTinSurface.FindCivilTinSurface("All"))
                {
                    #region Insert Point Cloud into Overall Surface


                    #endregion

                    #region get polylines and generate surfaces and boundaries

                    //polylines = surfaceManager.GetAllPolyLines();
                    polylines = GetIdsByTypeTypeValue("POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3D");

                    //polylines  = surfaceManager.GetIdsByTypeCollection();

                    //Create a surface hive to generate a TIN surface
                    if (!surfaceManager.CreateSurfaceForPolylines(polylines))
                    {
                        throw new SystemException("Create surface for polylines failed!");
                    }
                    if (!surfaceManager.PasteAllSurfaces(CivilTinSurface.GetCivilSurfaceBySurfaceName("All")))
                    {
                        throw new SystemException("Pasting Surfaces failed!");
                    }
                    if (!surfaceManager.AddBoundariesForSurfaces(polylines))
                    {
                        throw new SystemException("Add overall Boundaries for surfaces failed!");
                    }

                    #endregion
                    PGA.MessengerManager.MessengerManager.AddLog
                        ("Store boundaries to Object Dictionary");
                    ObjectIdCollection internalPLines = null;
                    foreach (ObjectId baseObj in polylines)
                    {
                        #region store the internal boundaries for the selected base object in dict
                        if (GetPolyFromObjId(baseObj) == null)
                        {
                            continue;
                        }

                        if (IsTINExcluded(baseObj))
                        {
                            continue;
                        }

                        internalPLines = surfaceManager.GetAllInternalPolyLinesToSelected(baseObj, polylines);


                        m_dict.Add(baseObj, internalPLines);


                        #endregion
                    }

                    #region Iterate through inner boundaries
                    PGA.MessengerManager.MessengerManager.AddLog("Start Iterate through inner boundaries");
                    CivilTinSurface lsurface = null;
                    foreach (KeyValuePair <ObjectId, ObjectIdCollection> innerbdy in m_dict)
                    {
                        if (innerbdy.Value == null)
                        {
                            continue;
                        }

                        ObjectId           outerPline        = innerbdy.Key;
                        ObjectIdCollection innerIdCollection = innerbdy.Value;


                        lsurface = PasteSurfaces.FindSurfaceIdForPolylineV2(outerPline);

                        if (lsurface == null)
                        {
                            continue;
                        }

                        lsurface.SetDefaultBuildOptions();

                        #region Interate Internal Polylines to add breaklines and boundaries
                        PGA.MessengerManager.MessengerManager.AddLog("Start AddStandardInnerBoundary");
                        if (innerIdCollection != null)
                        {
                            foreach (ObjectId pLines in innerIdCollection)
                            {
                                if (pLines == null)
                                {
                                    continue;
                                }
                                try
                                {
                                    var layer = PGA.SurfaceManager.SurfaceManager.GetPolylineLayer(pLines);

                                    lsurface.AddStandardInnerBoundary(pLines, "Boundary-" + layer + DateTime.Now.Millisecond);
                                }
                                catch (NullReferenceException e)
                                {
                                    PGA.MessengerManager.MessengerManager.AddLog("AddAsInnerBoundary Failed: " + e.Message);
                                }
                                catch (Exception e)
                                {
                                    PGA.MessengerManager.MessengerManager.AddLog("AddAsInnerBoundary Failed: " + e.Message);
                                }
                                internalPLines = null;
                            }
                        }
                        PGA.MessengerManager.MessengerManager.AddLog("End AddStandardInnerBoundary");

                        #endregion
                        #region Rebuild Surfaces
                        PGA.MessengerManager.MessengerManager.AddLog("Start RebuildSurfaceBySurfaceName");
                        if (lsurface != null)
                        {
                            CivilTinSurface.RebuildSurfaceBySurfaceName(lsurface.Name);
                        }
                        #endregion
                    }

                    #endregion


                    internalPLines = null;
                    PGA.MessengerManager.MessengerManager.AddLog
                        ("End Iterate through inner boundaries");
                }
                else
                {
                    EditorUtils.Write("Missing 'All' Surface. Create Surfaces Incomplete!");
                    throw new FileNotFoundException(
                              "Did not find the surface ALL!");
                }

                EditorUtils.Write("Create Surfaces Complete!\n");
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine(e.StackTrace);
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
            catch (global::Autodesk.AutoCAD.Runtime.Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
            catch (Exception e)
            {
                PGA.MessengerManager.MessengerManager.LogException(e);
            }
        }
Example #12
0
        /// <summary>
        /// Offsets the features by -0.001 ft
        /// </summary>
        /// <param name="name">The name.</param>
        /// <exception cref="System.ArgumentNullException">layer name</exception>
        public static void OffsetFeatures(string name)
        {
            try
            {
                MessengerManager.MessengerManager.AddLog("Start Offset Features");

                if (String.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException("Layer Name");
                }

                var pidsToDelete = new Acaddb.ObjectIdCollection();
                var pids         = GetAllPolylines();

                //var refcentroid = GetCentroidOfOuterBoundary(GetPolylinePoints(OGR.ObjectId));


                var offset = -0.0001; //inital start value

                foreach (Acaddb.ObjectId oid in pids)
                {
                    offset = -0.001;

                    Acaddb.Polyline polyline = GetPolyline((oid));

                    if (polyline == null)
                    {
                        throw new ArgumentNullException("Polyline is Null");
                    }

                    if (polyline.Layer != name.ToUpper())
                    {
                        continue;
                    }

                    MessengerManager.MessengerManager.AddLog("Found Offset Features on Layer " + name);

                    var newpoly = polyline.GetOffsetCurves(offset).Cast <Acaddb.Polyline>();

                    newpoly.FirstOrDefault().Layer = polyline.Layer;

                    // Get the current document and database

                    var acDoc   = Application.DocumentManager.MdiActiveDocument;
                    var acCurDb = acDoc.Database;

                    using (var acTrans = Application.DocumentManager.MdiActiveDocument
                                         .TransactionManager.StartTransaction())
                    {
                        // Open the Block table for read
                        Acaddb.BlockTable acBlkTbl;
                        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                     Acaddb.OpenMode.ForRead) as Acaddb.BlockTable;

                        // Open the Block table record Model space for write
                        Acaddb.BlockTableRecord acBlkTblRec;
                        acBlkTblRec = acTrans.GetObject(acBlkTbl[Acaddb.BlockTableRecord.ModelSpace],
                                                        Acaddb.OpenMode.ForWrite) as Acaddb.BlockTableRecord;
                        // Add each offset object
                        acBlkTblRec.AppendEntity(newpoly.FirstOrDefault());
                        acTrans.AddNewlyCreatedDBObject(newpoly.FirstOrDefault(), true);
                        acTrans.Commit();
                    }
                    pidsToDelete.Add(oid);
                }

                DeletePolys(pidsToDelete);
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }
            finally
            {
                MessengerManager.MessengerManager.AddLog("End Offset Features");
            }
        }
Example #13
0
        public static void TestScaleObject()
        {
            try
            {
                MessengerManager.MessengerManager.AddLog("Start Scaling");


                var pids         = GetAllPolylines();
                var pidsToDelete = new Acaddb.ObjectIdCollection();

                var offset = -0.001;

                foreach (Acaddb.ObjectId oid in pids)
                {
                    offset = -0.001;



                    using (var acTrans = Application.DocumentManager.MdiActiveDocument
                                         .TransactionManager.StartTransaction())
                    {
                        Acaddb.DBObject obj =
                            acTrans.GetObject(oid, Acaddb.OpenMode.ForWrite);

                        Acaddb.Polyline polyline = obj as Acaddb.Polyline;

                        if (polyline != null)
                        {
                            if (polyline.Closed)
                            {
                                if (polyline.Layer != "S-TEE-BOX")
                                {
                                    continue;
                                }

                                SendPolylineMessage("Length Info Before", polyline);

                                var centroid   = GetCentroidOfOuterBoundary(GetPolylinePoints(oid));
                                var centroid3d = new Point3d(centroid.X, centroid.Y, 0.0);
                                var closepnt   = polyline.GetClosestPointTo(centroid3d, true);
                                var radius     = polyline.GetDistAtPoint(closepnt);
                                var scaleFac   = 1 + (offset / Math.Abs(radius));
                                polyline.TransformBy(Matrix3d.Scaling(scaleFac, new Point3d(centroid.X, centroid.Y, 0)));


                                SendPolylineMessage("Length Info After", polyline);

                                MessengerManager.MessengerManager.AddLog
                                    (String.Format("Scale Info {0},{1},{2},{3},{4}",
                                                   centroid,
                                                   centroid3d,
                                                   closepnt,
                                                   radius,
                                                   scaleFac));
                            }
                            else
                            {
                                SendPolylineMessage("Polyline is not closed! ", polyline);
                            }
                        }
                        else
                        {
                            SendPolylineMessage("Polyline is NULL! ", polyline);
                        }

                        acTrans.Commit();
                    }
                    MessengerManager.MessengerManager.AddLog("End Scaling");
                }
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }
        }