예제 #1
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);
        }
예제 #2
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");
        }
예제 #3
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);
        }
예제 #4
0
        public static Acaddb.ObjectId ScaleNewPolylineObject(Point2dCollection points)
        {
            var offset = -0.001;
            var newoid = Acaddb.ObjectId.Null;
            var doc    = Active.Document;

            try
            {
                // Get the current document and database
                Document        acDoc   = Application.DocumentManager.MdiActiveDocument;
                Acaddb.Database acCurDb = acDoc.Database;
                using (acDoc.LockDocument())
                {
                    // Start a transaction
                    using (Acaddb.Transaction acTrans = acCurDb.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;

                        // Create a lightweight polyline
                        using (Acaddb.Polyline acPoly = new Acaddb.Polyline())
                        {
                            int i = 0;
                            foreach (Point2d pnt in points)
                            {
                                acPoly.AddVertexAt(i++, pnt, 0, 0, 0);
                            }
                            // Close the polyline
                            acPoly.Closed = true;

                            SendPolylineMessage("Length Info Before", acPoly);

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


                            SendPolylineMessage("Length Info After", acPoly);

                            // Add the new object to the block table record and the transaction

                            newoid = acBlkTblRec.AppendEntity(acPoly);
                            acTrans.AddNewlyCreatedDBObject(acPoly, true);

                            // Save the new objects to the database
                            acTrans.Commit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }

            return(newoid);
        }