39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Autodesk.Revit.DB;
|
|
|
|
namespace ShrlAlgoToolkit.RevitCore.Base
|
|
{
|
|
public abstract class BaseCommand : IExternalCommand
|
|
{
|
|
// 封装常用属性,方便直接调用
|
|
public ExternalCommandData CommandData { get; private set; }
|
|
public UIApplication UiApplication => CommandData?.Application;
|
|
public UIDocument UiDocument => UiApplication?.ActiveUIDocument;
|
|
public Autodesk.Revit.ApplicationServices.Application Application => UiApplication?.Application;
|
|
public Document Document => UiDocument?.Document;
|
|
|
|
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
|
{
|
|
CommandData = commandData;
|
|
|
|
try
|
|
{
|
|
ExecuteCommand();
|
|
return Result.Succeeded;
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
return Result.Cancelled;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
message = ex.Message;
|
|
TaskDialog.Show("Command Error", ex.ToString());
|
|
return Result.Failed;
|
|
}
|
|
}
|
|
|
|
// 留给具体命令去实现的核心方法
|
|
protected abstract void ExecuteCommand();
|
|
}
|
|
}
|