예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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);
        }