Пример #1
0
        /// <summary>
        /// Gets the object.
        /// </summary>
        /// <param name="polyoid">The polyoid.</param>
        /// <returns>ACADDB.Polyline.</returns>
        private static Acaddb.Polyline GetObject(Acaddb.ObjectId polyoid)
        {
            using (var tr = Application.DocumentManager.MdiActiveDocument
                            .TransactionManager.StartTransaction())
            {
                var obj =
                    tr.GetObject(polyoid, Acaddb.OpenMode.ForRead);


                // If a "lightweight" (or optimized) polyline

                var lwp = obj as Acaddb.Polyline;

                if (lwp != null)
                {
                    // Is Polyline Closed
                    if (lwp.Closed)
                    {
                        return(lwp);
                    }
                    lwp.UpgradeOpen();
                    lwp.Closed = true;
                    lwp.DowngradeOpen();
                    return(lwp);
                }
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the polyline points.
        /// </summary>
        /// <param name="poid">The poid.</param>
        /// <returns>Point2dCollection.</returns>
        private static Point2dCollection GetPolylinePoints(Acaddb.ObjectId poid)
        {
            Point2dCollection points;

            using (Acaddb.Transaction tr = Active.StartTransaction())
            {
                points = new Point2dCollection();

                Acaddb.DBObject obj =
                    tr.GetObject(poid, Acaddb.OpenMode.ForRead);

                Acaddb.Polyline lwp = obj as Acaddb.Polyline;

                if (lwp != null)
                {
                    if (lwp.Closed)
                    {
                        int vn = lwp.NumberOfVertices;

                        for (int i = 0; i < vn; i++)
                        {
                            Point2d pt = lwp.GetPoint2dAt(i);
                            points.Add(pt);
                        }
                    }
                }
            }

            return(points);
        }
Пример #3
0
        /// <summary>
        /// Scales the object.
        /// </summary>
        /// <param name="polyId">The poly identifier.</param>
        public static void ScaleObject(Acaddb.ObjectId polyId)
        {
            try
            {
                MessengerManager.MessengerManager.AddLog("Start Scaling");

                var offset = -0.01;

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

                    Acaddb.Polyline polyline = obj as Acaddb.Polyline;

                    if (polyline != null)
                    {
                        if (polyline.Closed)
                        {
                            SendPolylineMessage("Length Info Before", polyline);

                            var centroid   = GetCentroidOfOuterBoundary(GetPolylinePoints(polyId));
                            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);
            }
        }
Пример #4
0
        public static void SimplifyPolylinesInterative(ObjectId polyid)
        {
            // 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 = new ObjectIdCollection();
                collection.Add(polyid);

                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
                        ModifyPolylineVertices(sortedCollection, collection[index]);

                        GetPolylineName(sortedCollection, point2DCollections.IndexOf(pnt2DCol));
                        index++;
                    }
                }
            }
            catch (System.Exception ex)
            {
                DatabaseLogs.FormatLogs("SimplifyPolylines: " + ex.Message);
            }
        }
Пример #5
0
        /// <summary>
        /// Gets the name of the polyline.
        /// </summary>
        /// <param name="selectedObjectId">The selected object identifier.</param>
        /// <returns>System.String.</returns>
        public static string GetPolylineName(ObjectId selectedObjectId)
        {
            var          doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var          ed  = doc.Editor;
            var          db  = doc.Database;
            PlanarEntity plane;

            //Get the current UCS

            var ucs =
                ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

            plane = new Plane(ucs.Origin, ucs.Xaxis);

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var obj =
                    tr.GetObject(selectedObjectId, OpenMode.ForRead);


                //"lightweight" (or optimized) polyline

                var lwp = obj as Polyline;

                if (lwp != null)
                {
                    return(lwp.Layer);
                }

                // If an old-style, 2D polyline

                var p2d = obj as Polyline2d;


                if (p2d != null)
                {
                    return(p2d.Layer);
                }

                // If an old-style, 3D polyline

                var p3d = obj as Polyline3d;

                if (p3d != null)
                {
                    return(p3d.Layer);
                }


                // Committing is cheaper than aborting

                tr.Commit();
            }
            return(null);
        }
Пример #6
0
        public static void CheckElevFromFeatureLine(Acaddb.ObjectId featureId)
        {
            var mean = 0.0;

            using (Acaddb.Transaction tr = Active.StartTransaction())
            {
                var feature =
                    (Autodesk.Civil.DatabaseServices.FeatureLine)featureId.GetObject(Acaddb.OpenMode.ForRead);

                if (feature == null)
                {
                    return;
                }
                if (feature != null)
                {
                    SendMessage(feature);

                    try
                    {
                        mean = GetAverageElev(feature);
                    }
                    catch
                    {
                    }

                    if (Math.Abs(mean) <= 0.01)
                    {
                        goto Skip;
                    }

                    if (ZeroElevation(feature))
                    {
                        COMS.MessengerManager.AddLog("Starting Checking Zero Elevation > 20 Points");
                        if (feature.GetPoints(FeatureLinePointType.AllPoints).Cast <Point3d>().Count(p => Math.Abs(p.Z) < 0.001) < 20)
                        {
                            COMS.MessengerManager.AddLog("Starting Correcting Zero Elevation > 20 Points");
                            ApplyElevationCorrection(feature, mean, feature.MaxElevation);
                            COMS.MessengerManager.AddLog("Ending Correcting Zero Elevation > 20 Points");
                        }
                        COMS.MessengerManager.AddLog("Ending Checking Zero Elevation > 20 Points");
                    }

                    SendMessage(feature);
                }

Skip:

                tr.Commit();
            }

            COMS.MessengerManager.AddLog("End CheckElevFromFeatureLine");
        }
Пример #7
0
        //    /// <summary>
        //    /// Gets the object identifier.
        //    /// </summary>
        //    /// <param name="handle">The handle.</param>
        //    /// <returns>ObjectId.</returns>
        public static ObjectId GetObjectId(string handle)
        {
            ObjectId id  = ObjectId.Null;
            Document doc = Application.DocumentManager.MdiActiveDocument;

            global::Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Handle h = new Handle(Int64.Parse
                                          (handle, NumberStyles.AllowHexSpecifier));
                db.TryGetObjectId(h, out id);
                tr.Commit();
            }
            return(id);
        }
Пример #8
0
        //    /// <summary>
        //    /// Determines whether [is tin excluded] [the specified objectid].
        //    /// </summary>
        //    /// <param name="objectid">The objectid.</param>
        //    /// <returns><c>true</c> if [is tin excluded] [the specified objectid]; otherwise, <c>false</c>.</returns>
        public static bool IsTINExcluded(ObjectId objectid)
        {
            using (DatabaseCommands commands = new DatabaseCommands())
            {
                IList <ExcludedFeatures> excludedfeatures;
                excludedfeatures = commands.GetAllExcludedFeatures_V2();

                foreach (var str in excludedfeatures)
                {
                    ObjectId compare = GetObjectId(str.Handle.Trim());
                    if (objectid.Equals(compare))
                    {
                        PGA.Database.DatabaseLogs.FormatLogs("Filtered Polylines");
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #9
0
        /// <summary>
        /// Gets the polyline.
        /// </summary>
        /// <param name="poid">The poid.</param>
        /// <returns>Acaddb.Polyline.</returns>
        private static Acaddb.Polyline GetPolyline(Acaddb.ObjectId poid)
        {
            using (Acaddb.Transaction tr = Active.StartTransaction())
            {
                Acaddb.DBObject obj =
                    tr.GetObject(poid, Acaddb.OpenMode.ForRead);

                Acaddb.Polyline lwp = obj as Acaddb.Polyline;

                if (lwp != null)
                {
                    if (lwp.Closed)
                    {
                        return(lwp);
                    }
                }
            }

            return(null);
        }
Пример #10
0
        /// <summary>
        /// Modifies the polyline vertices.
        /// </summary>
        /// <param name="sortedpoints">The sortedpoints.</param>
        /// <param name="polylineoId">The polylineo identifier.</param>
        private static void ModifyPolylineVertices(Point2dCollection sortedpoints, ObjectId polylineoId)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;


            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                var obj = tr.GetObject(polylineoId, OpenMode.ForRead);
                var pl  = obj as Polyline;
                if (pl != null)
                {
                    pl.UpgradeOpen();
                    pl.Reset(true, sortedpoints.Count);
                    for (int i = 0; i < sortedpoints.Count; i++)
                    {
                        pl.AddVertexAt(i, sortedpoints[i], 0, 0, 0);
                    }
                    pl.Closed = true;
                }
                tr.Commit();
            }
        }
Пример #11
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);
            }
        }
Пример #12
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);
            }
        }
Пример #13
0
        /// <summary>
        /// Gets the name of the polyline.
        /// </summary>
        /// <param name="selectedObjectId">The selected object identifier.</param>
        /// <param name="index">The index.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        static bool GetPolylineName(ObjectId selectedObjectId, int index)
        {
            var          doc      = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var          ed       = doc.Editor;
            var          db       = doc.Database;
            var          counter  = 0;
            var          position = 0;
            var          name     = "";
            PlanarEntity plane;

            //Get the current UCS

            CoordinateSystem3d ucs =
                ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

            plane = new Plane(ucs.Origin, ucs.Xaxis);

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var obj =
                    tr.GetObject(selectedObjectId, OpenMode.ForRead);


                //"lightweight" (or optimized) polyline

                var lwp = obj as Polyline;

                if (lwp != null)
                {
                    var vn = lwp.NumberOfVertices;

                    DatabaseLogs.FormatLogs(String.Format("Polyline Name= {2}-{0} - Vertices= {1}",
                                                          lwp.Layer, lwp.NumberOfVertices, index));
                }

                else
                {
                    // If an old-style, 2D polyline

                    var p2d = obj as Polyline2d;


                    if (p2d != null)
                    {
                        foreach (ObjectId vId in p2d)
                        {
                            var v2d =
                                (Vertex2d)tr.GetObject(
                                    vId,
                                    OpenMode.ForRead
                                    );

                            name = v2d.BlockName;
                            position++;
                        }

                        DatabaseLogs.FormatLogs(String.Format("Polyline Name= {2}-{0} - Vertices= {1}",
                                                              p2d.Layer, counter, index));
                    }

                    else
                    {
                        // If an old-style, 3D polyline

                        var p3d = obj as Polyline3d;

                        if (p3d != null)
                        {
                            // Use foreach to get each contained vertex

                            foreach (ObjectId vId in p3d)
                            {
                                var v3d =
                                    (PolylineVertex3d)tr.GetObject(
                                        vId,
                                        OpenMode.ForRead
                                        );
                                name = v3d.Layer;
                            }

                            DatabaseLogs.FormatLogs(String.Format("Polyline Name= {2}-{0} - Vertices= {1}",
                                                                  name, counter, index));
                        }
                    }
                }

                // Committing is cheaper than aborting

                tr.Commit();
            }
            return(true);
        }
Пример #14
0
        /// <summary>
        /// Gets the point2d from polylines.
        /// </summary>
        /// <param name="selectedObjectId">The selected object identifier.</param>
        /// <returns>Point2dCollection.</returns>
        public static Point2dCollection GetPoint2dFromPolylines(ObjectId selectedObjectId)
        {
            var          doc    = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var          ed     = doc.Editor;
            var          db     = doc.Database;
            var          Points = new Point2dCollection();
            PlanarEntity plane;

            //Get the current UCS

            CoordinateSystem3d ucs =
                ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

            plane = new Plane(ucs.Origin, ucs.Xaxis);

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var obj =
                    tr.GetObject(selectedObjectId, OpenMode.ForRead);


                //"lightweight" (or optimized) polyline

                var lwp = obj as Polyline;

                if (lwp != null)
                {
                    var vn = lwp.NumberOfVertices;

                    for (var i = 0; i < vn; i++)
                    {
                        var pt = lwp.GetPoint2dAt(i);
                        Points.Add(pt);
                    }
                }

                else
                {
                    // If an old-style, 2D polyline

                    var p2d = obj as Polyline2d;

                    if (p2d != null)
                    {
                        foreach (ObjectId vId in p2d)
                        {
                            var v2d =
                                (Vertex2d)tr.GetObject(
                                    vId,
                                    OpenMode.ForRead
                                    );

                            // Points.Add(v2d.Position.Convert2d(plane));
                            Points.Add((new Point2d(v2d.Position.X, v2d.Position.Y)));
                        }
                    }

                    else
                    {
                        // If an old-style, 3D polyline

                        var p3d = obj as Polyline3d;

                        if (p3d != null)
                        {
                            // Use foreach to get each contained vertex

                            foreach (ObjectId vId in p3d)
                            {
                                var v3d =
                                    (PolylineVertex3d)tr.GetObject(
                                        vId,
                                        OpenMode.ForRead
                                        );

                                //ed.WriteMessage(
                                //    "\n" + v3d.Position.ToString()
                                //    );
                            }
                        }
                    }
                }

                // Committing is cheaper than aborting

                tr.Commit();
            }
            return(Points);
        }
Пример #15
0
        /// <summary>
        /// Modifies the polyline vertices.
        /// </summary>
        /// <param name="originalpoints">The originalpoints.</param>
        /// <param name="sortedpoints">The sortedpoints.</param>
        /// <param name="polylineoId">The polylineo identifier.</param>
        private static void ModifyPolylineVertices(Point2dCollection originalpoints, Point2dCollection sortedpoints, ObjectId polylineoId)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;


            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                var obj  = tr.GetObject(polylineoId, OpenMode.ForRead);
                var pl   = obj as Polyline;
                var flag = false;

                if (pl != null)
                {
                    pl.UpgradeOpen();
                    for (int i = 1; i < pl.NumberOfVertices - 1; i++)
                    {
                        flag = false;
                        for (int j = 0; j < sortedpoints.Count; j++)
                        {
                            if ((pl.GetPoint2dAt(i).Equals(sortedpoints[j])))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag == false)
                        {
                            pl.RemoveVertexAt(i);
                        }
                    }
                }
                tr.Commit();
            }
        }