本例为给标注加前缀,也可定制其他形式,效果如下:
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);
}
}
}
插件联系↓↓↓