本帖最后由 Bao_lai 于 2025-6-8 21:21 编辑
PS:我这边用这个入口点,发现这个入口点对天正的单行和多行文字可以通用,不过有一个小问题,每个图元仅能操作一次,如果对已经操作过的图元第二次操作时,就会崩溃掉。不知道你那边测试有没有这样的情况。
 - using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Runtime;
- using System.Runtime.InteropServices;
- namespace CAD_天正文字
- {
- public static class Class1
- {
- //天正多行文字
- [DllImport("tch_kernal.arx", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, EntryPoint = "?GetText@TDbText@@QEBAPEB_WXZ")]
- private static extern string GetText_Native(IntPtr tchMText);
- [CommandMethod("TT")]
- public static void TT()
- {
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- TypedValue[] values = new TypedValue[1];
- values.SetValue(new TypedValue((int)DxfCode.Start, "TCH_TEXT,TCH_MTEXT"), 0);
- SelectionFilter filter = new SelectionFilter(values);
- PromptSelectionOptions pso = new PromptSelectionOptions();
- pso.MessageForAdding = "\n请选择天正文字对象";
- pso.RejectObjectsOnLockedLayers = true;
- PromptSelectionResult psr = ed.GetSelection(pso, filter);
- if (psr.Status != PromptStatus.OK) { return; }
- SelectionSet sSt = psr.Value;
- using (Transaction trans = doc.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btrMs = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- foreach (ObjectId id in sSt.GetObjectIds())
- {
- Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead);
- string tchText = GetText_Native(ent.UnmanagedObject);
- ed.WriteMessage("\n" + tchText);
- }
- trans.Commit();
- }
- }
- }
- }
|