修改文字内容后不能保存???
//替换文字
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, 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
{
}
}
public void SaveAs(string fileName, Autodesk.AutoCAD.DatabaseServices.DwgVersion version)
Autodesk.AutoCAD.DatabaseServices.Database 的成员
-------------------------
使用这个试试 dbDwgFile.SaveAs(fileName, DwgVersion.Current) 用这句可以了,感谢sieben ,昨晚研究这个问题到2点都没有搞出来,睡觉也不踏实,早晨起来第一件事就是看贴,现在灰常开心。 不过能否解释一下为什么.save()会报错吗??
页:
[1]