Example #1
0
        /// <summary>
        /// 多实体定位
        /// </summary>
        /// <param name="polylineHandleList"></param>
        public static void FindPolyline(List <string> polylineHandleList)
        {
            DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument();
            Document     doc            = Application.DocumentManager.MdiActiveDocument;
            Database     db             = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    List <Point3d> maxList = new List <Point3d>();
                    List <Point3d> minList = new List <Point3d>();
                    foreach (var polylineHandle in polylineHandleList)
                    {
                        ObjectId newObjectId = TechnologicalProcess.GetObjectId(polylineHandle, 10);
                        Entity   entity      = tr.GetObject(newObjectId, OpenMode.ForWrite) as Entity;
                        if (entity == null)
                        {
                            continue;
                        }
                        var range = entity.GeometricExtents;
                        entity.Highlight();
                        maxList.Add(range.MaxPoint);
                        minList.Add(range.MinPoint);
                    }
                    double maxX = GetMaximumValue(maxList, true);
                    double maxY = GetMaximumValue(maxList, false);
                    double minX = GetMinimumBValue(minList, true);
                    double minY = GetMinimumBValue(minList, false);
                    Autodesk.AutoCAD.Interop.AcadApplication acadApplication = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
                    //参数要求是双精度的数组
                    if (acadApplication != null)
                    {
                        double[] doubles1 = new double[3] {
                            minX, minY, 0
                        };
                        double[] doubles2 = new double[3] {
                            maxX, maxY, 0
                        };
                        acadApplication.ZoomWindow(doubles1, doubles2);
                    }
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("定位:" + e.ToString());
                }
                finally
                {
                    tr.Commit();
                    m_DocumentLock.Dispose();
                }
            }
        }
Example #2
0
        /// <summary>
        /// 定位
        /// </summary>
        /// <param name="polylineHandle"></param>
        public static void FindPolyline(string polylineHandle)
        {
            DocumentLock m_DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument();
            Document     doc            = Application.DocumentManager.MdiActiveDocument;
            Database     db             = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    ObjectId newObjectId = TechnologicalProcess.GetObjectId(polylineHandle, 10);
                    Entity   entity      = tr.GetObject(newObjectId, OpenMode.ForWrite) as Entity;
                    var      range       = entity.GeometricExtents;
                    if (entity == null)
                    {
                        return;
                    }
                    Autodesk.AutoCAD.Interop.AcadApplication acadApplication = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
                    //参数要求是双精度的数组
                    if (acadApplication != null)
                    {
                        double[] doubles1 = new double[3] {
                            range.MinPoint.X, range.MinPoint.Y, range.MinPoint.Z
                        };
                        double[] doubles2 = new double[3] {
                            range.MaxPoint.X, range.MaxPoint.Y, range.MaxPoint.Z
                        };
                        acadApplication.ZoomWindow(doubles1, doubles2);
                        entity.Highlight();
                    }
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("定位:" + e.ToString());
                }
                finally
                {
                    tr.Commit();
                    m_DocumentLock.Dispose();
                }
            }
        }