Skip to content

Commit

Permalink
v4.6.11
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Jan 12, 2019
2 parents 745591e + 17d083c commit 8b4534e
Show file tree
Hide file tree
Showing 48 changed files with 853 additions and 111 deletions.
Binary file modified bin/engines/273/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/273/pyRevitLoader.pdb
Binary file not shown.
Binary file added bin/engines/273/pyRevitRunner.dll
Binary file not shown.
Binary file added bin/engines/273/pyRevitRunner.pdb
Binary file not shown.
Binary file modified bin/engines/277/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/277/pyRevitLoader.pdb
Binary file not shown.
Binary file added bin/engines/277/pyRevitRunner.dll
Binary file not shown.
Binary file added bin/engines/277/pyRevitRunner.pdb
Binary file not shown.
Binary file modified bin/engines/278/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/278/pyRevitLoader.pdb
Binary file not shown.
Binary file added bin/engines/278/pyRevitRunner.dll
Binary file not shown.
Binary file added bin/engines/278/pyRevitRunner.pdb
Binary file not shown.
Binary file modified bin/engines/279/pyRevitLoader.dll
Binary file not shown.
Binary file modified bin/engines/279/pyRevitLoader.pdb
Binary file not shown.
Binary file added bin/engines/279/pyRevitRunner.dll
Binary file not shown.
Binary file added bin/engines/279/pyRevitRunner.pdb
Binary file not shown.
1 change: 1 addition & 0 deletions bin/engines/pyRevitLoader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
#pylint: disable=C0103,W1401,E0401,E0602
"""
██▓███▓██ ██▓ ██▀███ ▓█████ ██▒ █▓ ██▓▄▄▄█████▓
▓██░ ██▒██ ██▒▓██ ▒ ██▒▓█ ▀▓██░ █▒▓██▒▓ ██▒ ▓▒
Expand Down
Binary file modified bin/pyRevitLabs.Common.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.Common.pdb
Binary file not shown.
Binary file modified bin/pyRevitLabs.CommonCLI.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.CommonCLI.pdb
Binary file not shown.
Binary file modified bin/pyRevitLabs.DeffrelDB.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.Language.dll
Binary file not shown.
Binary file modified bin/pyRevitLabs.Language.pdb
Binary file not shown.
Binary file modified bin/pyRevitLabs.TargetApps.Revit.dll
Binary file not shown.
Binary file modified bin/pyRevitUpdater.exe
Binary file not shown.
Binary file modified bin/pyrevit.exe
Binary file not shown.
Binary file modified bin/pyrevit.pdb
Binary file not shown.
56 changes: 19 additions & 37 deletions dev/pyRevitLoader/Source/PyRevitLoaderApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,49 @@
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace PyRevitLoader
{
namespace PyRevitLoader {
[Regeneration(RegenerationOption.Manual)]
[Transaction(TransactionMode.Manual)]
class PyRevitLoaderApplication : IExternalApplication
{
private static string versionNumber;

class PyRevitLoaderApplication : IExternalApplication {
// Hook into Revit to allow starting a command.
Result IExternalApplication.OnStartup(UIControlledApplication application)
{

try
{
versionNumber = application.ControlledApplication.VersionNumber;
if (application.ControlledApplication.VersionName.ToLower().Contains("vasari"))
{
versionNumber = "_Vasari";
}

ExecuteStartupScript(application);

return Result.Succeeded;
Result IExternalApplication.OnStartup(UIControlledApplication application) {
try {
return ExecuteStartupScript(application);
}
catch (Exception ex)
{
TaskDialog.Show("Error setting up PyRevitLoader", ex.ToString());
catch (Exception ex) {
TaskDialog.Show("Error Loading Startup Script", ex.ToString());
return Result.Failed;
}
}

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

var uiApplication = (UIApplication)fi.GetValue(uiControlledApplication);
// execute StartupScript
Result result = Result.Succeeded;
var startupScript = GetStartupScriptPath();
if (startupScript != null)
{
if (startupScript != null) {
var executor = new ScriptExecutor(uiApplication); // uiControlledApplication);
var result = executor.ExecuteScript(startupScript);
if (result == (int)Result.Failed)
{
TaskDialog.Show("PyRevitLoader", executor.Message);
result = executor.ExecuteScript(startupScript);
if (result == Result.Failed) {
TaskDialog.Show("Error Loading pyRevit", executor.Message);
}
}

return result;
}

private static string GetStartupScriptPath()
{
private static string GetStartupScriptPath() {
var loaderDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var dllDir = Path.GetDirectoryName(loaderDir);
return Path.Combine(dllDir, String.Format("{0}.py", Assembly.GetExecutingAssembly().GetName().Name));
return Path.Combine(dllDir, string.Format("{0}.py", Assembly.GetExecutingAssembly().GetName().Name));
}

Result IExternalApplication.OnShutdown(UIControlledApplication application)
{
Result IExternalApplication.OnShutdown(UIControlledApplication application) {
// FIXME: deallocate the python shell...
return Result.Succeeded;
}
Expand Down
43 changes: 43 additions & 0 deletions dev/pyRevitLoader/Source/PyRevitRunnerApplication.cs
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;
}
}
}
96 changes: 96 additions & 0 deletions dev/pyRevitLoader/Source/PyRevitRunnerCommand.cs
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;
}
}

}
Loading

0 comments on commit 8b4534e

Please sign in to comment.