C# 重叠图元的文本(AutoCAD/C)
我试图修改MText.Contents实体,但正如您所看到的,新字符串123与原始字符串完全重叠,H e l o 这是我试过注释部分的代码,但到目前为止运气不好C# 重叠图元的文本(AutoCAD/C),c#,text,autocad,overlapping,C#,Text,Autocad,Overlapping,我试图修改MText.Contents实体,但正如您所看到的,新字符串123与原始字符串完全重叠,H e l o 这是我试过注释部分的代码,但到目前为止运气不好 //BlockTableRecord btrr = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(curdb), OpenMode.ForWrite); BlockTableRecord btrr = bt[BlockTableReco
//BlockTableRecord btrr = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(curdb), OpenMode.ForWrite);
BlockTableRecord btrr = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId id in btrr)
{
Entity currentEntity = tr.GetObject(id, OpenMode.ForWrite, false, true) as Entity;
//Entity currentEntity = tr.GetObject(id, OpenMode.ForWrite, true) as Entity;
if (currentEntity == null)
{
continue;
}
if (currentEntity.GetType() == typeof(MText))
{
if (((MText)currentEntity).Contents == "H e l l o")
{
//currentEntity.UpgradeOpen();
((MText)currentEntity).Contents = "123";
//currentEntity.DowngradeOpen();
// TextEditor textEditor = TextEditor.CreateTextEditor((MText)currentEntity);
// textEditor.SelectAll();
// TextEditorSelection selection = textEditor.Selection;
// selection.InsertString("123");
// textEditor.Close(TextEditor.ExitStatus.ExitSave);
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(((MText)currentEntity).Contents + "--MText");
}
}
}
AlertDialog文本为123,这是新的
谢谢 这对我很有用:
[CommandMethod("TEST")]
public static void Test()
{
var db = HostApplicationServices.WorkingDatabase;
using (var tr = db.TransactionManager.StartTransaction())
{
var ms = (BlockTableRecord)tr.GetObject(
SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
foreach (ObjectId id in ms)
{
if (id.ObjectClass == RXObject.GetClass(typeof(MText)))
{
var mtext = (MText)tr.GetObject(id, OpenMode.ForRead);
if (mtext.Contents == "H e l l o")
{
tr.GetObject(id, OpenMode.ForWrite);
mtext.Contents = "123";
}
}
}
tr.Commit();
}
}
谢谢实际上是从serverStream下载的DWG文件,字节。。。爆炸后等等。我找到了你能从答案中看出的问题。我也喜欢你的方法。
BlockTableRecord btrec = (BlockTableRecord)blkid.GetObject(OpenMode.ForRead);
btrec.UpgradeOpen();
btrec.DowngradeOpen();
foreach (ObjectId index in btrec)
{
Entity en = (Entity)index.GetObject(OpenMode.ForRead);
AttributeDefinition adef = en as AttributeDefinition;
if (adef != null)
{
ed.WriteMessage("\n" + adef.Tag);
}
foreach (ObjectId id in btrec)
{
Entity currentEntity = (Entity)id.GetObject(OpenMode.ForWrite);
if (currentEntity == null)
{
continue;
}
if (currentEntity.GetType() == typeof(MText))
{
if (((MText)currentEntity).Contents == "H E L L O")
{
((MText)currentEntity).Contents = "123";
}
}
}