Exemplo n.º 1
0
Arquivo: Ac.cs Projeto: 15831944/Geo7
        private static void DoEvents()
        {
            //Db.TransactionManager.QueueForGraphicsFlush();

            Editor.UpdateScreen();
            AcApp.UpdateScreen();
            //System.Windows.Forms.Application.DoEvents();
        }
Exemplo n.º 2
0
 public static void Fix(long DevFID)
 {
     try
     {
         Document doc   = Application.DocumentManager.MdiActiveDocument;
         ObjectId objId = DBEntityFinder.Instance.GetObjectIdByFid(DevFID);
         if (!objId.IsNull)
         {
             FixEntity.Instance.ClickFixEntity(objId);
             using (doc.LockDocument())
             {
                 for (int i = 0; i < 3; i++)
                 {
                     using (Transaction transaction = doc.TransactionManager.StartTransaction())
                     {
                         DCadApi.isModifySymbol = true;
                         var ent = transaction.GetObject(objId, OpenMode.ForRead) as Entity;
                         ent.UpgradeOpenAndRun();
                         ent.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 255, 0);
                         transaction.Commit();
                         Application.UpdateScreen();
                         DCadApi.isModifySymbol = false;
                     }
                     System.Threading.Thread.Sleep(50);
                     using (Transaction transaction = doc.TransactionManager.StartTransaction())
                     {
                         DCadApi.isModifySymbol = true;
                         var ent = transaction.GetObject(objId, OpenMode.ForRead) as Entity;
                         ent.UpgradeOpenAndRun();
                         ent.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0);
                         transaction.Commit();
                         Application.UpdateScreen();
                         DCadApi.isModifySymbol = false;
                     }
                     System.Threading.Thread.Sleep(50);
                 }
             }
         }
         else
         {
             //PublicMethod.ShowMessage("温馨提示:当前设备在沿布图上没有对应的符号!!");
         }
     }
     catch (SystemException ex)
     {
         LogManager.Instance.Error(ex);
     }
     finally
     {
         DCadApi.isModifySymbol = false;
     }
 }
Exemplo n.º 3
0
        public void DrawPolylines(List <Point3D> Objects, bool ShouldDeletePrevious, Autodesk.AutoCAD.Colors.Color color)
        {
            // If ModifyViewspace method is called from different thread, InvokeRequired will be true
            if (syncControl.InvokeRequired)
            {
                syncControl.Invoke(new DrawPolylinesDelegate(DrawPolylines), new object[] { Objects, ShouldDeletePrevious, color });
            }
            else
            {
                Document doc = AcadApp.DocumentManager.MdiActiveDocument;
                using (DocumentLock docLock = doc.LockDocument())
                {
                    Database currentDb = doc.Database;
                    using (Transaction trans = currentDb.TransactionManager.StartTransaction())
                    {
                        // Deleting the previous drawn object
                        if ((PreviousViewPoint != ObjectId.Null) && (ShouldDeletePrevious))
                        {
                            Entity ent = (Entity)trans.GetObject(PreviousViewPoint, OpenMode.ForWrite);
                            ent.Erase();
                            ent.Dispose();
                        }
                        // Open the Block table for read
                        BlockTable blockTable;
                        blockTable = trans.GetObject(currentDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                        // Open the Block table record Model space for write
                        BlockTableRecord blockTblRec =
                            trans.GetObject(blockTable[BlockTableRecord.ModelSpace],
                                            OpenMode.ForWrite) as BlockTableRecord;

                        Point3dCollection plCollection = new Point3dCollection();
                        foreach (Point3D p in Objects)
                        {
                            plCollection.Add(new Point3d(p.X, p.Y, p.Z));
                        }
                        Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, plCollection, false);
                        pl.Color = color;

                        PreviousViewPoint = blockTblRec.AppendEntity(pl);
                        trans.AddNewlyCreatedDBObject(pl, true);
                        trans.Commit();

                        // Updates the screen without flickering of view
                        AcadApp.UpdateScreen(); // or doc.Editor.Regen();
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void DrawPolylines(List <Point3D> Objects, bool ShouldFlush, Color color)
        {
            if (SyncControl.InvokeRequired)
            {
                SyncControl.Invoke(new DrawPolylinesDelegate(DrawPolylines), new object[] { Objects, ShouldFlush, color });
            }
            else
            {
                Document doc = AcadApp.DocumentManager.MdiActiveDocument;
                using (DocumentLock docLock = doc.LockDocument())
                {
                    Database currentDb = doc.Database;
                    using (Transaction trans = currentDb.TransactionManager.StartTransaction())
                    {
                        // Deleting the previous drawn objects
                        if (ShouldFlush)
                        {
                            FlushPolylinesQueue();
                        }

                        // Open the Block table for read
                        BlockTable blockTable;
                        blockTable = trans.GetObject(currentDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                        // Open the Block table record Model space for write
                        BlockTableRecord blockTblRec =
                            trans.GetObject(blockTable[BlockTableRecord.ModelSpace],
                                            OpenMode.ForWrite) as BlockTableRecord;

                        Point3dCollection plCollection = new Point3dCollection();
                        foreach (Point3D p in Objects)
                        {
                            plCollection.Add(new Point3d(p.X, p.Y, p.Z));
                        }
                        Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, plCollection, false);
                        pl.Color = AcadColor.FromColor(color);

                        blockTblRec.AppendEntity(pl);
                        trans.AddNewlyCreatedDBObject(pl, true);
                        trans.Commit();

                        // Updates the screen without flickering of view
                        AcadApp.UpdateScreen(); // or doc.Editor.Regen();
                    }
                }
            }
        }
Exemplo n.º 5
0
Arquivo: Ac.cs Projeto: 15831944/Geo7
 public static void UpdateScreen()
 {
     AcApp.UpdateScreen();
 }
Exemplo n.º 6
0
        /**
         *  对话框隐藏后无法对焦点的问题通过设置dialog的parent可以解决
         *  这里是重点
         *  找到父窗口
         **/
        private void BlockImage_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //string Prefix = "_";
            if (e.Button == MouseButtons.Right)
            {
                return;
            }
            Form   Parent = this.FindForm();
            Editor ed     = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            DWGLib.Dialog.LibaryDialog Dialog = Parent as DWGLib.Dialog.LibaryDialog;
            Document Doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            ed.WriteMessage("\n", true, true, false);
            if (this._type == 1)
            {
                Dialog.Hide();
                if (File.Exists(this.FilePath))
                {
                    Document _Doc = AcadApp.DocumentManager.Open(this.FilePath, false);
                }
                else
                {
                    AcadApp.ShowAlertDialog(string.Format("文件{0}不存在", this.FilePath));
                }
                Dialog.Close();
                Dialog.Dispose();
                return;
            }
            if (Dialog != null)
            {
                ObjectId BlockId = default(ObjectId);
                Dialog.Hide();

                Database     TargetDB  = HostApplicationServices.WorkingDatabase;
                DocumentLock DocLock   = Doc.LockDocument();
                string       BlockName = Path.GetFileNameWithoutExtension(this.FilePath);
                WBlockBetweenDataBase(BlockName);

                using (Transaction Tr = TargetDB.TransactionManager.StartTransaction())
                {
                    BlockTable       Btr        = Tr.GetObject(TargetDB.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord ModelSpace = (BlockTableRecord)SymbolUtilityServices.GetBlockModelSpaceId(TargetDB).GetObject(OpenMode.ForWrite);
                    try
                    {
                        BlockId = Btr[BlockName];
                    }catch (Autodesk.AutoCAD.Runtime.Exception ex)
                    {
                        //这样可以吗;
                        Dialog.Show();
                        AcadApp.ShowAlertDialog(ex.Message);
                        DocLock.Dispose();
                        TargetDB.Dispose();
                        return;
                    }
                    #region
                    ////<summary>

                    /*****
                     * if (Stats == ErrorStatus.OK)
                     * {
                     *  BlockId = Btr[BlockName];
                     * }
                     *  /****
                     *  try
                     *  {
                     *      if (Btr.Has(BlockName))
                     *      {
                     *          BlockId = Btr[BlockName];
                     *      }else
                     *      {
                     *          BlockId = TargetDB.Insert(BlockName, SourceDB, true);
                     *
                     *      }
                     *  }catch(Autodesk.AutoCAD.Runtime.Exception ex)
                     *  {
                     *      AcadApp.ShowAlertDialog("插入图块失败");
                     *
                     *      Tr.Commit();
                     *      DocLock.Dispose();
                     *      TargetDB.Dispose();
                     *      SourceDB.Dispose();
                     *      return;
                     *  }
                     * }
                     * else
                     * {
                     *  AcadApp.ShowAlertDialog("打开文件失败");
                     *  Dialog.Close();
                     *
                     *  Tr.Commit();
                     *  DocLock.Dispose();
                     *  TargetDB.Dispose();
                     *  SourceDB.Dispose();
                     *  return;
                     * }
                     ****/
                    #endregion
                    BlockReference Block = new BlockReference(new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0), BlockId);
                    Block.Highlight();
                    BlockJig _BlockJig = new BlockJig(Block);
                    bool     IsOK      = _BlockJig.RunBlockJig(Block);
                    //这里的运行情况是这样的,do......while,不会按照计算机的时钟频率运行,而是点击了屏幕之后才会运行,每点击一次运行一次
                    //这个AutoCAD运行的特殊的地方。
                    #region
                    #endregion

                    if (!IsOK)
                    {
                        AcadApp.UpdateScreen();
                        Dialog.Show();
                        ed.WriteMessage("取消插入\n", true, true, false);
                        Tr.Commit();
                        DocLock.Dispose();
                        TargetDB.Dispose();
                    }
                    else
                    {
                        Dialog.Close();
                        ed.WriteMessage("\n插入成功\n", true, true, false);
                        DBObjectCollection Objs = new DBObjectCollection();
                        ModelSpace.AppendEntity(Block);
                        Tr.AddNewlyCreatedDBObject(Block, true);
                        // Block.ExplodeToOwnerSpace();
                        Tr.Commit();
                        DocLock.Dispose();
                        TargetDB.Dispose();
                    }
                    //if is not OK
                }
            }
        }