明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2354|回复: 4

定时提示

[复制链接]
发表于 2010-2-4 13:35 | 显示全部楼层 |阅读模式
能不能定义一个timer,每隔一定时间在命令行写入时间实现报时功能呢?我尝试写过一个,但是timer事件里面取不到editor
发表于 2010-2-4 18:46 | 显示全部楼层
你的代码?试下文档加锁
 楼主| 发表于 2010-2-5 00:06 | 显示全部楼层

写一段利用timer的Elapsed事件在命令行里写一些信息的代码看看

发表于 2010-2-5 10:55 | 显示全部楼层
editor试过了,有问题,呵呵
Com调用的方式还可以,不过命令提示会消失掉
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using Autodesk.AutoCAD.ApplicationServices;
  6. using Autodesk.AutoCAD.DatabaseServices;
  7. using Autodesk.AutoCAD.Geometry;
  8. using TlsCad.Trans;
  9. using Autodesk.AutoCAD.EditorInput;
  10. using System.Reflection;
  11. namespace TlsCad
  12. {
  13.     class Work
  14.     {
  15.         public Document _doc;
  16.         private object _acUtility;
  17.         static Type _acUtilityType;
  18.         private Timer t;
  19.         private bool m_Starting = false;
  20.         public Work(Document doc)
  21.         {
  22.             _doc = doc;
  23.             object acDoc = _doc.AcadDocument;
  24.             Type acDocType = Type.GetTypeFromHandle(Type.GetTypeHandle(acDoc));
  25.             _acUtility = acDocType.InvokeMember("Utility", BindingFlags.GetProperty, null, acDoc, new object[0]);
  26.             _acUtilityType = Type.GetTypeFromHandle(Type.GetTypeHandle(_acUtility));
  27.             t = new Timer(DoWork, null, 500, 3000);
  28.         }
  29.         public void DoWork(object sender)
  30.         {
  31.             if (!_doc.IsDisposed)
  32.             {
  33.                 if (!m_Starting)
  34.                 {
  35.                     m_Starting = true;
  36.                     if (_doc.Editor.IsQuiescent)
  37.                     {
  38.                         try
  39.                         {
  40.                             _acUtilityType.InvokeMember
  41.                             (
  42.                                 "prompt",
  43.                                 BindingFlags.InvokeMethod,
  44.                                 null,
  45.                                 _acUtility,
  46.                                 new object[] { DateTime.Now.ToString() + "\r\n" }
  47.                             );
  48.                         }
  49.                         catch
  50.                         { }
  51.                     }
  52.                     m_Starting = false;
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }
发表于 2010-2-5 10:56 | 显示全部楼层
  1.         [CommandMethod("tt")]
  2.         public static void Test()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Work w = new Work(doc);
  6.         }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 21:59 , Processed in 2.130358 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表