cad.net 图元动画效果+图元刷新

动图演示

img

img

实现代码

#if !HC2020
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Acap = Autodesk.AutoCAD.ApplicationServices.Application;
#else
using GrxCAD.DatabaseServices;
using GrxCAD.EditorInput;
using GrxCAD.Geometry;
using GrxCAD.Runtime;
using Acap = GrxCAD.ApplicationServices.Application;
#endif

// https://www.cnblogs.com/JJBox/p/11354224.html
namespace JoinBox
{
    public partial class CmdTest
    {
        static bool flag = false;

        [CommandMethod("CmdTest_Animation", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
        public void CmdTest_Animation()
        {
            flag = !flag;

            var dm = Acap.DocumentManager;
            var doc = dm.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            db.Action(tr => {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                var btRec = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                int num = 0;
                for (int i = 0; i < 25; i++)
                {
                    var acCirc = new Circle(new Point3d(num++, 0, 0), Vector3d.ZAxis, 0.5);
                    btRec.AppendEntity(acCirc);
                    tr.AddNewlyCreatedDBObject(acCirc, true);

                    //非必要 https://gitee.com/inspirefunction/IFoxCAD/blob/develop/src/IFoxCAD.Cad/ExtensionMethod/EditorEx.cs
                    //ed.ZoomWindow(); 

                    //输出到命令栏,注意一下这两种不同感觉
                    var strNum = num.ToString();
                    if (flag)
                        strNum += "\n";
                    else
                        strNum += "\r";
                    ed.WriteMessage(strNum);

                    CadSystem.UpdateScreenEx(acCirc);
                    System.Threading.Thread.Sleep(100);
                }
            });
        }
    }
    public class CadSystem
    {       
        public static void UpdateScreenEx(Entity ent = null)
        {
            ent?.Draw();//图元刷新
            ent?.RecordGraphicsModified(true);//图块刷新
           if (ent is Dimension dim)//标注刷新
               dim.RecomputeDimensionBlock(true);
            Acap.UpdateScreen();//和ed.UpdateScreen();//底层实现差不多
            //acad2014及以上要加,立即处理队列上面的消息
            System.Windows.Forms.Application.DoEvents();
        }
    }
}

子函数

db.Action

相关阅读

e大也写了一篇Arx同等效果:
ObjectARX延时动画效果简单示意

图层影响图元刷新:
cad.net 图层解锁时图层褪色度设置LayLockFadectl

(完)

posted @ 2019-08-14 19:36  惊惊  阅读(1208)  评论(0编辑  收藏  举报