Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Dialogs in Journal Playback #1220

Merged
merged 2 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private static void ProcessArguments() {
else {
// try parse the engine version as an integer e.g. 277 for 2.7.7
if (int.TryParse(engStrVer, out var engIntVer))
engineVersion = (PyRevitEngineVersion)engIntVer;
engineVersion = (PyRevitEngineVersion)engIntVer;
}

if (engineVersion is null) {
Expand Down Expand Up @@ -550,7 +550,8 @@ private static void ProcessArguments() {
PurgeTempFiles = arguments["--purge"].IsTrue,
ImportPath = TryGetValue("--import", null)
},
targetIsFileList: true
targetIsFileList: true,
allowDialogs = arguments["--allowdialogs"].IsTrue
);
}
else
Expand All @@ -561,7 +562,8 @@ private static void ProcessArguments() {
runOptions: new PyRevitRunnerOptions() {
PurgeTempFiles = arguments["--purge"].IsTrue,
ImportPath = TryGetValue("--import", null)
}
},
allowDialogs = arguments["--allowdialogs"].IsTrue
);
}
}
Expand Down Expand Up @@ -699,8 +701,8 @@ private static void ProcessArguments() {
Console.WriteLine(string.Format("User {0} config",
PyRevitConfigs.GetUserCanConfig() ? "CAN" : "CAN NOT"));

}
}

else if (all("colordocs")) {
if (any("enable", "disable"))
PyRevitConfigs.SetColorizeDocs(arguments["enable"].IsTrue);
Expand Down Expand Up @@ -889,7 +891,7 @@ private static void ProcessArguments() {

else if (TryGetValue("<doctor_command>") is var doctorCommand && doctorCommand != null)
PyRevitCLIAppCmds.RunDoctor(doctorCommand, dryRun: arguments["--dryrun"].IsTrue);

else if (all("doctor", "--list"))
PyRevitCLIAppCmds.RunDoctor("--list");

Expand Down
7 changes: 4 additions & 3 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLIAppHelps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class PyRevitCLIAppHelps {
internal static void
PrintHelp(PyRevitCLICommandType commandType) {
switch (commandType) {

case PyRevitCLICommandType.Main:
BuildHelp(
null,
Expand Down Expand Up @@ -57,7 +57,7 @@ internal static void
}
);
break;

case PyRevitCLICommandType.Env:
BuildHelp(
new List<string>() { "env" },
Expand Down Expand Up @@ -297,6 +297,7 @@ internal static void
{ "<model_file>", "Target Revit model file path" },
{ "--purge", "Remove temporary run environment after completion" },
{ "--import=<import_path>", "Copy content of this folder into the runtime temp path." },
{ "--allowdialogs", "To allow dialogs during journal playback" }
});
break;

Expand Down Expand Up @@ -447,7 +448,7 @@ private static string BuildOptions(string baseHelp, string header, IDictionary<s
if (options != null) {
baseHelp += header + Environment.NewLine;
foreach (var optionPair in options) {
baseHelp +=
baseHelp +=
string.Format(outputFormat, optionPair.Key, optionPair.Value)
+ Environment.NewLine;
}
Expand Down
11 changes: 6 additions & 5 deletions dev/pyRevitLabs/pyRevitCLI/PyRevitCLIRevitCmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ internal static void
}

internal static void
RunExtensionCommand(string commandName, string targetFile, string revitYear, PyRevitRunnerOptions runOptions, bool targetIsFileList = false) {
RunExtensionCommand(string commandName, string targetFile, string revitYear, PyRevitRunnerOptions runOptions, bool targetIsFileList = false, bool allowDialogs = false) {
// verify command
if (commandName is null || commandName == string.Empty)
throw new Exception("Command name must be provided.");
Expand All @@ -163,7 +163,7 @@ internal static void
int revitYearNumber = 0;
int.TryParse(revitYear, out revitYearNumber);


// setup a list of models
var modelFiles = new List<string>();
// if target file is a list of model paths
Expand All @@ -176,7 +176,7 @@ internal static void
else
modelFiles.Add(targetFile);


// verify all models are accessible
foreach (string modelFile in modelFiles)
if (!CommonUtils.VerifyFile(modelFile))
Expand Down Expand Up @@ -256,7 +256,8 @@ internal static void
attachment,
commandScriptPath,
modelFiles,
runOptions
runOptions,
allowDialogs
);

// print results (exec env)
Expand Down Expand Up @@ -288,7 +289,7 @@ internal static void
}
}
}

}

// privates:
Expand Down
28 changes: 16 additions & 12 deletions dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
namespace pyRevitLabs.PyRevit {
public class PyRevitRunnerCommand {
public PyRevitRunnerCommand(string commandPath) => Path = commandPath;

public override string ToString() {
return $"{Name} | \"{Path}\"";
}

public string Name => System.IO.Path.GetFileName(Path).Replace(PyRevitConsts.ExtensionUICommandPostfix, "");
public string Path { get; }
}

public class PyRevitRunnerExecEnv {
private static readonly Logger logger = LogManager.GetCurrentClassLogger();

public PyRevitRunnerExecEnv(PyRevitAttachment attachment, string script, IEnumerable<string> modelPaths) {
public PyRevitRunnerExecEnv(PyRevitAttachment attachment, string script, IEnumerable<string> modelPaths, bool allowDialogs) {
Attachment = attachment;
Script = script;
ModelPaths = modelPaths;
AllowDialogs = allowDialogs;

// check if clone is compatible
if (!CommonUtils.VerifyFile(PyRevitCloneRunner))
Expand All @@ -54,22 +55,23 @@ public PyRevitRunnerExecEnv(PyRevitAttachment attachment, string script, IEnumer
' 0:< 'C {0};
Dim Jrn
Set Jrn = CrsJournalScript
Jrn.Directive ""DebugMode"", ""PerformAutomaticActionInErrorDialog"", 1
Jrn.Directive ""DebugMode"", ""PerformAutomaticActionInErrorDialog"", {1}
Jrn.Directive ""DebugMode"", ""PermissiveJournal"", 1
Jrn.RibbonEvent ""TabActivated:Add-Ins""
Jrn.RibbonEvent ""Execute external command:CustomCtrl_%CustomCtrl_%Add-Ins%pyRevitRunner%PyRevitRunnerCommand:PyRevitRunner.PyRevitRunnerCommand""
Jrn.Data ""APIStringStringMapJournalData"" _
, 4 _
, ""ScriptSource"" , ""{1}"" _
, ""SearchPaths"" , ""{2}"" _
, ""Models"" , ""{3}"" _
, ""LogFile"" , ""{4}""
, ""ScriptSource"" , ""{2}"" _
, ""SearchPaths"" , ""{3}"" _
, ""Models"" , ""{4}"" _
, ""LogFile"" , ""{5}""
Jrn.Command ""SystemMenu"" , ""Quit the application; prompts to save projects , ID_APP_EXIT""
Jrn.Data ""TaskDialogResult"" , ""Do you want to save changes to Untitled?"", ""No"", ""IDNO""
";

public PyRevitAttachment Attachment { get; private set; }
public string Script { get; private set; }
public bool AllowDialogs {get; private set;}
public IEnumerable<string> ModelPaths { get; private set; }

public RevitProduct Revit { get { return Attachment.Product; } }
Expand Down Expand Up @@ -101,8 +103,8 @@ public void Purge() {
}

// MDJ added code to copy all .addin files and subdirs into the batch running context.
// This is to workaround built-in Revit addins like the NavisExporter not being available while using pyRevit batch.
// Per MSDN, the below code is a relatively safe way to recurse through dirs and copy: http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx
// This is to workaround built-in Revit addins like the NavisExporter not being available while using pyRevit batch.
// Per MSDN, the below code is a relatively safe way to recurse through dirs and copy: http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx

public void CopyExistingAddons(string sourceDirectory) {
var targetDirectoryInfo = new DirectoryInfo(WorkingDirectory);
Expand All @@ -116,6 +118,7 @@ private void GenerateJournal() {
string.Format(
JournalTemplate, // template string
CommonUtils.GetISOTimeStampNow(), // timestamp with format: 27-Oct-2016 19:33:31.459
AllowDialogs ? 0 : 1, // whether journal playback should allow dialogs
Script, // script path
"", // sys paths
string.Join(";", ModelPaths), // model paths
Expand Down Expand Up @@ -172,7 +175,8 @@ public static class PyRevitRunner {
public static PyRevitRunnerExecEnv Run(PyRevitAttachment attachment,
string scriptPath,
IEnumerable<string> modelPaths,
PyRevitRunnerOptions opts = null) {
PyRevitRunnerOptions opts = null,
bool allowDialogs = false) {
var product = attachment.Product;
var clone = attachment.Clone;
var engineVer = attachment.Engine != null ? attachment.Engine.Version : 0;
Expand All @@ -185,7 +189,7 @@ public static PyRevitRunnerExecEnv Run(PyRevitAttachment attachment,
if (opts is null)
opts = new PyRevitRunnerOptions();

var execEnv = new PyRevitRunnerExecEnv(attachment, scriptPath, modelPaths);
var execEnv = new PyRevitRunnerExecEnv(attachment, scriptPath, modelPaths, allowDialogs);

// purge files if requested
if (opts.ImportPath != null)
Expand Down