当前位置: 首页 > article >正文

024集——CAD 动态显示图形——ed.Redraw(ent)实现(CAD—C#二次开发入门)

 cad二开中提交事务前可动态显示实体图形,方法如下:

主代码:

        public static void Redraw(this Editor ed, Entity? ent = null)
        {
            using (ent?.ForWrite())
            {
                ent?.Redraw(BrightEntity.RecordGraphicsModified | BrightEntity.RecomputeDimensionBlock | BrightEntity.Draw | BrightEntity.MoveZero);
                ed.Redraw(BrightEditor.UpdateScreen);
            }

            Autodesk.AutoCAD.ApplicationServices.TransactionManager transactionManager = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.TransactionManager;
            transactionManager.QueueForGraphicsFlush();
            transactionManager.FlushGraphics();
           //Application.DoEvents();//目前不可用
        }
        public static void Redraw(this Editor ed, BrightEditor bright)
        {
            if ((bright & BrightEditor.UpdateScreen) == BrightEditor.UpdateScreen)
            {
                ed.UpdateScreen();
            }

            if ((bright & BrightEditor.Regen) == BrightEditor.Regen)
            {
                ed.Regen();
            }

            if ((bright & BrightEditor.SelectionClean) == BrightEditor.SelectionClean)
            {
                ed.SetImpliedSelection(new ObjectId[0]);
            }

            if ((bright & BrightEditor.ViewportsFrom) == BrightEditor.ViewportsFrom)
            {
                ed.UpdateTiledViewportsFromDatabase();
            }

            if ((bright & BrightEditor.ViewportsIn) == BrightEditor.ViewportsIn)
            {
                ed.UpdateTiledViewportsInDatabase();
            }
        }

        public static void Redraw(this Entity ent, BrightEntity bright)
        {
            if ((bright & BrightEntity.RecordGraphicsModified) == BrightEntity.RecordGraphicsModified)
            {
                ent.RecordGraphicsModified(setModified: true);
            }

            if ((bright & BrightEntity.RecomputeDimensionBlock) == BrightEntity.RecomputeDimensionBlock && ent is Dimension dimension)
            {
                dimension.RecomputeDimensionBlock(forceUpdate: true);
            }

            if ((bright & BrightEntity.Draw) == BrightEntity.Draw)
            {
                ent.Draw();
            }

            if ((bright & BrightEntity.Highlight) == BrightEntity.Highlight)
            {
                ent.Highlight();
            }

            if ((bright & BrightEntity.Unhighlight) == BrightEntity.Unhighlight)
            {
                ent.Unhighlight();
            }

            if ((bright & BrightEntity.VisibleTrue) == BrightEntity.VisibleTrue)
            {
                ent.Visible = true;
            }

            if ((bright & BrightEntity.VisibleFalse) == BrightEntity.VisibleFalse)
            {
                ent.Visible = false;
            }

            if ((bright & BrightEntity.MoveZero) == BrightEntity.MoveZero)
            {
                //ent.Move(Point3d.Origin, Point3d.Origin);
                EditEntityTools.MoveEntity(ent, Point3d.Origin, Point3d.Origin);
            }
        }

 上述代码含有封装函数,需要调用以下方法、字段:

 

    [Flags]
    public enum BrightEntity
    {
        RecordGraphicsModified = 1,
        RecomputeDimensionBlock = 2,
        Draw = 4,
        Highlight = 8,
        Unhighlight = 0x10,
        VisibleTrue = 0x20,
        VisibleFalse = 0x40,
        MoveZero = 0x80
    }
    [Flags]
    public enum BrightEditor
    {
        UpdateScreen = 1,
        Regen = 2,
        SelectionClean = 4,
        ViewportsFrom = 8,
        ViewportsIn = 0x10
    }

       public static T CloneEx<T>(this T ent) where T : RXObject
       {
           if (!(ent.Clone() is T result))
           {
               throw new ArgumentException("CloneEx克隆出错");
           }

           return result;
       }

   

       public static void ForWrite<T>(this T obj, Action<T> action) where T : DBObject
       {
           bool isNotifyEnabled = obj.IsNotifyEnabled;
           bool isWriteEnabled = obj.IsWriteEnabled;
           if (isNotifyEnabled)
           {
               obj.UpgradeFromNotify();
           }
           else if (!isWriteEnabled)
           {
               obj.UpgradeOpen();
           }

           action?.Invoke(obj);
           if (isNotifyEnabled)
           {
               obj.DowngradeToNotify(isWriteEnabled);
           }
           else if (!isWriteEnabled)
           {
               obj.DowngradeOpen();
           }
       }

       public static UpgradeOpenManager ForWrite(this DBObject obj)
       {
           return new UpgradeOpenManager(obj);
       }

 


http://www.kler.cn/a/376464.html

相关文章:

  • Linux高阶——1027—守护进程
  • wx.setNavigationBarColor动态设置导航栏颜色无效(亲测有效)
  • Vue3+TypeScript+Vite 后台管理项目_登录页面开发实战
  • Python爬虫:揭开淘宝商品描述的神秘面纱
  • AI视频管理平台中使用目标检测模型中的NMS参数原理及设置原则
  • Cuda By Example - 12 (Texture Memory)
  • 初探Flink的序列化
  • centos7 zabbix监控nginx的pv和uv和status_code
  • 无法启动此程序win10玩游戏找不到d3dx9_43.dll缺失的五种常用有效解决方法
  • el-table 修改高亮行样式
  • 基于 Flask 的 Python 应用程序,主要功能包括用户认证、文件上传(CSV 和图片)、图像文字识别(OCR)以及根据识别结果进行一些数据处理和比对
  • [MySQL]DQL语句(一)
  • SRS:构建实时免费视频服务器的全方位指南
  • 使用Nginx作为Web服务器和反向代理
  • Webserver(2.4)进程控制
  • 2024 手机解压缩软件评测与推荐
  • 【ROS2】文档、教程、源码汇总
  • Android——横屏竖屏
  • 视频怎么进行格式转换?6款视频转换MP4格式的免费软件!
  • 【sqlmap使用手册-持续更新中】
  • 安装xtrabackup备份mysql
  • python项目实战 查询手机号码归属地源码
  • Node.js:Express 服务 路由
  • 工控一体机行业前景:智能化、自动化与高效能
  • 针对Hmaster启动后很快停止
  • 【大数据学习 | kafka】producer的参数与结构