forked from architecture-building-systems/revitpythonshell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
743 additions
and
717 deletions.
There are no files selected for viewing
1,237 changes: 619 additions & 618 deletions
1,237
...ythonShell/RevitPythonShellApplication.cs → RevitPythonShell/App.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 63 additions & 65 deletions
128
RevitPythonShell/CommandLoaderBase.cs → ...nShell/RevitCommands/CommandLoaderBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,63 @@ | ||
using System; | ||
using System.IO; | ||
using Autodesk.Revit; | ||
using Autodesk.Revit.UI; | ||
using Autodesk.Revit.DB; | ||
using Autodesk.Revit.Attributes; | ||
using RpsRuntime; | ||
|
||
namespace RevitPythonShell | ||
{ | ||
/// <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> | ||
[Regeneration(RegenerationOption.Manual)] | ||
[Transaction(TransactionMode.Manual)] | ||
public abstract class CommandLoaderBase : IExternalCommand | ||
{ | ||
protected string _scriptSource = ""; | ||
|
||
public CommandLoaderBase(string scriptSource) | ||
{ | ||
_scriptSource = scriptSource; | ||
} | ||
|
||
/// <summary> | ||
/// Overload this method to implement an external command within Revit. | ||
/// </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> | ||
/// <param name="commandData">An ExternalCommandData object which contains reference to Application and View | ||
/// needed by external command.</param><param name="message">Error message can be returned by external command. This will be displayed only if the command status | ||
/// was "Failed". There is a limit of 1023 characters for this message; strings longer than this will be truncated.</param><param name="elements">Element set indicating problem elements to display in the failure dialog. This will be used | ||
/// only if the command status was "Failed".</param> | ||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) | ||
{ | ||
// FIXME: somehow fetch back message after script execution... | ||
var executor = new ScriptExecutor(RevitPythonShellApplication.GetConfig(), commandData, message, elements); | ||
|
||
string source; | ||
using (var reader = File.OpenText(_scriptSource)) | ||
{ | ||
source = reader.ReadToEnd(); | ||
} | ||
|
||
var result = executor.ExecuteScript(source, _scriptSource); | ||
message = executor.Message; | ||
switch (result) | ||
{ | ||
case (int)Result.Succeeded: | ||
return Result.Succeeded; | ||
case (int)Result.Cancelled: | ||
return Result.Cancelled; | ||
case (int)Result.Failed: | ||
return Result.Failed; | ||
default: | ||
return Result.Succeeded; | ||
} | ||
} | ||
} | ||
} | ||
using System.IO; | ||
using Autodesk.Revit.Attributes; | ||
using Autodesk.Revit.DB; | ||
using Autodesk.Revit.UI; | ||
using RpsRuntime; | ||
|
||
namespace RevitPythonShell.RevitCommands | ||
{ | ||
/// <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> | ||
[Regeneration(RegenerationOption.Manual)] | ||
[Transaction(TransactionMode.Manual)] | ||
public abstract class CommandLoaderBase : IExternalCommand | ||
{ | ||
protected string _scriptSource = ""; | ||
|
||
public CommandLoaderBase(string scriptSource) | ||
{ | ||
_scriptSource = scriptSource; | ||
} | ||
|
||
/// <summary> | ||
/// Overload this method to implement an external command within Revit. | ||
/// </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> | ||
/// <param name="commandData">An ExternalCommandData object which contains reference to Application and View | ||
/// needed by external command.</param><param name="message">Error message can be returned by external command. This will be displayed only if the command status | ||
/// was "Failed". There is a limit of 1023 characters for this message; strings longer than this will be truncated.</param><param name="elements">Element set indicating problem elements to display in the failure dialog. This will be used | ||
/// only if the command status was "Failed".</param> | ||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) | ||
{ | ||
// FIXME: somehow fetch back message after script execution... | ||
var executor = new ScriptExecutor(App.GetConfig(), commandData, message, elements); | ||
|
||
string source; | ||
using (var reader = File.OpenText(_scriptSource)) | ||
{ | ||
source = reader.ReadToEnd(); | ||
} | ||
|
||
var result = executor.ExecuteScript(source, _scriptSource); | ||
message = executor.Message; | ||
switch (result) | ||
{ | ||
case (int)Result.Succeeded: | ||
return Result.Succeeded; | ||
case (int)Result.Cancelled: | ||
return Result.Cancelled; | ||
case (int)Result.Failed: | ||
return Result.Failed; | ||
default: | ||
return Result.Succeeded; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RevitAddIns> | ||
<AddIn Type="Application"> | ||
<FullClassName>RevitPythonShell.App</FullClassName> | ||
<ClientId>3a7a1d24-51ed-462b-949f-1ddcca12008d</ClientId> | ||
<Name>RevitPythonShell</Name> | ||
<Assembly>RevitPythonShell/RevitPythonShell.dll</Assembly> | ||
<VendorId>3a7a1d24-51ed-462b-949f-1ddcca12008d</VendorId> | ||
<VendorDescription>RIPS, RIPS, </VendorDescription> | ||
</AddIn> | ||
</RevitAddIns> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters