-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathCommandLoaderBase.cs
More file actions
47 lines (40 loc) · 1.49 KB
/
CommandLoaderBase.cs
File metadata and controls
47 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using CADPythonShell.App;
using CADRuntime;
using System.IO;
namespace CADPythonShell.Command
{
/// <summary>
/// Starts up a ScriptOutput window for a given canned command.
///
/// It is expected that this will be inherited by dynamic types that have the field
/// _scriptSource set to point to a python file that will be executed in the constructor.
/// </summary>
public abstract class CommandLoaderBase
{
protected string _scriptSource;
private CommandLoaderBase(string scriptSource)
{
_scriptSource = scriptSource;
}
/// <summary>
/// Overload this method to implement an external command within CAD.
/// </summary>
/// <returns>
/// The result indicates if the execution fails, succeeds, or was canceled by user. If it does not
/// succeed, Revit will undo any changes made by the external command.
/// </returns>
private int Execute(ref string message, params string[] parameters)
{
// FIXME: somehow fetch back message after script execution...
var executor = new ScriptExecutor(CADPythonShellApplication.GetConfig());
string source;
using (var reader = File.OpenText(_scriptSource))
{
source = reader.ReadToEnd();
}
var result = executor.ExecuteScript(source, _scriptSource);
message = executor.Message;
return result;
}
}
}