Cad c#.net 一键修改标注dimension中的文本内容

本例为给标注加前缀,也可定制其他形式,效果如下:

cs 复制代码
  public class Demo
  {
      [CommandMethod("xx")]//
      public void Dim()
      {
          Document doc = Application.DocumentManager.MdiActiveDocument;

          Database db = doc.Database;

          Editor ed = doc.Editor;
          try

          {
              using (Transaction tr = db.TransactionManager.StartTransaction())

              {
                  BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                  BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                  foreach (ObjectId dimId in btr)

                  {

                      if (dimId.ObjectClass.Name.ToLower().Contains("dimension"))

                      {

                          Dimension dim = (Dimension)tr.GetObject(dimId, OpenMode.ForWrite);

                          string originalText = dim.DimensionText;
                          string measureText = Math.Round( dim.Measurement,3).ToString();
                          if (!string.IsNullOrEmpty(originalText))

                          {

                              dim.DimensionText = "dzb_"+ originalText ;

                          }

                          else
                          { dim.DimensionText = "dzb_" + measureText; }
                          if (!string.IsNullOrEmpty(measureText))

                          {


                              ed.WriteMessage($"\n{measureText}\n");

                          }

                      }

                  }

                  tr.Commit();

                  ed.WriteMessage("\n修改标注文本前缀成功。");
              }

          }

          catch (System.Exception ex)

          {

              ed.WriteMessage("\n发生错误: " + ex.Message);

          }

      }
  }

插件联系↓↓↓

相关推荐
创可贴治愈心灵10 分钟前
WPF中UI线程频繁操作造成卡顿的处理
ui·c#·wpf
格林威5 小时前
Baumer工业相机堡盟工业相机如何通过YoloV8深度学习模型和EasyOCR实现汽车牌照动态检测和识别(C#代码,UI界面版)
人工智能·深度学习·数码相机·yolo·c#·汽车·视觉检测
Aczone285 小时前
Linux 软件编程(九)网络编程:IP、端口与 UDP 套接字
linux·网络·网络协议·tcp/ip·http·c#
chenglin0167 小时前
C#_接口设计:角色与契约的分离
java·前端·c#
谷宇.20 小时前
【Unity3D实例-功能-拔枪】角色拔枪(三)IK的使用-紧握武器
游戏·unity·c#·unity3d·游戏开发·游戏编程·steam
用户8356290780511 天前
C# 从 PDF 提取图片教程
后端·c#
格林威1 天前
Baumer高防护相机如何通过YoloV8深度学习模型实现网球运动员和网球速度的检测分析(C#代码UI界面版)
人工智能·深度学习·数码相机·yolo·ui·c#·视觉检测
hixiong1231 天前
用OpencvSharp编写视频录制工具
opencv·c#·音视频
张飞洪1 天前
C# 13 与 .NET 9 跨平台开发实战:基于.NET 9 与 EF Core 9 的现代网站与服务开发
开发语言·c#·.net