diff --git a/src/ProcessRunner/Journal.cs b/src/ProcessRunner/Journal.cs
index ccd1286..ad6183d 100644
--- a/src/ProcessRunner/Journal.cs
+++ b/src/ProcessRunner/Journal.cs
@@ -34,7 +34,7 @@ private static string GetDynamoVersion(dynamic revitVersion)
}
///
- /// Returns the Revit version entered as string, double or integer as an integer
+ /// Returns the Revit version (entered as string, double or integer) as an integer
///
/// The version number of Revit (e.g. 2017).
/// The Revit version as an integer
@@ -61,6 +61,23 @@ private static int RevitVersionAsInt(dynamic revitVersion)
return revitVersionAsInt;
}
+ ///
+ /// Verifies that the given file path is a valid path for usage in journal files
+ ///
+ /// The file path
+ /// The name of the parameter for the path
+ /// A boolean to indicate success/failure
+ private static bool CheckFilePath(string filePath, string paramName)
+ {
+ if (filePath.Contains(" "))
+ {
+ throw new ArgumentException("The file path is not valid because it contains whitespace.", paramName);
+ }
+ else
+ {
+ return true;
+ }
+ }
///
/// Builds the first part of the journal string
@@ -72,7 +89,7 @@ private static string BuildJournalStart(bool debugMode = false)
string journalStart = "'" +
"Dim Jrn \n" +
"Set Jrn = CrsJournalScript \n";
- // These two directives
+ // These two directives can make things easier if needed
if (debugMode)
{
journalStart += "Jrn.Directive \"DebugMode\", \"PerformAutomaticActionInErrorDialog\", 1 \n";
@@ -80,21 +97,33 @@ private static string BuildJournalStart(bool debugMode = false)
}
return journalStart;
}
-
+
///
/// Builds the part of the journal string responsible for opening a project
///
/// The path to the Revit file. This can be an .rvt or .rfa file.
+ /// Should workshared models be opened detached from central model?
+ /// This setting can be used to suppress the Specify Open Worksets dialog. Possible input values are "All" (load all worksets), "Editable" (load editable worksets only) and "Custom" (load last used worksets only).
/// The part of the journal string responsible for opening a project.
- private static string BuildProjectOpen(string revitFilePath)
+ private static string BuildProjectOpen(string revitFilePath, bool openDetached = false, string openWorksetsMode = "")
{
// Exception if the rvt/rfa file isn't found
if (!File.Exists(revitFilePath))
{
throw new FileNotFoundException();
}
- string projectOpen = String.Format("Jrn.Command \"StartupPage\" , \"Open this project , ID_FILE_MRU_FIRST\" \n" +
- "Jrn.Data \"MRUFileName\" , \"{0}\" \n", revitFilePath.Replace(' ', '/'));
+ string projectOpen = "Jrn.Command \"StartupPage\" , \"Open this project , ID_FILE_MRU_FIRST\" \n";
+ if (openDetached)
+ {
+ projectOpen += "Jrn.Data \"FileOpenSubDialog\" , \"OpenAsLocalCheckBox\", \"False\" \n";
+ projectOpen += "Jrn.Data \"FileOpenSubDialog\" , \"DetachCheckBox\", \"True\" \n";
+ // ToDo: This won't be enough. We'll need to decide if to keep or discard worksets...
+ }
+ projectOpen += String.Format("Jrn.Data \"MRUFileName\" , \"{0}\" \n", revitFilePath);
+ if (openWorksetsMode == "All" || openWorksetsMode == "Editable" || openWorksetsMode == "Custom")
+ {
+ projectOpen += String.Format("Jrn.Data \"WorksetConfig\" , \"{0}\", 0 \n", openWorksetsMode);
+ }
return projectOpen;
}
@@ -118,12 +147,12 @@ private static string BuildDynamoLaunch(string workspacePath, dynamic revitVersi
{
// Doesn't work with Dynamo 1.0
launchDynamo += String.Format("Jrn.Command \"Ribbon\" , \"Launch Dynamo, ID_VISUAL_PROGRAMMING_DYNAMO\" \n" +
- "Jrn.Data \"APIStringStringMapJournalData\", 5, \"dynPath\", \"{0}\", \"dynShowUI\", \"false\", \"dynAutomation\", \"false\", \"dynPathExecute\", \"true\", \"dynModelShutDown\", \"true\" \n", workspacePath.Replace(' ', '/'));
+ "Jrn.Data \"APIStringStringMapJournalData\", 5, \"dynPath\", \"{0}\", \"dynShowUI\", \"false\", \"dynAutomation\", \"false\", \"dynPathExecute\", \"true\", \"dynModelShutDown\", \"true\" \n", workspacePath);
}
else
{
launchDynamo += String.Format("Jrn.RibbonEvent \"Execute external command:CustomCtrl_%CustomCtrl_%Add-Ins%Visual Programming%Dynamo {0}:Dynamo.Applications.DynamoRevit\" \n" +
- "Jrn.Data \"APIStringStringMapJournalData\", 3, \"dynPath\", \"{1}\", \"dynShowUI\", \"false\", \"dynAutomation\", \"true\" \n", dynVersion, workspacePath.Replace(' ', '/'));
+ "Jrn.Data \"APIStringStringMapJournalData\", 3, \"dynPath\", \"{1}\", \"dynShowUI\", \"false\", \"dynAutomation\", \"true\" \n", dynVersion, workspacePath);
// This command must only be called in pre-2017 Revit versions
launchDynamo += "Jrn.Command \"Internal\" , \"Flush undo and redo stacks , ID_FLUSH_UNDO\" \n";
}
@@ -207,35 +236,50 @@ private static void WriteJournalFile(string journalFilePath, string journalStrin
/// Create a journal file for purging and subsequently saving a Revit file.
///
///
- /// The path to the Revit file. This can be an .rvt or .rfa file.
+ /// The path to the Revit file. This can be an .rvt or .rfa file. The path may not contain any whitespace.
/// The path of the generated journal file.
/// The path of the generated journal file.
public static string PurgeModel(string revitFilePath, string journalFilePath)
{
- DeleteJournalFile(journalFilePath);
- // Create journal string
- // Journal needs to be in debug mode.
- // Otherwise the journal playback may stop if there is nothing to purge.
- string journalString = BuildJournalStart(true);
- journalString += BuildProjectOpen(revitFilePath);
- journalString += BuildProjectPurge();
- journalString += BuildProjectSave();
- journalString += BuildProjectClose();
- journalString += BuildJournalEnd();
- // Create journal file
- WriteJournalFile(journalFilePath, journalString);
- return journalFilePath;
+ if (CheckFilePath(revitFilePath, "revitFilePath"))
+ {
+ DeleteJournalFile(journalFilePath);
+ // Create journal string
+ // Journal needs to be in debug mode.
+ // Otherwise the journal playback may stop if there is nothing to purge.
+ string journalString = BuildJournalStart(true);
+ journalString += BuildProjectOpen(revitFilePath);
+ journalString += BuildProjectPurge();
+ journalString += BuildProjectSave();
+ journalString += BuildProjectClose();
+ journalString += BuildJournalEnd();
+ // Create journal file
+ WriteJournalFile(journalFilePath, journalString);
+ return journalFilePath;
+ }
+ else
+ {
+ return null;
+ }
+
}
///
/// Create a journal file for purging and subsequently saving multiple Revit files in a single Revit session.
///
///
- /// The paths to the Revit files. These can be .rvt or .rfa files.
+ /// The paths to the Revit files. These can be .rvt or .rfa files. The paths may not contain any whitespace.
/// The path of the generated journal file.
/// The path of the generated journal file.
public static string PurgeModels(List revitFilePaths, string journalFilePath)
{
+ foreach (string revitFilePath in revitFilePaths)
+ {
+ if (!CheckFilePath(revitFilePath, "revitFilePaths"))
+ {
+ return null;
+ }
+ }
DeleteJournalFile(journalFilePath);
// Create journal string
string journalString = BuildJournalStart(true);
@@ -260,31 +304,47 @@ public static string PurgeModels(List revitFilePaths, string journalFile
/// Dynamo is never run in the idle loop. The workspace is executed immediately, and control is returned to the DynamoRevit
/// external application.
///
- /// The path to the Revit file. This can be an .rvt or .rfa file.
- /// The path to the Dynamo workspace.
+ /// The path to the Revit file. This can be an .rvt or .rfa file. The path may not contain any whitespace.
+ /// The path to the Dynamo workspace. The path may not contain any whitespace.
/// The path of the generated journal file.
/// The version number of Revit (e.g. 2017).
/// Should the journal file be run in debug mode? Set this to true if you expect models to have warnings (e.g. missing links etc.).
+ /// This setting can be used to suppress the Specify Open Worksets dialog. Possible input values are "All" (load all worksets), "Editable" (load editable worksets only) and "Custom" (load last used worksets only).
+ /// Should workshared models be opened detached from central model?
/// The path of the generated journal file.
- public static string ByWorkspacePath(string revitFilePath, string workspacePath, string journalFilePath, dynamic revitVersion, bool debugMode = false)
+ public static string ByWorkspacePath(string revitFilePath, string workspacePath, string journalFilePath, dynamic revitVersion, bool debugMode = false, bool openDetached = false, string openWorksetsMode = "")
{
- DeleteJournalFile(journalFilePath);
- int revitVersionInt = RevitVersionAsInt(revitVersion);
- string dynVersion = GetDynamoVersion(revitVersionInt);
- // Create journal string
- string journalString = BuildJournalStart(debugMode);
- journalString += BuildProjectOpen(revitFilePath);
- journalString += BuildDynamoLaunch(workspacePath, revitVersionInt, dynVersion);
- // In newer Revit versions the slave graph will only run if there are no journal commands after launching Dynamo.
- // The slave graph will then need to terminte itself.
- if (revitVersionInt < 2017)
+ if (CheckFilePath(revitFilePath, "revitFilePath"))
{
- journalString += BuildProjectClose();
- journalString += BuildJournalEnd();
+ if (CheckFilePath(workspacePath, "workspacePath"))
+ {
+ DeleteJournalFile(journalFilePath);
+ int revitVersionInt = RevitVersionAsInt(revitVersion);
+ string dynVersion = GetDynamoVersion(revitVersionInt);
+ // Create journal string
+ string journalString = BuildJournalStart(debugMode);
+ journalString += BuildProjectOpen(revitFilePath, openDetached, openWorksetsMode);
+ journalString += BuildDynamoLaunch(workspacePath, revitVersionInt, dynVersion);
+ // In newer Revit versions the slave graph will only run if there are no journal commands after launching Dynamo.
+ // The slave graph will then need to terminte itself.
+ if (revitVersionInt < 2017)
+ {
+ journalString += BuildProjectClose();
+ journalString += BuildJournalEnd();
+ }
+ // Create journal file
+ WriteJournalFile(journalFilePath, journalString);
+ return journalFilePath;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
}
- // Create journal file
- WriteJournalFile(journalFilePath, journalString);
- return journalFilePath;
}
}
}