Skip to content

Commit 8b4534e

Browse files
committed
v4.6.11
2 parents 745591e + 17d083c commit 8b4534e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+853
-111
lines changed

bin/engines/273/pyRevitLoader.dll

1 KB
Binary file not shown.

bin/engines/273/pyRevitLoader.pdb

0 Bytes
Binary file not shown.

bin/engines/273/pyRevitRunner.dll

2.46 MB
Binary file not shown.

bin/engines/273/pyRevitRunner.pdb

35.5 KB
Binary file not shown.

bin/engines/277/pyRevitLoader.dll

1 KB
Binary file not shown.

bin/engines/277/pyRevitLoader.pdb

0 Bytes
Binary file not shown.

bin/engines/277/pyRevitRunner.dll

3.47 MB
Binary file not shown.

bin/engines/277/pyRevitRunner.pdb

35.5 KB
Binary file not shown.

bin/engines/278/pyRevitLoader.dll

1 KB
Binary file not shown.

bin/engines/278/pyRevitLoader.pdb

0 Bytes
Binary file not shown.

bin/engines/278/pyRevitRunner.dll

3.56 MB
Binary file not shown.

bin/engines/278/pyRevitRunner.pdb

35.5 KB
Binary file not shown.

bin/engines/279/pyRevitLoader.dll

1 KB
Binary file not shown.

bin/engines/279/pyRevitLoader.pdb

0 Bytes
Binary file not shown.

bin/engines/279/pyRevitRunner.dll

3.58 MB
Binary file not shown.

bin/engines/279/pyRevitRunner.pdb

35.5 KB
Binary file not shown.

bin/engines/pyRevitLoader.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
#pylint: disable=C0103,W1401,E0401,E0602
23
"""
34
██▓███▓██ ██▓ ██▀███ ▓█████ ██▒ █▓ ██▓▄▄▄█████▓
45
▓██░ ██▒██ ██▒▓██ ▒ ██▒▓█ ▀▓██░ █▒▓██▒▓ ██▒ ▓▒

bin/pyRevitLabs.Common.dll

512 Bytes
Binary file not shown.

bin/pyRevitLabs.Common.pdb

2 KB
Binary file not shown.

bin/pyRevitLabs.CommonCLI.dll

0 Bytes
Binary file not shown.

bin/pyRevitLabs.CommonCLI.pdb

0 Bytes
Binary file not shown.

bin/pyRevitLabs.DeffrelDB.dll

0 Bytes
Binary file not shown.

bin/pyRevitLabs.Language.dll

0 Bytes
Binary file not shown.

bin/pyRevitLabs.Language.pdb

0 Bytes
Binary file not shown.

bin/pyRevitLabs.TargetApps.Revit.dll

7 KB
Binary file not shown.

bin/pyRevitUpdater.exe

4.5 KB
Binary file not shown.

bin/pyrevit.exe

4 KB
Binary file not shown.

bin/pyrevit.pdb

4 KB
Binary file not shown.

dev/pyRevitLoader/Source/PyRevitLoaderApplication.cs

+19-37
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,49 @@
44
using Autodesk.Revit.UI;
55
using Autodesk.Revit.Attributes;
66

7-
namespace PyRevitLoader
8-
{
7+
namespace PyRevitLoader {
98
[Regeneration(RegenerationOption.Manual)]
109
[Transaction(TransactionMode.Manual)]
11-
class PyRevitLoaderApplication : IExternalApplication
12-
{
13-
private static string versionNumber;
14-
10+
class PyRevitLoaderApplication : IExternalApplication {
1511
// Hook into Revit to allow starting a command.
16-
Result IExternalApplication.OnStartup(UIControlledApplication application)
17-
{
18-
19-
try
20-
{
21-
versionNumber = application.ControlledApplication.VersionNumber;
22-
if (application.ControlledApplication.VersionName.ToLower().Contains("vasari"))
23-
{
24-
versionNumber = "_Vasari";
25-
}
26-
27-
ExecuteStartupScript(application);
28-
29-
return Result.Succeeded;
12+
Result IExternalApplication.OnStartup(UIControlledApplication application) {
13+
try {
14+
return ExecuteStartupScript(application);
3015
}
31-
catch (Exception ex)
32-
{
33-
TaskDialog.Show("Error setting up PyRevitLoader", ex.ToString());
16+
catch (Exception ex) {
17+
TaskDialog.Show("Error Loading Startup Script", ex.ToString());
3418
return Result.Failed;
3519
}
3620
}
3721

38-
private static void ExecuteStartupScript(UIControlledApplication uiControlledApplication)
39-
{
22+
private static Result ExecuteStartupScript(UIControlledApplication uiControlledApplication) {
4023
// we need a UIApplication object to assign as `__revit__` in python...
4124
var versionNumber = uiControlledApplication.ControlledApplication.VersionNumber;
42-
var fieldName = int.Parse(versionNumber) >= 2017 ? "m_uiapplication": "m_application";
25+
var fieldName = int.Parse(versionNumber) >= 2017 ? "m_uiapplication" : "m_application";
4326
var fi = uiControlledApplication.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
4427

4528
var uiApplication = (UIApplication)fi.GetValue(uiControlledApplication);
4629
// execute StartupScript
30+
Result result = Result.Succeeded;
4731
var startupScript = GetStartupScriptPath();
48-
if (startupScript != null)
49-
{
32+
if (startupScript != null) {
5033
var executor = new ScriptExecutor(uiApplication); // uiControlledApplication);
51-
var result = executor.ExecuteScript(startupScript);
52-
if (result == (int)Result.Failed)
53-
{
54-
TaskDialog.Show("PyRevitLoader", executor.Message);
34+
result = executor.ExecuteScript(startupScript);
35+
if (result == Result.Failed) {
36+
TaskDialog.Show("Error Loading pyRevit", executor.Message);
5537
}
5638
}
39+
40+
return result;
5741
}
5842

59-
private static string GetStartupScriptPath()
60-
{
43+
private static string GetStartupScriptPath() {
6144
var loaderDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
6245
var dllDir = Path.GetDirectoryName(loaderDir);
63-
return Path.Combine(dllDir, String.Format("{0}.py", Assembly.GetExecutingAssembly().GetName().Name));
46+
return Path.Combine(dllDir, string.Format("{0}.py", Assembly.GetExecutingAssembly().GetName().Name));
6447
}
6548

66-
Result IExternalApplication.OnShutdown(UIControlledApplication application)
67-
{
49+
Result IExternalApplication.OnShutdown(UIControlledApplication application) {
6850
// FIXME: deallocate the python shell...
6951
return Result.Succeeded;
7052
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using Autodesk.Revit.Attributes;
3+
using Autodesk.Revit.UI;
4+
5+
namespace PyRevitRunner {
6+
[Regeneration(RegenerationOption.Manual)]
7+
[Transaction(TransactionMode.Manual)]
8+
class PyRevitRunnerApplication : IExternalApplication {
9+
// Hook into Revit to allow starting a command.
10+
Result IExternalApplication.OnStartup(UIControlledApplication application) {
11+
try {
12+
return RegisterExternalCommand(application);
13+
}
14+
catch (Exception ex) {
15+
TaskDialog.Show("Error Loading Script Runner Application", ex.ToString());
16+
return Result.Failed;
17+
}
18+
}
19+
20+
private static Result RegisterExternalCommand(UIControlledApplication application) {
21+
var assembly = typeof(PyRevitRunnerApplication).Assembly;
22+
23+
RibbonPanel ribbonPanel = application.CreateRibbonPanel("pyRevitRunner");
24+
25+
// Run service button
26+
var pbData = new PushButtonData(
27+
"PyRevitRunnerCommand",
28+
"PyRevitRunnerCommand",
29+
assembly.Location,
30+
"PyRevitRunner.PyRevitRunnerCommand");
31+
pbData.AvailabilityClassName = "PyRevitRunner.PyRevitRunnerCommandAvail";
32+
33+
ribbonPanel.AddItem(pbData);
34+
35+
return Result.Succeeded;
36+
}
37+
38+
Result IExternalApplication.OnShutdown(UIControlledApplication application) {
39+
// FIXME: deallocate the python shell...
40+
return Result.Succeeded;
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using Autodesk.Revit.Attributes;
5+
using Autodesk.Revit.UI;
6+
using Autodesk.Revit.DB;
7+
8+
using PyRevitLoader;
9+
using System.Reflection;
10+
using System.IO;
11+
12+
namespace PyRevitRunner {
13+
[Regeneration(RegenerationOption.Manual)]
14+
[Transaction(TransactionMode.Manual)]
15+
public class PyRevitRunnerCommand : IExternalCommand {
16+
17+
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) {
18+
// grab application and command data, skip elements since this is a batch runner and user doesn't
19+
// see the gui to make selections
20+
Application = commandData.Application;
21+
CommandData = commandData;
22+
23+
try {
24+
// 1
25+
// Processing Journal Data and getting the script path to be executed in IronPython engine
26+
IDictionary<string, string> dataMap = commandData.JournalData;
27+
ScriptSourceFile = dataMap["ScriptSource"];
28+
ModuleSearchPaths = new List<string>(dataMap["SearchPaths"].Split(';'));
29+
ModelPaths = new List<string>();
30+
var modelPaths = dataMap["Models"];
31+
if (modelPaths != null && modelPaths != string.Empty)
32+
ModelPaths.AddRange(modelPaths.Split(';'));
33+
LogFile = dataMap["LogFile"];
34+
35+
// add pyrevit library path and script directory path to search paths
36+
ModuleSearchPaths.Add(GetPyRevitLibsPath());
37+
ModuleSearchPaths.Add(GetSitePkgsPath());
38+
ModuleSearchPaths.Add(Path.GetDirectoryName(ScriptSourceFile));
39+
40+
// 2
41+
// Executing the script
42+
var executor = new ScriptExecutor(Application, fullFrame: true); // uiControlledApplication);
43+
var resultCode = executor.ExecuteScript(
44+
ScriptSourceFile,
45+
sysPaths: ModuleSearchPaths.ToArray(),
46+
logFilePath: LogFile,
47+
variables: new Dictionary<string, object>() {
48+
{"__batchexec__", true },
49+
{"__logfile__", LogFile },
50+
{"__models__", ModelPaths },
51+
});
52+
53+
// 3
54+
// Log results
55+
if (resultCode == 0)
56+
return Result.Succeeded;
57+
else
58+
return Result.Cancelled;
59+
}
60+
catch (Exception ex) {
61+
commandData.JournalData.Add("pyRevitRunner Execution Failure", ex.Message);
62+
return Result.Cancelled;
63+
}
64+
}
65+
66+
public UIApplication Application { get; private set; }
67+
public ExternalCommandData CommandData { get; private set; }
68+
69+
public string ScriptSourceFile { get; private set; }
70+
public List<string> ModuleSearchPaths { get; private set; }
71+
public List<string> ModelPaths { get; private set; }
72+
public string LogFile { get; private set; }
73+
public bool DebugMode { get; private set; }
74+
75+
private static string GetDeployPath() {
76+
var loaderDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
77+
var engineDir = Path.GetDirectoryName(loaderDir);
78+
var binDir = Path.GetDirectoryName(engineDir);
79+
return Path.GetDirectoryName(binDir);
80+
}
81+
82+
private static string GetPyRevitLibsPath() => Path.Combine(GetDeployPath(), "pyrevitlib");
83+
private static string GetSitePkgsPath() => Path.Combine(GetDeployPath(), "site-packages");
84+
}
85+
86+
87+
public class PyRevitRunnerCommandAvail : IExternalCommandAvailability {
88+
public PyRevitRunnerCommandAvail() {
89+
}
90+
91+
public bool IsCommandAvailable(UIApplication uiApp, CategorySet selectedCategories) {
92+
return true;
93+
}
94+
}
95+
96+
}

0 commit comments

Comments
 (0)