private static void ExecuteStartupScript(UIControlledApplication uiControlledApplication) { // we need a UIApplication object to assign as `__revit__` in python... var versionNumber = uiControlledApplication.ControlledApplication.VersionNumber; var fieldName = versionNumber == "2017" ? "m_uiapplication": "m_application"; var fi = uiControlledApplication.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance); var uiApplication = (UIApplication)fi.GetValue(uiControlledApplication); // execute StartupScript var startupScript = GetStartupScriptPath(); if (startupScript != null) { var executor = new ScriptExecutor(uiApplication, uiControlledApplication); var result = executor.ExecuteScript(startupScript); if (result == (int)Result.Failed) { TaskDialog.Show("PyRevitLoader", executor.Message); } } }
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 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) { var executor = new ScriptExecutor(uiApplication); // uiControlledApplication); result = executor.ExecuteScript(startupScript); if (result == Result.Failed) { TaskDialog.Show("Error Loading pyRevit", executor.Message); } } return(result); }