editor试过了,有问题,呵呵
Com调用的方式还可以,不过命令提示会消失掉 - using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using TlsCad.Trans;
- using Autodesk.AutoCAD.EditorInput;
- using System.Reflection;
- namespace TlsCad
- {
- class Work
- {
- public Document _doc;
- private object _acUtility;
- static Type _acUtilityType;
- private Timer t;
- private bool m_Starting = false;
- public Work(Document doc)
- {
- _doc = doc;
- object acDoc = _doc.AcadDocument;
- Type acDocType = Type.GetTypeFromHandle(Type.GetTypeHandle(acDoc));
- _acUtility = acDocType.InvokeMember("Utility", BindingFlags.GetProperty, null, acDoc, new object[0]);
- _acUtilityType = Type.GetTypeFromHandle(Type.GetTypeHandle(_acUtility));
- t = new Timer(DoWork, null, 500, 3000);
- }
- public void DoWork(object sender)
- {
- if (!_doc.IsDisposed)
- {
- if (!m_Starting)
- {
- m_Starting = true;
- if (_doc.Editor.IsQuiescent)
- {
- try
- {
- _acUtilityType.InvokeMember
- (
- "prompt",
- BindingFlags.InvokeMethod,
- null,
- _acUtility,
- new object[] { DateTime.Now.ToString() + "\r\n" }
- );
- }
- catch
- { }
- }
- m_Starting = false;
- }
- }
- }
- }
- }
|