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);

          }

      }
  }

插件联系↓↓↓

相关推荐
huaqianzkh1 天前
WinForm C#:循环修改控件UI闪烁卡顿?SuspendLayout / ResumeLayout 与 BeginUpdate 优化
开发语言·ui·c#
用户3721574261352 天前
C# 实现 Excel 单元格保护:锁定公式并允许编辑指定区域
c#·ai编程·编程语言
公子小六2 天前
基于.NET的Windows窗体编程之WinForms数据持久化(1)
windows·microsoft·c#·.net·winforms
三雷科技2 天前
第6章第4节:自定义分词器
开发语言·c#
zhanghaha13142 天前
C# 系列教程_12 字符串 string 保姆级系统教程(面向新手,大量示例 + 原理讲解)
开发语言·数据库·c#
Coder_Shenshen3 天前
罗克韦尔ACD工程归档离线变量树解析
算法·c#
寂寞的船3 天前
【Unity知识速递】第10期 Unity GC 零分配实战:从 UnityEngine.Pool 到手动 GC 控制的全链路优化
jvm·unity·c#·游戏引擎·lucene
1-1=03 天前
C# 数据结构和特殊类型
数据结构·c#·.net·.netcore
波力海苔夹心脆6755 天前
C# WPF 资源字典详解:ResourceDictionary、MergedDictionaries 与自定义控件案例
开发语言·c#·wpf·入门教程·resource·资源字典
AI导出鸭PC端5 天前
Perplexity批量导出没有PDF模式?AI导出鸭插件补上最后一块拼图
人工智能·pdf·c#·ai导出鸭