c# - 重叠实体的文本 (AutoCAD/C#)
问题描述
我正在尝试修改MText.Contents
实体,但是您可以看到新字符串“123”与原始字符串完全重叠,你好。
这是代码(我已经尝试了注释部分,但到目前为止还没有运气)。
//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();
}
}
推荐阅读
- angular - debounceTime rxjs 运算符和输入 keyup 函数的 http 请求问题
- r - 从另一个数据框 r 中添加/减去数据框行
- android - 使用相同布局中的过渡动画布局更改
- python - 我的脚本没有提取所有广告详细信息,而且我没有得到正确的数字
- javascript - 使用“chrome.webNavigation.onCompleted.addListener”时获取“”Uncaught TypeError:无法添加侦听器“
- android - Recyclerview 不显示警报对话框中的数据列表
- ajax - 块上传不适用于大文件 - Laravel 5.8
- aws-lambda - 如何从 Postman 调用受授权人保护的 Lambda?
- powershell - 如何使用 PSM1 文件安装模块?
- sql-server - 在 SQL JOB 中运行 BCP 命令时出错