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

圆周期性显示和消失——瞬态实现(CAD c#二次开发、插件定制)

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
[assembly: CommandClass(typeof(IfoxDemo.Commands))]
namespace IfoxDemo
{// 新增的圆形闪烁命令实现public class Commands{[CommandMethod("xx")]public void FlashCircles(){Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;try{// 收集当前数据库中的所有圆形List<Entity> circleEntities = CollectAllCircles();if (circleEntities.Count == 0){ed.WriteMessage("\n未找到圆形实体。");return;}// 设置圆形颜色为红色 (颜色索引1为红色)foreach (Circle circle in circleEntities){circle.ColorIndex = 1; // 红色}ed.WriteMessage($"\n找到 {circleEntities.Count} 个圆形。");ed.WriteMessage("\n按ESC键切换圆形的显示/隐藏状态,按其他键结束命令。\n");Flash circleFlash = null;bool circlesVisible = false; // 初始状态为隐藏while (true){// 提示用户操作PromptPointOptions ppo = new PromptPointOptions("\n按ESC键切换圆形显示状态: \n");PromptPointResult ppr = ed.GetPoint(ppo);// 如果用户按ESC键if (ppr.Status == PromptStatus.Cancel){// 切换显示状态circlesVisible = !circlesVisible;if (circlesVisible){// 创建瞬态显示 (显示红色圆形)if (circleFlash != null)circleFlash.FlashlistErase();circleFlash = new Flash(circleEntities);ed.WriteMessage("\n圆形已显示。");}else{// 移除瞬态显示 (隐藏圆形)if (circleFlash != null){circleFlash.FlashlistErase();ed.WriteMessage("\n圆形已隐藏。");}}}else{// 用户点击鼠标break;}}// 确保清理资源if (circleFlash != null)circleFlash.FlashlistErase();ed.WriteMessage("\n命令已结束。");}catch (System.Exception ex){ed.WriteMessage("\n错误: " + ex.Message);}}private List<Entity> CollectAllCircles(){Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;List<Entity> circles = new List<Entity>();using (Transaction tr = db.TransactionManager.StartTransaction()){try{// 获取模型空间BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);// 遍历模型空间中的所有实体foreach (ObjectId objId in btr){if (objId.IsErased)continue;Entity ent = tr.GetObject(objId, OpenMode.ForRead) as Entity;if (ent is Circle){// 克隆圆形实体,避免直接修改原始对象Circle circleClone = ent.Clone() as Circle;//稍微移动一点,circleClone.TransformBy(Matrix3d.Displacement(new Vector3d(0.01, 0.01, 0)));circles.Add(circleClone);}}tr.Commit();}catch (System.Exception ex){Editor ed = doc.Editor;ed.WriteMessage("\n收集圆形错误: " + ex.Message);tr.Abort();}}return circles;}}// 瞬态类封装代码保持不变public class Flash{public FlashEntity flash = null;public Entity ent = null;public List<FlashEntity> listflash = new List<FlashEntity>();public List<Entity> listent = new List<Entity>();public Flash(Entity ent){this.ent = ent;flash = new FlashEntity(ent);Transient.CapturedDrawable = flash;TransientManager.CurrentTransientManager.AddTransient(flash,TransientDrawingMode.Main, 128, new IntegerCollection());}public Flash(List<Entity> ents){for (int i = 0; i < ents.Count; i++){this.listent.Add(ents[i]);listflash.Add(new FlashEntity(listent[i]));Transient.CapturedDrawable = listflash[i];TransientManager.CurrentTransientManager.AddTransient(listflash[i],TransientDrawingMode.Main, 128, new IntegerCollection());}}public void FlashUpdate(Entity ent){if (ent == null){this.ent = ent;flash = new FlashEntity(ent);Transient.CapturedDrawable = flash;TransientManager.CurrentTransientManager.AddTransient(flash,TransientDrawingMode.Main, 128, new IntegerCollection());}else{this.ent = ent;flash._ent = ent;TransientManager.CurrentTransientManager.UpdateTransient(flash, new IntegerCollection());}}public void FlashUpdate(List<Entity> ents){if (ents == null){this.listent = ents;foreach (var item in ents){flash._ents.Add(item);}foreach (var item in listflash){Transient.CapturedDrawable = item;TransientManager.CurrentTransientManager.AddTransient(item,TransientDrawingMode.Main, 128, new IntegerCollection());}}else{this.listent = ents;for (int i = 0; i < ents.Count; i++){listflash[i]._ent = ents[i];}foreach (var item in listflash){TransientManager.CurrentTransientManager.UpdateTransient(item, new IntegerCollection());}}}public void FlashErase(){if (flash == null) return;flash._ent = null;TransientManager.CurrentTransientManager.EraseTransient(flash, new IntegerCollection());flash = null;}public void FlashlistErase(){if (listflash == null) return;foreach (var item in listflash){item._ent = null;}foreach (var item in listflash){TransientManager.CurrentTransientManager.EraseTransient(item, new IntegerCollection());}listflash = null;}}public class FlashEntity : Transient{public Entity _ent;public List<Entity> _ents = new List<Entity>();public FlashEntity(Entity ent){_ent = ent;}public FlashEntity(List<Entity> ents){foreach (var item in ents){_ents.Add(item);}}protected override int SubSetAttributes(DrawableTraits traits){traits.FillType = FillType.FillAlways;return (int)DrawableAttributes.IsAnEntity;}protected override void SubViewportDraw(ViewportDraw vd){vd.Geometry.Draw(_ent);foreach (Entity ent in _ents){vd.Geometry.Draw(ent);}}protected override bool SubWorldDraw(WorldDraw wd){return false;}}}

CAD插件定制联系↓↓↓

http://www.lqws.cn/news/538255.html

相关文章:

  • Nordic nRF54L15 SoC对包含电池监测、中断处理和电源轨控制的定制 nPM1300 示例
  • springcloud 尚硅谷 看到9开头
  • 华为云鸿蒙应用入门级开发者认证 实验(HCCDA-HarmonyOS Cloud Apps)
  • 玄机抽奖Spring Web项目
  • Maven Javadoc 插件使用详解
  • [论文阅读]RaFe: Ranking Feedback Improves Query Rewriting for RAG
  • 解决uniapp vue3版本封装组件后:deep()样式穿透不生效的问题
  • react-嵌套路由 二级路由
  • 事件循环(Event Loop)机制对比:Node.js vs 浏览器​
  • python+requests接口自动化测试
  • 大脑感官:视觉系统中将感观信息转换为神经信号
  • @Autowired 和 @Resource 有什么区别?
  • Java常用设计模式详解
  • linux网络编程socket套接字
  • 【论文阅读】--Instruction Backdoor Attacks Against Customized LLMs
  • Neo4j2.0.1桌面端使用教程(简化版)
  • MySQL 锁的分类
  • WinAppDriver 自动化测试:C#篇
  • EMQ X Broker 配置HTTP 的外部鉴权接口
  • 生物化学 PCR(聚合酶链式反应)引物 制造(固相磷酰胺化学法) 购买 存储
  • 如何在x86_64 Linux上部署Android Cuttlefish模拟器运行环境
  • MySQL事物隔离级别详解
  • 笔记04:层叠的定义及添加
  • 链表基本功(相交链表)
  • Ubuntu通过防火墙管控Docker容器
  • Go语言与云原生:Kubernetes Operator开发全流程
  • Selenium+Pytest自动化测试框架实战
  • 第十二章:温度传感器拓展模块
  • 《汇编语言:基于X86处理器》第5章 过程(1)
  • LeetCode 2311.小于等于 K 的最长二进制子序列:贪心(先选0再选1)-好像还是比灵神写的清晰些