- 积分
- 1655
- 明经币
- 个
- 注册时间
- 2008-5-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
//替换文字
public static void RePlaceText(string fileName)
{
try
{
Database dbDwgFile = new Database(false, true);
dbDwgFile.ReadDwgFile(fileName, System.IO.FileShare.ReadWrite, true, null);
using (Transaction OldTrans = dbDwgFile.TransactionManager.StartTransaction())
{
BlockTable bt = OldTrans.GetObject(dbDwgFile.BlockTableId, OpenMode.ForNotify) as BlockTable;
BlockTableRecord btr = OldTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForNotify) as BlockTableRecord;
foreach (ObjectId id in btr)
{
if (id.IsErased)
{
continue;
}
Entity ent = OldTrans.GetObject(id, OpenMode.ForWrite) as Entity;
if (ent.GetType().Name == "DBText")
{
DBText text1 = ent as DBText;
if (text1.TextString.Contains("被替换"))
{
text1.TextString = text1.TextString.Replace("被替换", "正在试验");
}
}
else if (ent.GetType().Name == "MText")
{
MText text1 = ent as MText;
if (text1.Contents.Contains("被替换"))
{
text1.Contents = text1.Contents.Replace("被替换", "正在试验");
}
}
}
OldTrans.Commit();
}
// dbDwgFile.Save();如果不注释掉, 这句会出错,请大家帮忙看下应该怎么写?
}
catch
{
System.Windows.Forms.MessageBox.Show("替换错误", "提示");
}
finally
{
}
}
|
|