调整代码
This commit is contained in:
42
ShrlAlgoToolkit.RevitCore/Base/BaseCommand.cs
Normal file
42
ShrlAlgoToolkit.RevitCore/Base/BaseCommand.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user