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

          }

      }
  }

插件联系↓↓↓

相关推荐
cjp56021 小时前
012.UG二次开发,UG管道服务器与WPF管道通讯,传输JSON数据
c#
jiushidt1 天前
ArcGIS Pro Add‑in 打包流程详解
arcgis·c#·.net·arcgispro
geovindu2 天前
CSharp: Observer Pattern
开发语言·后端·观察者模式·设计模式·c#·.netcore·行为模式
软件黑马王子2 天前
20.Resources资源加载:基本实现
开发语言·前端框架·c#
张人玉2 天前
基于 C# / .NET 8 + Windows Forms + SQLite 的桌面银行业务演示系统——华夏示范银行管理系统
windows·sqlite·c#·.net
1314lay_10072 天前
C#调用Sql Server存储过程,并且使用传入表结构
数据库·经验分享·笔记·sqlserver·c#
慧都小妮子2 天前
.NET 报表控件选型对比:Stimulsoft 与 FastReport 怎么选
c#·.net·报表开发·数据可视化·报表控件·报表引擎选型
1314lay_10072 天前
C#调用Sql Server存储过程,有返回值的
数据库·sqlserver·c#
我是唐青枫2 天前
C#.NET PInvoke 深入解析:封送、内存布局与原生互操作实战
开发语言·c#·.net
Am-Chestnuts2 天前
AI 生成的数学公式,怎么用 DS随心转 导出成 Word 里能改的公式
人工智能·c#·word