- 积分
- 4400
- 明经币
- 个
- 注册时间
- 2015-1-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 qq1254582201 于 2022-6-9 15:20 编辑
- using System;
- using System.Runtime.InteropServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
-
- [assembly: CommandClass(typeof(FieldDialog.Utils))]
-
- namespace FieldDialog
- {
- public class Utils
- {
- [DllImport("AcFdUi.arx", CallingConvention = CallingConvention.StdCall, EntryPoint = "AcFdUiInvokeFieldDialog")]
- private static extern Int32 InvokeFieldDialog(ref IntPtr fd, Int32 bEdit, IntPtr pDb, IntPtr pParent);
-
- [CommandMethod("InsField", CommandFlags.Modal)]
- public void InsField()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- if (doc == null) return;
- Database db = doc.Database;
- Editor ed = doc.Editor;
-
- PromptPointResult ppr =
- ed.GetPoint("\nУкажите точку вставки мультитекста: ");
- if (ppr.Status != PromptStatus.OK) return;
-
- using (Field fd = new Field())
- {
- IntPtr ptr = fd.UnmanagedObject;
- InvokeFieldDialog(ref ptr, 1, db.UnmanagedObject, IntPtr.Zero);
- using (BlockTableRecord curSpace =
- db.CurrentSpaceId.Open(OpenMode.ForWrite) as BlockTableRecord)
- {
- using (MText mt = new MText())
- {
- mt.Location = ppr.Value;
- curSpace.AppendEntity(mt);
- mt.SetField("TEXT", fd);
- fd.Evaluate((int)FieldEvaluationContext.Demand, db);
- }
- }
- }
- }
- }
- }
|
|