123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI;
- using SAGA.RevitUtils.Extends;
- using TSZ.RevitBaseDll.Extends;
- namespace SAGA.RevitUtils.Windows
- {
- public class ExecuteCmd
- {
- private static TIdlingExternalEvent _externalEventObject;
-
- public static void ExecuteCommand(ExecuteCommandHandler executeHandler)
- {
- RaisedCallback callback = null;
- try
- {
- if (callback == null)
- {
- callback = param0 => executeHandler();
- }
- ExternalEventObject.Raise(callback);
- }
- catch (Exception exception)
- {
- MessageShow.Show(exception, false, "");
- }
- }
- public static void ExecuteCommandOnce(ExecuteCommandHandler executeHandler, ExecuteCommandHandler executeHandlerCallBack)
- {
- if (executeHandler == null)
- {
- throw new ArgumentNullException("executeHandler");
- }
- if (executeHandlerCallBack == null)
- {
- throw new ArgumentNullException("executeHandlerCallBack");
- }
- try
- {
- bool isRuned = false;
- Timer timer = new Timer {
- Interval = 2
- };
- timer.Tick += delegate (object sender, EventArgs e) {
- if (isRuned)
- {
- timer.Stop();
- executeHandlerCallBack();
- }
- };
- timer.Start();
- ExternalEventObject.Raise(delegate (ExternalEventExecuteEventArgs param0) {
- executeHandler();
- isRuned = true;
- });
- }
- catch (Exception exception)
- {
- MessageShow.Show(exception, false, "");
- }
- }
- public static void RevitCommand(PostableCommand cmd)
- {
- ExecuteCommandOnce(delegate {
- Application.DoEvents();
- ExternalDataWrapper.Current.UiApp.PostCommand(cmd);
- Application.DoEvents();
- return Result.Succeeded;
- }, () => Result.Succeeded);
- }
- private static TIdlingExternalEvent ExternalEventObject
- {
- get
- {
- if ((_externalEventObject == null) || _externalEventObject.Disposeed)
- {
- TszExternalEventHandler handler = new TszExternalEventHandler();
- _externalEventObject = TIdlingExternalEvent.Create(handler);
- }
- return _externalEventObject;
- }
- }
- public delegate Result CurveDrawnHandler(List<Curve> clist);
- public delegate Result ExecuteCommandHandler();
- }
- }
|