diff --git a/src/RhinoInside.Revit.AddIn/Commands/Grasshopper/GrasshopperPlayerCommand.cs b/src/RhinoInside.Revit.AddIn/Commands/Grasshopper/GrasshopperPlayerCommand.cs index d0d971bfa..a7a9f4b89 100644 --- a/src/RhinoInside.Revit.AddIn/Commands/Grasshopper/GrasshopperPlayerCommand.cs +++ b/src/RhinoInside.Revit.AddIn/Commands/Grasshopper/GrasshopperPlayerCommand.cs @@ -411,7 +411,7 @@ ref string message { using (var transGroup = new TransactionGroup(app.ActiveUIDocument.Document)) { - transGroup.Start(Path.GetFileNameWithoutExtension(definition.Properties.ProjectFileName)); + transGroup.Start(definition.GetTransactionName()); definition.NewSolution(expireAllObjects: true); @@ -550,7 +550,7 @@ ref string message // { // using (var transGroup = new TransactionGroup(app.ActiveUIDocument.Document)) // { - // transGroup.Start(Path.GetFileNameWithoutExtension(definition.Properties.ProjectFileName)); + // transGroup.Start(definition.GetTransactionName()); // GH_Document.EnableSolutions = true; // definition.Enabled = true; diff --git a/src/RhinoInside.Revit.External/Extensions/Grasshopper.cs b/src/RhinoInside.Revit.External/Extensions/Grasshopper.cs index ef6b4ceda..71248a232 100644 --- a/src/RhinoInside.Revit.External/Extensions/Grasshopper.cs +++ b/src/RhinoInside.Revit.External/Extensions/Grasshopper.cs @@ -1,9 +1,21 @@ +using System; +using System.IO; using Grasshopper.Kernel; namespace Grasshopper { internal static class GH_DocumentExtension { + public static string GetTransactionName(this GH_Document document) + { + var displayName = string.Empty; + if (document.Properties.ProjectFileName is object) displayName = Path.GetFileNameWithoutExtension(document.Properties.ProjectFileName).TripleDot(24).Replace("_", " ").Replace("-", " "); + if (string.IsNullOrEmpty(displayName) && document.FilePath is object) displayName = Path.GetFileNameWithoutExtension(document.FilePath).TripleDot(24).Replace("_", " ").Replace("-", " "); + if (string.IsNullOrEmpty(displayName)) displayName = $"Grasshopper {DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentUICulture)}"; + + return displayName.ToControlEscaped(); + } + public static bool KeepOpen(this GH_Document document) { #if RHINO_8 diff --git a/src/RhinoInside.Revit/GH/Guest.cs b/src/RhinoInside.Revit/GH/Guest.cs index 19748033e..d1c487ebc 100755 --- a/src/RhinoInside.Revit/GH/Guest.cs +++ b/src/RhinoInside.Revit/GH/Guest.cs @@ -703,10 +703,8 @@ GH_Document NewSolution() internal void StartTransactionGroups() { - var now = DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentUICulture); - var name = ActiveDocumentStack.Peek().DisplayName; - - StartTransactionGroups($"Grasshopper {now}: {name.TripleDot(16)}", true); + var name = ActiveDocumentStack.Peek().GetTransactionName(); + StartTransactionGroups(name, true); } internal void StartTransactionGroups(string name, bool forcedModal)