Skip to content

Commit

Permalink
Started work on #16, #40 & #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Dieckmann committed Aug 31, 2017
1 parent 8c8bf6c commit 6dd1cd6
Showing 1 changed file with 101 additions and 41 deletions.
142 changes: 101 additions & 41 deletions src/ProcessRunner/Journal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static string GetDynamoVersion(dynamic revitVersion)
}

/// <summary>
/// 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
/// </summary>
/// <param name="revitVersion">The version number of Revit (e.g. 2017).</param>
/// <returns>The Revit version as an integer</returns>
Expand All @@ -61,6 +61,23 @@ private static int RevitVersionAsInt(dynamic revitVersion)
return revitVersionAsInt;
}

/// <summary>
/// Verifies that the given file path is a valid path for usage in journal files
/// </summary>
/// <param name="filePath">The file path</param>
/// <param name="paramName">The name of the parameter for the path</param>
/// <returns>A boolean to indicate success/failure</returns>
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;
}
}

/// <summary>
/// Builds the first part of the journal string
Expand All @@ -72,29 +89,41 @@ 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";
journalStart += "Jrn.Directive \"DebugMode\", \"PermissiveJournal\", 1 \n";
}
return journalStart;
}

/// <summary>
/// Builds the part of the journal string responsible for opening a project
/// </summary>
/// <param name="revitFilePath">The path to the Revit file. This can be an .rvt or .rfa file.</param>
/// <param name="openDetached">Should workshared models be opened detached from central model?</param>
/// <param name="openWorksetsMode">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).</param>
/// <returns>The part of the journal string responsible for opening a project.</returns>
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;
}

Expand All @@ -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";
}
Expand Down Expand Up @@ -207,35 +236,50 @@ private static void WriteJournalFile(string journalFilePath, string journalStrin
/// Create a journal file for purging and subsequently saving a Revit file.
///
/// </summary>
/// <param name="revitFilePath">The path to the Revit file. This can be an .rvt or .rfa file.</param>
/// <param name="revitFilePath">The path to the Revit file. This can be an .rvt or .rfa file. The path may not contain any whitespace.</param>
/// <param name="journalFilePath">The path of the generated journal file.</param>
/// <returns>The path of the generated journal file.</returns>
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;
}

}

/// <summary>
/// Create a journal file for purging and subsequently saving multiple Revit files in a single Revit session.
///
/// </summary>
/// <param name="revitFilePaths">The paths to the Revit files. These can be .rvt or .rfa files.</param>
/// <param name="revitFilePaths">The paths to the Revit files. These can be .rvt or .rfa files. The paths may not contain any whitespace.</param>
/// <param name="journalFilePath">The path of the generated journal file.</param>
/// <returns>The path of the generated journal file.</returns>
public static string PurgeModels(List<string> revitFilePaths, string journalFilePath)
{
foreach (string revitFilePath in revitFilePaths)
{
if (!CheckFilePath(revitFilePath, "revitFilePaths"))
{
return null;
}
}
DeleteJournalFile(journalFilePath);
// Create journal string
string journalString = BuildJournalStart(true);
Expand All @@ -260,31 +304,47 @@ public static string PurgeModels(List<string> 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.
/// </summary>
/// <param name="revitFilePath">The path to the Revit file. This can be an .rvt or .rfa file.</param>
/// <param name="workspacePath">The path to the Dynamo workspace.</param>
/// <param name="revitFilePath">The path to the Revit file. This can be an .rvt or .rfa file. The path may not contain any whitespace.</param>
/// <param name="workspacePath">The path to the Dynamo workspace. The path may not contain any whitespace.</param>
/// <param name="journalFilePath">The path of the generated journal file.</param>
/// <param name="revitVersion">The version number of Revit (e.g. 2017).</param>
/// <param name="debugMode">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.).</param>
/// <param name="openWorksetsMode">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).</param>
/// <param name="openDetached">Should workshared models be opened detached from central model?</param>
/// <returns>The path of the generated journal file.</returns>
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;
}
}
}

0 comments on commit 6dd1cd6

Please sign in to comment.