CAD 屏幕进度条

news2025/3/20 1:06:10

 

 参考鸿视频实现,代码如下:

主类

using System.IO.Ports;
using System.Threading;
using System.Windows.Controls;
using static IFoxDemo.进度条class;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;

//[assembly: CommandClass(typeof(IFoxDemo.进度条class))]//只允许此类快捷键命令
namespace IFoxDemo
{
    public class 进度条class
    {
        public static bool isover;
        [CommandMethod("xx")]
        public static void tt()
        {
            isover = false;
            Document doc = Env.Document;
            using var tr = new DBTrans();
            //瞬态进度条
            int n = 10000;//总循环次数
            int m = 100;//进度条更新次数
            int k = 0;
            屏幕进度条 jd = new 屏幕进度条(m, "正在运行中......");
            for (int i = 0; i < n; i++)
            {
                if (i % (n / m) == 0)
                {
                    jd.Run();
                    k++;
                    var mydouble = (double)k / m * 100;
                    var mystr = mydouble.ToString() + "%";
                    mystr.Print();//命令行输出进度
                    Thread.Sleep(20);//暂停50毫秒
                                     //Env.Editor.Redraw();//ifox 写法 。
                    System.Windows.Forms.Application.DoEvents();//影响程序速度
                    //暂停调试.暂停();
                }
            }
            isover = true;
            jd.Stop();
            "ok\n".Print();
        }
        class 屏幕进度条
        {
            double max;//总进度
            double tick;//当前进度
            string str;
            TransientManager tm;
            Polyline 进度多段线, 总进度线;
            Extents3d 屏幕包围盒;
            double 屏幕高度, 屏幕宽度, 进度条长度, 进度条高度, 百分比高度, 提示高度;
            Point3d 起点, 终点, 当前点, 百分比位置点, 提示位置点;
            MText 百分比;
            MText 提示文字;
            public 屏幕进度条(int max, string str)
            {
                this.max = max;
                this.str = str;
                tm = TransientManager.CurrentTransientManager;
                Document doc = Env.Document;//
                doc.BeginDocumentClose += Doc_BeginDocumentClose;
                doc.CloseWillStart += Doc_CloseWillStart;
                //Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                屏幕包围盒 = 视口包围盒.GetViewExtents3d();
                屏幕宽度 = 屏幕包围盒.MaxPoint.X - 屏幕包围盒.MinPoint.X;
                屏幕高度 = 屏幕包围盒.MaxPoint.Y - 屏幕包围盒.MinPoint.Y;
                进度条高度 = 屏幕高度 * 0.02;
                进度条长度 = 屏幕宽度 * (1 - 0.618) * 0.618;
                起点 = new Point3d(屏幕包围盒.MinPoint.X + 屏幕宽度 * 0.618, 屏幕包围盒.MinPoint.Y + 屏幕高度 * 0.2, 0);
                终点 = new Point3d(起点.X + 进度条长度, 起点.Y, 0);
                当前点 = 起点;
                进度多段线 = new Polyline();
                进度多段线.AddVertexAt(0, 起点.Point2d(), 0, 0, 0);
                进度多段线.AddVertexAt(1, 起点.Point2d(), 0, 0, 0);
                进度多段线.Color = ColorName.huang;
                进度多段线.ConstantWidth = 进度条高度;
                总进度线 = new Autodesk.AutoCAD.DatabaseServices.Polyline();
                总进度线.AddVertexAt(0, 起点.Point2d(), 0, 0, 0);
                总进度线.AddVertexAt(1, 终点.Point2d(), 0, 0, 0);
                总进度线.Color = ColorName.lv;
                百分比高度 = 进度条高度 * 0.7;
                百分比位置点 = 当前点 + new Vector3d(0, 进度条高度 * 1.6, 0);
                //百分比 = new MText();
                //百分比.SetDatabaseDefaults(Env.Database);
                //百分比.Contents = "0.0%";
                //百分比.Location = 百分比位置点;
                //百分比.Height = 百分比高度;
                百分比 = MTextEx.CreateMText(百分比位置点, "0.0%", 百分比高度, action: t => t.Color = ColorName.lv);//ifox写法
                提示高度 = 进度条高度;
                提示位置点 = 起点 - new Vector3d(0, 进度条高度, 0);
                提示文字 = MTextEx.CreateMText(提示位置点, str, 提示高度, action: t => t.Color = ColorName.lv);//ifox写法
                tm.AddTransient(总进度线, TransientDrawingMode.DirectTopmost, 0, new IntegerCollection());
                tm.AddTransient(进度多段线, TransientDrawingMode.DirectTopmost, 0, new IntegerCollection());
                tm.AddTransient(百分比, TransientDrawingMode.DirectTopmost, 0, new IntegerCollection());
                tm.AddTransient(提示文字, TransientDrawingMode.DirectTopmost, 0, new IntegerCollection());
                tick = 0;
                doc.ViewChanged += Doc_ViewChanged;
            }

            private void Doc_CloseWillStart(object sender, EventArgs e)
            {
                Stop();
            }

            private void Doc_BeginDocumentClose(object sender, DocumentBeginCloseEventArgs e)
            {
                Stop();
            }

            public void Doc_ViewChanged(object sender, EventArgs e)
            {
                if (!isover)
                {
                    //更新瞬态();
                    屏幕包围盒 = 视口包围盒.GetViewExtents3d();
                    屏幕宽度 = 屏幕包围盒.MaxPoint.X - 屏幕包围盒.MinPoint.X;
                    屏幕高度 = 屏幕包围盒.MaxPoint.Y - 屏幕包围盒.MinPoint.Y;
                    进度条高度 = 屏幕高度 * 0.02;
                    进度条长度 = 屏幕宽度 * (1 - 0.618) * 0.618;
                    起点 = new Point3d(屏幕包围盒.MinPoint.X + 屏幕宽度 * 0.618, 屏幕包围盒.MinPoint.Y + 屏幕高度 * 0.2, 0);
                    终点 = 起点 + new Vector3d(进度条长度, 0, 0); //new Point3d(起点.X + 进度条长度, 起点.Y, 0);
                    当前点 = 起点 + new Vector3d(tick / max * 进度条长度, 0, 0);
                    //进度多段线 = new Polyline();
                    进度多段线.SetPointAt(0, 起点.Point2d());
                    进度多段线.SetPointAt(1, 当前点.Point2d());
                    //进度多段线.Color = ColorName.huang;
                    进度多段线.ConstantWidth = 进度条高度 * 0.7;
                    //总进度线 = new Autodesk.AutoCAD.DatabaseServices.Polyline();
                    总进度线.SetPointAt(0, 起点.Point2d());
                    总进度线.SetPointAt(1, 终点.Point2d());
                    总进度线.Color = ColorName.lv;
                    百分比高度 = 进度条高度 * 0.7;
                    百分比位置点 = 当前点 + new Vector3d(0, 进度条高度 * 1.6, 0);
                    //百分比 = MTextEx.CreateMText(百分比位置点, "0.0%", 百分比高度, action: t => t.Color = ColorName.lv);//ifox写法
                    百分比.Location = 当前点 + new Vector3d(0, 进度条高度 * 1.6, 0);
                    提示高度 = 进度条高度;
                    提示位置点 = 起点 - new Vector3d(0, 进度条高度, 0);
                    //提示文字 = MTextEx.CreateMText(提示位置点, str, 提示高度, action: t => t.Color = ColorName.lv);//ifox写法
                    提示文字.Location = 提示位置点;
                    提示文字.Height = 提示高度;
                    更新瞬态();
                    //tm.UpdateTransient(总进度线, new IntegerCollection());
                    //tm.UpdateTransient(进度多段线, new IntegerCollection());
                    //tm.UpdateTransient(百分比, new IntegerCollection());
                    //tm.UpdateTransient(提示文字, new IntegerCollection());
                    //System.Windows.Forms.Application.DoEvents();//影响程序速度
                    Env.Editor.UpdateScreen();
                }
            }

            private void 更新瞬态()
            {
                tm.UpdateTransient(总进度线, new IntegerCollection());
                tm.UpdateTransient(进度多段线, new IntegerCollection());
                tm.UpdateTransient(百分比, new IntegerCollection());
                tm.UpdateTransient(提示文字, new IntegerCollection());
            }

            public void Run()
            {
                tick++;
                if (tick >= max) Stop();
                当前点 = 起点 + new Vector3d(tick / max * 进度条长度, 0, 0);
                进度多段线.SetPointAt(1, 当前点.Point2d());
                百分比.Location = 当前点 + new Vector3d(0, 进度条高度 * 1.6, 0);
                百分比.Contents = (tick / max * 100).ToString("0") + "%";
                tm.UpdateTransient(进度多段线, new IntegerCollection());
                tm.UpdateTransient(百分比, new IntegerCollection());
                //Env.Editor.Redraw();//ifox 写法 。
                Document doc1 = Env.Document;
                // doc1.ViewChanged += Doc1_ViewChanged;
               // System.Windows.Forms.Application.DoEvents();//影响程序速度
                Env.Editor.UpdateScreen();//比redraw更新瞬态效果好
            }
            public void Stop()
            {
                tm.EraseTransient(总进度线, new IntegerCollection());
                tm.EraseTransient(进度多段线, new IntegerCollection());
                tm.EraseTransient(百分比, new IntegerCollection());
                tm.EraseTransient(提示文字, new IntegerCollection());
                //System.Windows.Forms.Application.DoEvents();//影响程序速度
                Env.Editor.UpdateScreen();
            }
            //MText MText(string textstring,Point3d location ,double height)
            //{//代码省略
            //    return null;
            //}
        }
      

    }
    
    
}

colorname

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IFoxDemo
{
    public static class ColorName
    {
        public static Color 红 = Color.FromRgb(255, 0, 0);
        public static Color 绿 = Color.FromRgb(0, 255, 0);
        public static Color 蓝 = Color.FromRgb(0, 0, 255);
        public static Color 黄 = Color.FromRgb(255, 255, 0);
        public static Color 洋 = Color.FromRgb(255, 0, 255);
        public static Color 青 = Color.FromRgb(0, 255, 255);
        public static Color 白 = Color.FromRgb(255, 255, 255);
        public static Color 黑 = Color.FromRgb(0, 0, 0);
        public static Color 灰127 = Color.FromRgb(127, 127, 127);
        public static Color 灰50 = Color.FromRgb(50, 50, 50);
        public static Color 灰200 = Color.FromRgb(200, 200, 200);
        public static Color 克莱因蓝 = Color.FromRgb(0, 47, 167);
        public static Color hong = Color.FromRgb(255, 0, 0);
        public static Color lv = Color.FromRgb(0, 255, 0);
        public static Color lan = Color.FromRgb(0, 0, 255);
        public static Color huang = Color.FromRgb(255, 255, 0);
        public static Color yanghong = Color.FromRgb(255, 0, 255);
        public static Color qing = Color.FromRgb(0, 255, 255);
        public static Color bai = Color.FromRgb(255, 255, 255);
        public static Color hei = Color.FromRgb(0, 0, 0);
    }
}

视口包围盒

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IFoxDemo
{
    public static class 视口包围盒
    {
        public static Extents3d GetViewExtents3d()
        {
            ViewTableRecord vtr = Env.Editor.GetCurrentView();//获取当前视图
            double w = vtr.Width;//视图宽度
            double h = vtr.Height;//视图高度
            Point2d pc = vtr.CenterPoint;//视图中心点xy坐标
            Point3d pmin = new Point3d(pc.X - w / 2, pc.Y - h / 2, 0);//当前视图左下角坐标
            Point3d pmax = new Point3d(pc.X + w / 2, pc.Y + h / 2, 0);//当前视图右上角坐标
            Extents3d ext = new Extents3d(pmin, pmax);//当前视图包围盒
            ext.TransformBy(Matrix3d.Displacement(vtr.Target - Point3d.Origin));//从用户坐标系转为世界坐标系?ucsto wcs
            return ext;
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2296312.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

小红书爬虫: 获取所需数据

小红书&#xff0c;又名 “小红书 ”或简称 “红”&#xff0c;已迅速成为中国社交和电子商务领域的重要参与者&#xff0c;成为一个不可或缺的平台。对于企业、营销人员和数据分析师来说&#xff0c;从小红书收集数据可以获得宝贵的洞察力&#xff0c;从而推动业务增长。虽然这…

使用sunshine和moonlight串流时的音频输出问题

设备&#xff1a;电脑和平板串流&#xff0c;把平板当副屏使用 1.如果启用安装steam音频驱动程序&#xff0c;则平板有声&#xff0c;电脑无声&#xff0c;在moonlight端可以设置平板和电脑同时发声&#xff0c;但是有点卡 2.只想电脑发声&#xff0c;平板无声 禁用安装steam…

活动预告 |【Part 2】Microsoft 安全在线技术公开课:通过扩展检测和响应抵御威胁

课程介绍 通过 Microsoft Learn 免费参加 Microsoft 安全在线技术公开课&#xff0c;掌握创造新机遇所需的技能&#xff0c;加快对 Microsoft Cloud 技术的了解。参加我们举办的“通过扩展检测和响应抵御威胁”技术公开课活动&#xff0c;了解如何更好地在 Microsoft 365 Defen…

网络工程师 (26)TCP/IP体系结构

一、层次 四层&#xff1a; 网络接口层&#xff1a;TCP/IP协议的最底层&#xff0c;负责网络层与硬件设备间的联系。该层协议非常多&#xff0c;包括逻辑链路和媒体访问控制&#xff0c;负责与物理传输的连接媒介打交道&#xff0c;主要功能是接收数据报&#xff0c;并把接收到…

GIS笔记之Shapefile与KML相互转换

在GIS应用中&#xff0c;各种不同类型数据的转换与使用是一个重要的环节。在这其中&#xff0c;Shapefile和KML是两种常见的数据形式&#xff0c;两者间的相互转换也是日常工作和学习绕不开的话题。在这里&#xff0c;我们将常用的几种数据转换方法整理如下。 1.Shapefile和KM…

【UVM】寄存器模型

寄存器模型的优势 sequence复用性高&#xff0c;方便对 DUT 中寄存器进行读写&#xff1b;提供了后门访问方式&#xff0c;可以不耗时的获取寄存器的值&#xff1b;可以很方便的对寄存器的 coverage 验证点的收集 寄存器模型基本概念 寄存器模型概念作用uvm_reg_field寄存器模…

WordPress博客在fnOS环境下的极简搭建与公网地址配置指南

文章目录 前言1. Docker下载源设置2. Docker下载WordPress3. Docker部署Mysql数据库4. WordPress 参数设置5. 飞牛云安装Cpolar工具6. 固定Cpolar公网地址7. 修改WordPress配置文件8. 公网域名访问WordPress 前言 你是否曾经为搭建自己的网站而头疼不已&#xff1f;是不是觉得…

计算机毕业设计SpringBoot校园二手交易小程序 校园二手交易平台(websocket消息推送+云存储+双端+数据统计)(源码+文档+运行视频+讲解视频)

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 作者简介&#xff1a;Java领…

2025年前端面试题~ 【前端面试】更新

前言 金三银四的招聘季即将来临&#xff0c;对于怀揣前端梦想的求职者而言&#xff0c;这是机遇与挑战并存的黄金时段。前端面试可不只是简单的问答&#xff0c;它是一场对综合能力的深度检验。面试官会从多个维度考量&#xff0c;比如扎实的 HTML、CSS 和 JavaScript 基础&…

从基础到人脸识别与目标检测

前言 从本文开始&#xff0c;我们将开始学习ROS机器视觉处理&#xff0c;刚开始先学习一部分外围的知识&#xff0c;为后续的人脸识别、目标跟踪和YOLOV5目标检测做准备工作。我采用的笔记本是联想拯救者游戏本&#xff0c;系统采用Ubuntu20.04&#xff0c;ROS采用noetic。 颜…

Photoshop自定义键盘快捷键

编辑 - 键盘快捷键 CtrlShiftAltK 把画笔工具改成Q , 橡皮擦改成W , 涂抹工具改成E , 增加和减小画笔大小A和S 偏好设置 - 透明度和色域 设置一样颜色 套索工具 可以自定义套选一片区域 Shiftf5 填充 CtrlU 可以改颜色/色相/饱和度 CtrlE 合并图层 CtrlShiftS 另存…

LSTM的介绍

网上一些描述LSTM文章看的云里雾里&#xff0c;只是介绍LSTM 的结构&#xff0c;并没有说明原理。我这里用通俗易懂的话来描述一下。 我们先来复习一些RNN的核心公式&#xff1a; h t t a n h ( W h h t − 1 W x x t b h ) h_t tanh(W_h h_{t-1} W_x x_t b_h) ht​tan…

C++ ——从C到C++

1、C的学习方法 &#xff08;1&#xff09;C知识点概念内容比较多&#xff0c;需要反复复习 &#xff08;2&#xff09;偏理论&#xff0c;有的内容不理解&#xff0c;可以先背下来&#xff0c;后续可能会理解更深 &#xff08;3&#xff09;学好编程要多练习&#xff0c;简…

AI技术填坑记2:标注系统

在问答中,通用大模型往往拥有不可控性,而在正常的业务系统里面,往往有自己的各种专门的术语和内容,标注系统可以对大量数据进行标记,确认大模型解答的结果符合设想。 一、总体思路 一个标注,一般分为模块、应用、提问词汇、标注值,其中,模块可以认为是一种应用分类;应…

【机器学习】超参数的选择,以kNN算法为例

分类准确度 一、摘要二、超参数的概念三、调参的方法四、实验搜索超参数五、扩展搜索范围六、考虑距离权重的kNN算法七、距离的计算方法及代码实现八、明可夫斯基距离的应用九、网格搜索超参数 一、摘要 本博文讲解了机器学习中的超参数问题&#xff0c;以K近邻算法为例&#…

哪吒闹海!SCI算法+分解组合+四模型原创对比首发!SGMD-FATA-Transformer-LSTM多变量时序预测

哪吒闹海&#xff01;SCI算法分解组合四模型原创对比首发&#xff01;SGMD-FATA-Transformer-LSTM多变量时序预测 目录 哪吒闹海&#xff01;SCI算法分解组合四模型原创对比首发&#xff01;SGMD-FATA-Transformer-LSTM多变量时序预测效果一览基本介绍程序设计参考资料 效果一览…

Django开发入门 – 3.用Django创建一个Web项目

Django开发入门 – 3.用Django创建一个Web项目 Build A Web Based Project With Django By JacksonML 本文简要介绍如何利用最新版Python 3.13.2来搭建Django环境&#xff0c;以及创建第一个Django Web应用项目&#xff0c;并能够运行Django Web服务器。 创建该Django项目需…

2025.2.8——二、Confusion1 SSTI模板注入|Jinja2模板

题目来源&#xff1a;攻防世界 Confusion1 目录 一、打开靶机&#xff0c;整理信息 二、解题思路 step 1&#xff1a;查看网页源码信息 step 2&#xff1a;模板注入 step 3&#xff1a;构造payload&#xff0c;验证漏洞 step 4&#xff1a;已确认为SSTI漏洞中的Jinjia2…

【C语言标准库函数】标准输入输出函数详解[5]:格式化文件输入输出

目录 一、fprintf() 函数 1.1. 函数简介 1.2. fprintf使用场景 1.3. 注意事项 1.4. 示例 二、fscanf() 函数 2.1. 函数简介 2.2. fscanf使用场景 2.3. 注意事项 2.3. 示例 三、总结 在 C 语言中&#xff0c;格式化文件输入输出函数能够让我们以特定的格式对文件进行…

【详细版】DETR系列之Deformable DETR(2021 ICLR)

论文标题Deformable DETR: Deformable Transformers for End-to-End Object Detection论文作者Xizhou Zhu, Weijie Su, Lewei Lu, Bin Li, Xiaogang Wang, Jifeng Dai发表日期2021年03月01日GB引用> Xizhou Zhu, Weijie Su, Lewei Lu, et al. Deformable DETR: Deformable T…