cad.net 图元动画效果+图元刷新
动图演示
实现代码
#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(nameof(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;
using var tr = new DBTans();
var btRec = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
for (int i = 0; i < 25; i++) {
//输出到命令栏,注意一下这两种不同感觉
var strNum = i.ToString();
if (flag) strNum += "\n";
else strNum += "\r";
ed.WriteMessage(strNum);
// 创建圆形并加入数据库
var acCirc = new Circle(new Point3d(i, 0, 0), Vector3d.ZAxis, 0.5);
btRec.AppendEntity(acCirc);
tr.AddNewlyCreatedDBObject(acCirc, true);
// 事务提交前刷新图元
CadSystem.UpdateScreenEx(acCirc);
// 延时100ms
System.Threading.Thread.Sleep(100);
}
tr.Transaction.TransactionManager.QueueForGraphicsFlush();
tr.Document?.TransactionManager.FlushGraphics();
}
}
public class CadSystem {
public static void UpdateScreenEx(Entity? ent = null,
OpenMode om = OpenMode.ForWrite) {
if (ent is not null) {
if(om == OpenMode.ForWrite)
ent.UpgradeOpen();
// 标注刷新
if (ent is Dimension dim)
dim.RecomputeDimensionBlock(true);
// 图元重绘
ent.Draw();
// 图块刷新
ent.RecordGraphicsModified(true);
// move0要提权才有效果,不然也不报错
ent.TransformBy(Matrix3d.Displacement(new Vector3d(0,0,0)));
if(om == OpenMode.ForWrite)
ent.DowngradeOpen();
}
Acap.UpdateScreen(); //它们底层差不多ed.UpdateScreen();
// acad2014及以上要加,立即处理队列上面的消息
System.Windows.Forms.Application.DoEvents();
}
}
子函数
相关阅读
e大也写了一篇Arx同等效果:
ObjectARX延时动画效果简单示意
图层影响图元刷新:
cad.net 图层解锁时图层褪色度设置LayLockFadectl
IFox内两个封装:
https://gitee.com/inspirefunction/ifoxcad/blob/jing/src/IFoxCAD.Cad.Shared/ExtensionMethod/EditorEx.cs
https://gitee.com/inspirefunction/ifoxcad/blob/jing/src/IFoxCAD.Cad.Shared/Runtime/RedrawEx.cs
(完)