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

          }

      }
  }

插件联系↓↓↓

相关推荐
我才是银古6 小时前
当 GIS 开发遇上 .NET:一个 GDAL 集成工具库的架构设计与实践
c#·gis·gdal
Hesionberger7 小时前
快速求解完全平方数的最少数量
开发语言·数据结构·python·算法·leetcode·c#
逝水无殇20 小时前
C# 运算符重载详解
开发语言·后端·c#
丁小未1 天前
基于MVVM框架的XUUI HelloWorld 新手教程
unity·性能优化·c#·游戏引擎
ctrl_v助手1 天前
C#日志工具类log4net的使用
开发语言·c#
Jazz_z1 天前
通过 Java 实现 Word 转 TXT
java·c#·word
丁小未1 天前
基于MVVM框架的XUUI MoreComplex案例
unity·c#
ctrl_v助手1 天前
C#表达题笔记
开发语言·c#
geovindu1 天前
CSharp: Dijkstra Algorithms
开发语言·后端·算法·c#
公子小六1 天前
基于.NET的Windows窗体编程之WinForms图像控件
windows·microsoft·c#·.net·winforms