Example #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);
        }
Example #2
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);
            }
        }
Example #3
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 #4
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);
        }