-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
48 changed files
with
853 additions
and
111 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,43 @@ | ||
using System; | ||
using Autodesk.Revit.Attributes; | ||
using Autodesk.Revit.UI; | ||
|
||
namespace PyRevitRunner { | ||
[Regeneration(RegenerationOption.Manual)] | ||
[Transaction(TransactionMode.Manual)] | ||
class PyRevitRunnerApplication : IExternalApplication { | ||
// Hook into Revit to allow starting a command. | ||
Result IExternalApplication.OnStartup(UIControlledApplication application) { | ||
try { | ||
return RegisterExternalCommand(application); | ||
} | ||
catch (Exception ex) { | ||
TaskDialog.Show("Error Loading Script Runner Application", ex.ToString()); | ||
return Result.Failed; | ||
} | ||
} | ||
|
||
private static Result RegisterExternalCommand(UIControlledApplication application) { | ||
var assembly = typeof(PyRevitRunnerApplication).Assembly; | ||
|
||
RibbonPanel ribbonPanel = application.CreateRibbonPanel("pyRevitRunner"); | ||
|
||
// Run service button | ||
var pbData = new PushButtonData( | ||
"PyRevitRunnerCommand", | ||
"PyRevitRunnerCommand", | ||
assembly.Location, | ||
"PyRevitRunner.PyRevitRunnerCommand"); | ||
pbData.AvailabilityClassName = "PyRevitRunner.PyRevitRunnerCommandAvail"; | ||
|
||
ribbonPanel.AddItem(pbData); | ||
|
||
return Result.Succeeded; | ||
} | ||
|
||
Result IExternalApplication.OnShutdown(UIControlledApplication application) { | ||
// FIXME: deallocate the python shell... | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Autodesk.Revit.Attributes; | ||
using Autodesk.Revit.UI; | ||
using Autodesk.Revit.DB; | ||
|
||
using PyRevitLoader; | ||
using System.Reflection; | ||
using System.IO; | ||
|
||
namespace PyRevitRunner { | ||
[Regeneration(RegenerationOption.Manual)] | ||
[Transaction(TransactionMode.Manual)] | ||
public class PyRevitRunnerCommand : IExternalCommand { | ||
|
||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { | ||
// grab application and command data, skip elements since this is a batch runner and user doesn't | ||
// see the gui to make selections | ||
Application = commandData.Application; | ||
CommandData = commandData; | ||
|
||
try { | ||
// 1 | ||
// Processing Journal Data and getting the script path to be executed in IronPython engine | ||
IDictionary<string, string> dataMap = commandData.JournalData; | ||
ScriptSourceFile = dataMap["ScriptSource"]; | ||
ModuleSearchPaths = new List<string>(dataMap["SearchPaths"].Split(';')); | ||
ModelPaths = new List<string>(); | ||
var modelPaths = dataMap["Models"]; | ||
if (modelPaths != null && modelPaths != string.Empty) | ||
ModelPaths.AddRange(modelPaths.Split(';')); | ||
LogFile = dataMap["LogFile"]; | ||
|
||
// add pyrevit library path and script directory path to search paths | ||
ModuleSearchPaths.Add(GetPyRevitLibsPath()); | ||
ModuleSearchPaths.Add(GetSitePkgsPath()); | ||
ModuleSearchPaths.Add(Path.GetDirectoryName(ScriptSourceFile)); | ||
|
||
// 2 | ||
// Executing the script | ||
var executor = new ScriptExecutor(Application, fullFrame: true); // uiControlledApplication); | ||
var resultCode = executor.ExecuteScript( | ||
ScriptSourceFile, | ||
sysPaths: ModuleSearchPaths.ToArray(), | ||
logFilePath: LogFile, | ||
variables: new Dictionary<string, object>() { | ||
{"__batchexec__", true }, | ||
{"__logfile__", LogFile }, | ||
{"__models__", ModelPaths }, | ||
}); | ||
|
||
// 3 | ||
// Log results | ||
if (resultCode == 0) | ||
return Result.Succeeded; | ||
else | ||
return Result.Cancelled; | ||
} | ||
catch (Exception ex) { | ||
commandData.JournalData.Add("pyRevitRunner Execution Failure", ex.Message); | ||
return Result.Cancelled; | ||
} | ||
} | ||
|
||
public UIApplication Application { get; private set; } | ||
public ExternalCommandData CommandData { get; private set; } | ||
|
||
public string ScriptSourceFile { get; private set; } | ||
public List<string> ModuleSearchPaths { get; private set; } | ||
public List<string> ModelPaths { get; private set; } | ||
public string LogFile { get; private set; } | ||
public bool DebugMode { get; private set; } | ||
|
||
private static string GetDeployPath() { | ||
var loaderDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
var engineDir = Path.GetDirectoryName(loaderDir); | ||
var binDir = Path.GetDirectoryName(engineDir); | ||
return Path.GetDirectoryName(binDir); | ||
} | ||
|
||
private static string GetPyRevitLibsPath() => Path.Combine(GetDeployPath(), "pyrevitlib"); | ||
private static string GetSitePkgsPath() => Path.Combine(GetDeployPath(), "site-packages"); | ||
} | ||
|
||
|
||
public class PyRevitRunnerCommandAvail : IExternalCommandAvailability { | ||
public PyRevitRunnerCommandAvail() { | ||
} | ||
|
||
public bool IsCommandAvailable(UIApplication uiApp, CategorySet selectedCategories) { | ||
return true; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.