From 7295f5736a3e150e383ce138dfd7317ccfa370c9 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 18:05:51 +0100 Subject: [PATCH 01/13] Fix on TransactionGroup when a Grasshopper document is opened. --- src/RhinoInside.Revit/GH/Guest.cs | 102 +++++++++++++++--------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/src/RhinoInside.Revit/GH/Guest.cs b/src/RhinoInside.Revit/GH/Guest.cs index d1c487ebc..1c34dc496 100755 --- a/src/RhinoInside.Revit/GH/Guest.cs +++ b/src/RhinoInside.Revit/GH/Guest.cs @@ -53,48 +53,48 @@ GuestResult IGuest.EntryPoint(object sender, EventArgs args) GuestResult OnCheckIn(CheckInArgs options) { - Instances.CanvasCreated += EditorLoaded; + Instances.CanvasCreated += Grasshopper_CanvasCreated; // Register PreviewServer previewServer = new PreviewServer(); previewServer.Register(); - Revit.DocumentChanged += OnDocumentChanged; + Revit.DocumentChanged += Revit_DocumentChanged; External.ActivationGate.Enter += ActivationGate_Enter; External.ActivationGate.Exit += ActivationGate_Exit; - RhinoDoc.BeginOpenDocument += BeginOpenDocument; - RhinoDoc.EndOpenDocumentInitialViewUpdate += EndOpenDocumentInitialViewUpdate; - Rhino.Commands.Command.EndCommand += RhinoCommand_EndCommand; + RhinoDoc.BeginOpenDocument += Rhino_BeginOpenDocument; + RhinoDoc.EndOpenDocumentInitialViewUpdate += Rhino_EndOpenDocument; + Rhino.Commands.Command.EndCommand += Rhino_EndCommand; Instances.CanvasCreatedEventHandler Canvas_Created = default; Instances.CanvasCreated += Canvas_Created = (canvas) => { Instances.CanvasCreated -= Canvas_Created; - Instances.DocumentEditor.Activated += DocumentEditor_Activated; - canvas.DocumentChanged += ActiveCanvas_DocumentChanged; - canvas.KeyDown += ActiveCanvas_KeyDown; + Instances.DocumentEditor.Activated += Grasshopper_Activated; + canvas.DocumentChanged += Grasshopper_DocumentChanged; + canvas.KeyDown += Grasshopper_KeyDown; }; Instances.CanvasDestroyedEventHandler Canvas_Destroyed = default; Instances.CanvasDestroyed += Canvas_Destroyed = (canvas) => { - canvas.KeyDown -= ActiveCanvas_KeyDown; - canvas.DocumentChanged -= ActiveCanvas_DocumentChanged; - Instances.DocumentEditor.Activated -= DocumentEditor_Activated; + canvas.KeyDown -= Grasshopper_KeyDown; + canvas.DocumentChanged -= Grasshopper_DocumentChanged; + Instances.DocumentEditor.Activated -= Grasshopper_Activated; Instances.CanvasDestroyed -= Canvas_Destroyed; }; - Instances.DocumentServer.DocumentAdded += DocumentServer_DocumentAdded; - Instances.DocumentServer.DocumentRemoved += DocumentServer_DocumentRemoved; + Instances.DocumentServer.DocumentAdded += Grasshopper_DocumentAdded; + Instances.DocumentServer.DocumentRemoved += Grasshopper_DocumentRemoved; return GuestResult.Succeeded; } - private void EditorLoaded(GH_Canvas canvas) + private void Grasshopper_CanvasCreated(GH_Canvas canvas) { - Instances.CanvasCreated += EditorLoaded; + Instances.CanvasCreated -= Grasshopper_CanvasCreated; var message = string.Empty; try @@ -119,16 +119,16 @@ private void EditorLoaded(GH_Canvas canvas) GuestResult OnCheckOut(CheckOutArgs options) { - Instances.DocumentServer.DocumentAdded -= DocumentServer_DocumentAdded; + Instances.DocumentServer.DocumentAdded -= Grasshopper_DocumentAdded; - Rhino.Commands.Command.EndCommand -= RhinoCommand_EndCommand; - RhinoDoc.EndOpenDocumentInitialViewUpdate -= EndOpenDocumentInitialViewUpdate; - RhinoDoc.BeginOpenDocument -= BeginOpenDocument; + Rhino.Commands.Command.EndCommand -= Rhino_EndCommand; + RhinoDoc.EndOpenDocumentInitialViewUpdate -= Rhino_EndOpenDocument; + RhinoDoc.BeginOpenDocument -= Rhino_BeginOpenDocument; External.ActivationGate.Exit -= ActivationGate_Exit; External.ActivationGate.Enter -= ActivationGate_Enter; - Revit.DocumentChanged -= OnDocumentChanged; + Revit.DocumentChanged -= Revit_DocumentChanged; // Unregister PreviewServer previewServer?.Unregister(); @@ -247,9 +247,11 @@ void ActivationGate_Exit(object sender, EventArgs e) } static bool? EnableSolutions; - private void DocumentServer_DocumentAdded(GH_DocumentServer sender, GH_Document doc) + private void Grasshopper_DocumentAdded(GH_DocumentServer sender, GH_Document doc) { - doc.ObjectsDeleted += Doc_ObjectsDeleted; + doc.SolutionStart += Grasshopper_SolutionStart; + doc.ObjectsDeleted += Grasshopper_ObjectsDeleted; + doc.SolutionEnd += Grasshopper_SolutionEnd; // If we don't disable the solutions Grasshopper will // evaluate doc before notifiy us the document is being active. @@ -260,13 +262,17 @@ private void DocumentServer_DocumentAdded(GH_DocumentServer sender, GH_Document } } - private void DocumentServer_DocumentRemoved(GH_DocumentServer sender, GH_Document doc) + private void Grasshopper_DocumentRemoved(GH_DocumentServer sender, GH_Document doc) { - doc.ObjectsDeleted -= Doc_ObjectsDeleted; + if (PendingSolution == doc) PendingSolution = null; + + doc.SolutionEnd -= Grasshopper_SolutionEnd; + doc.ObjectsDeleted -= Grasshopper_ObjectsDeleted; + doc.SolutionStart -= Grasshopper_SolutionStart; } bool activeDefinitionWasEnabled = false; - void BeginOpenDocument(object sender, DocumentOpenEventArgs e) + void Rhino_BeginOpenDocument(object sender, DocumentOpenEventArgs e) { if (Instances.ActiveCanvas?.Document is GH_Document definition) { @@ -275,7 +281,7 @@ void BeginOpenDocument(object sender, DocumentOpenEventArgs e) } } - void EndOpenDocumentInitialViewUpdate(object sender, DocumentOpenEventArgs e) + void Rhino_EndOpenDocument(object sender, DocumentOpenEventArgs e) { if (Instances.ActiveCanvas?.Document is GH_Document definition) { @@ -284,7 +290,7 @@ void EndOpenDocumentInitialViewUpdate(object sender, DocumentOpenEventArgs e) } } - private void RhinoCommand_EndCommand(object sender, Rhino.Commands.CommandEventArgs args) + private void Rhino_EndCommand(object sender, Rhino.Commands.CommandEventArgs args) { if (args.CommandEnglishName == "GrasshopperBake") { @@ -504,7 +510,8 @@ public static UnitScale ModelUnitScale private set => modelUnitScale = value; } - void DocumentEditor_Activated(object sender, EventArgs e) => AuditUnits(Revit.ActiveUIDocument?.Document); + void Grasshopper_Activated(object sender, EventArgs e) => AuditUnits(Revit.ActiveUIDocument?.Document); + void Grasshopper_DocumentChanged(GH_Canvas sender, GH_CanvasDocumentChangedEventArgs e) { } internal static void AuditUnits(ARDB.Document document) { @@ -526,25 +533,10 @@ internal static void AuditUnits(ARDB.Document document) } } } - - void ActiveCanvas_DocumentChanged(GH_Canvas sender, GH_CanvasDocumentChangedEventArgs e) - { - if (e.OldDocument is object) - { - e.OldDocument.SolutionEnd -= ActiveDefinition_SolutionEnd; - e.OldDocument.SolutionStart -= ActiveDefinition_SolutionStart; - } - - if (e.NewDocument is object) - { - e.NewDocument.SolutionStart += ActiveDefinition_SolutionStart; - e.NewDocument.SolutionEnd += ActiveDefinition_SolutionEnd; - } - } #endregion #region Revit Document Changed - void OnDocumentChanged(object sender, ARDB.Events.DocumentChangedEventArgs e) + void Revit_DocumentChanged(object sender, ARDB.Events.DocumentChangedEventArgs e) { #if DEBUG var transactions = e.GetTransactionNames(); @@ -759,7 +751,7 @@ internal void CommitTransactionGroups() /// /// /// - private void ActiveCanvas_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) + private void Grasshopper_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (sender is GH_Canvas canvas && canvas.Document is GH_Document document) { @@ -777,7 +769,7 @@ private void ActiveCanvas_KeyDown(object sender, System.Windows.Forms.KeyEventAr } } - private void Doc_ObjectsDeleted(object sender, GH_DocObjectEventArgs e) => ObjectsDeleted(sender, (e.Document, e.Objects)); + private void Grasshopper_ObjectsDeleted(object sender, GH_DocObjectEventArgs e) => ObjectsDeleted(sender, (e.Document, e.Objects)); internal async void ObjectsDeleted(object sender, (GH_Document Document, IReadOnlyCollection Objects) e) { @@ -946,7 +938,7 @@ internal async void ObjectsDeleted(object sender, (GH_Document Document, IReadOn } } - void ActiveDefinition_SolutionStart(object sender, GH_SolutionEventArgs e) + void Grasshopper_SolutionStart(object sender, GH_SolutionEventArgs e) { if (e.Document is GH_Document document) { @@ -959,9 +951,12 @@ void ActiveDefinition_SolutionStart(object sender, GH_SolutionEventArgs e) obj.ExpireSolution(false); } - GeometryCache.StartKeepAliveRegion(); + if (ActiveDocumentStack.Count == 0) GeometryCache.StartKeepAliveRegion(); ActiveDocumentStack.Push(e.Document); - if (document.Enabled) StartTransactionGroups(); + if (document.Enabled) + { + if (ActiveDocumentStack.Count == 1) StartTransactionGroups(); + } else if (Instances.ActiveCanvas?.Document == document) { if (PendingSolution is object) PendingSolution = document; @@ -982,16 +977,19 @@ void ActiveDefinition_SolutionStart(object sender, GH_SolutionEventArgs e) private static GH_Document PendingSolution; - void ActiveDefinition_SolutionEnd(object sender, GH_SolutionEventArgs e) + void Grasshopper_SolutionEnd(object sender, GH_SolutionEventArgs e) { if (e.Document is GH_Document document) { if (ActiveDocumentStack.Peek() != e.Document) throw new InvalidOperationException(); - if (document.Enabled) CommitTransactionGroups(); + if (document.Enabled) + { + if (ActiveDocumentStack.Count == 1) CommitTransactionGroups(); + } ActiveDocumentStack.Pop(); - GeometryCache.EndKeepAliveRegion(); + if (ActiveDocumentStack.Count == 0) GeometryCache.EndKeepAliveRegion(); // Warn the user about objects that contain elements modified by Grasshopper. { From b8759d40bbff4827ef16f73dd633b2efec754231 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 18:42:01 +0100 Subject: [PATCH 02/13] Moved All 'Boundary Conditions' components to the same section. --- .../Structure/AddBoundaryConditions-Area.cs | 4 +-- .../Structure/AddBoundaryConditions-Line.cs | 4 +-- .../Structure/AddBoundaryConditions-Point.cs | 4 +-- .../Structure/QueryBoundaryConditions.cs | 2 +- .../Structure/StructuralSettings.cs | 26 +++++++++++++------ .../Parameters/Document.cs | 18 +++++++++---- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs index 4b4af056d..70ba559c4 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs @@ -75,8 +75,8 @@ public AddAreaBoundaryConditions() : base protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; - Parameters.Document.GetStructuralSettings(this, DA, "Document", out var hasSymbols); - if (!hasSymbols) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); + if (!Parameters.Document.TryGetStructuralSettings(doc, out var _)) + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); ReconstructElement ( diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs index ad175ef0e..903319e06 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs @@ -76,8 +76,8 @@ public AddLineBoundaryConditions() : base protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; - Parameters.Document.GetStructuralSettings(this, DA, "Document", out var hasSymbols); - if (!hasSymbols) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); + if (!Parameters.Document.TryGetStructuralSettings(doc, out var _)) + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); ReconstructElement ( diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs index 7de77d24f..6f7278f66 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs @@ -73,8 +73,8 @@ public AddPointBoundaryConditions() : base protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; - Parameters.Document.GetStructuralSettings(this, DA, "Document", out var hasSymbols); - if (!hasSymbols) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); + if (!Parameters.Document.TryGetStructuralSettings(doc, out var _)) + AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); ReconstructElement ( diff --git a/src/RhinoInside.Revit.GH/Components/Structure/QueryBoundaryConditions.cs b/src/RhinoInside.Revit.GH/Components/Structure/QueryBoundaryConditions.cs index 50409aa1b..68d828f9b 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/QueryBoundaryConditions.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/QueryBoundaryConditions.cs @@ -10,7 +10,7 @@ namespace RhinoInside.Revit.GH.Components.Walls public class QueryBoundaryConditions : ElementCollectorComponent { public override Guid ComponentGuid => new Guid("F8C6588F-4131-4692-A43D-CC4E34F88AB4"); - public override GH_Exposure Exposure => GH_Exposure.tertiary | GH_Exposure.obscure; + public override GH_Exposure Exposure => GH_Exposure.senary | GH_Exposure.obscure; private ARDB.ElementFilter _ElementFilter = new ARDB.ElementClassFilter(typeof(ARDB.Structure.BoundaryConditions)); protected override ARDB.ElementFilter ElementFilter => _ElementFilter; diff --git a/src/RhinoInside.Revit.GH/Components/Structure/StructuralSettings.cs b/src/RhinoInside.Revit.GH/Components/Structure/StructuralSettings.cs index ef0bcd290..b863d252b 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/StructuralSettings.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/StructuralSettings.cs @@ -1,21 +1,21 @@ using System; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; -using RhinoInside.Revit.GH.Exceptions; using ARDB = Autodesk.Revit.DB; namespace RhinoInside.Revit.GH.Components.Structure { [ComponentVersion(introduced: "1.27")] - public class StructuralSettings : TransactionalChainComponent + public class BoundaryConditionsSettings : TransactionalChainComponent { public override Guid ComponentGuid => new Guid("B5144C5D-F374-4786-99A7-6A579ED2FD59"); + public override GH_Exposure Exposure => GH_Exposure.senary | GH_Exposure.obscure; - public StructuralSettings() : base + public BoundaryConditionsSettings() : base ( - name: "Structural Settings", - nickname: "SS", - description: "Main structural settings associated with a Revit document.", + name: "Boundary Conditions Settings", + nickname: "BCS", + description: "Boundary conditions settings associated with a Revit document.", category: "Revit", subCategory: "Structure" ) @@ -31,7 +31,6 @@ public StructuralSettings() : base Name = "Document", NickName = "DOC", Description = "Document", - Optional = true }, ParamRelevance.Occasional ), new ParamDefinition @@ -89,6 +88,15 @@ public StructuralSettings() : base protected override ParamDefinition[] Outputs => outputs; static readonly ParamDefinition[] outputs = { + new ParamDefinition + ( + new Parameters.Element + { + Name = _BoundaryConditionsSettings_, + NickName = "BCS", + Description = "Structural Settings element.", + }, ParamRelevance.Secondary + ), new ParamDefinition ( new Param_Number @@ -136,6 +144,7 @@ public StructuralSettings() : base ) }; + const string _BoundaryConditionsSettings_ = "Boundary Conditions Settings"; const string _Spacing_ = "Spacing"; const string _Fixed_ = "Fixed"; const string _Pinned_ = "Pinned"; @@ -145,7 +154,8 @@ public StructuralSettings() : base protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc)) return; - var settings = Parameters.Document.GetStructuralSettings(this, DA, "Document", out var hasSymbols); + if (!Parameters.Document.TryGetStructuralSettings(doc, out var settings)) return; + if (!Params.TrySetData(DA, _BoundaryConditionsSettings_, () => settings)) return; if (!Params.TryGetData(DA, _Fixed_, out Types.FamilySymbol fixedSymbol)) return; if (!Params.TryGetData(DA, _Pinned_, out Types.FamilySymbol pinnedSymbol)) return; diff --git a/src/RhinoInside.Revit.GH/Parameters/Document.cs b/src/RhinoInside.Revit.GH/Parameters/Document.cs index 86c14801f..0dfcb771c 100644 --- a/src/RhinoInside.Revit.GH/Parameters/Document.cs +++ b/src/RhinoInside.Revit.GH/Parameters/Document.cs @@ -74,12 +74,20 @@ public static bool GetDataOrDefault(IGH_Component component, IGH_DataAccess DA, return document is object; } - public static ARDB.Structure.StructuralSettings GetStructuralSettings(IGH_Component component, IGH_DataAccess DA, string name, out bool hasSymbols) + internal static bool TryGetStructuralSettings(Types.Document document, out ARDB.Structure.StructuralSettings settings) { - TryGetDocumentOrCurrent(component, DA, name, out var doc); - var settings = ARDB.Structure.StructuralSettings.GetStructuralSettings(doc?.Value); - hasSymbols = settings.BoundaryConditionFamilySymbolFixed != ARDB.ElementId.InvalidElementId; - return settings; + try + { + if (document?.Value is ARDB.Document doc) + { + settings = ARDB.Structure.StructuralSettings.GetStructuralSettings(doc); + return settings.BoundaryConditionFamilySymbolFixed.IsValid(); + } + } + catch { } + + settings = null; + return false; } #region UI From fb3c3dc2246dbed80f4c55eb6762814d6b7daa87 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 18:43:06 +0100 Subject: [PATCH 03/13] Renamed 'Structural Settings' to 'Boundary Conditions Settings' --- .../{StructuralSettings.cs => BoundaryConditionsSettings.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/RhinoInside.Revit.GH/Components/Structure/{StructuralSettings.cs => BoundaryConditionsSettings.cs} (100%) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/StructuralSettings.cs b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs similarity index 100% rename from src/RhinoInside.Revit.GH/Components/Structure/StructuralSettings.cs rename to src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs From a58eac4209fbf3b043fc4ae54dc1a51fa0dc7a50 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 18:50:29 +0100 Subject: [PATCH 04/13] Renamed the output. It was too long. --- .../Components/Structure/BoundaryConditionsSettings.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs index b863d252b..c92edda0a 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs @@ -92,10 +92,10 @@ public BoundaryConditionsSettings() : base ( new Parameters.Element { - Name = _BoundaryConditionsSettings_, - NickName = "BCS", + Name = _StructuralSettings_, + NickName = "SS", Description = "Structural Settings element.", - }, ParamRelevance.Secondary + }, ParamRelevance.Occasional ), new ParamDefinition ( @@ -144,7 +144,7 @@ public BoundaryConditionsSettings() : base ) }; - const string _BoundaryConditionsSettings_ = "Boundary Conditions Settings"; + const string _StructuralSettings_ = "Structural Settings"; const string _Spacing_ = "Spacing"; const string _Fixed_ = "Fixed"; const string _Pinned_ = "Pinned"; @@ -155,7 +155,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc)) return; if (!Parameters.Document.TryGetStructuralSettings(doc, out var settings)) return; - if (!Params.TrySetData(DA, _BoundaryConditionsSettings_, () => settings)) return; + if (!Params.TrySetData(DA, _StructuralSettings_, () => settings)) return; if (!Params.TryGetData(DA, _Fixed_, out Types.FamilySymbol fixedSymbol)) return; if (!Params.TryGetData(DA, _Pinned_, out Types.FamilySymbol pinnedSymbol)) return; From a5993d4a6d493dcb033ff750ea52d55973ef30a5 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 18:54:39 +0100 Subject: [PATCH 05/13] Fix --- .../Components/Structure/BoundaryConditionsSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs index c92edda0a..bec9e4989 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs @@ -155,7 +155,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc)) return; if (!Parameters.Document.TryGetStructuralSettings(doc, out var settings)) return; - if (!Params.TrySetData(DA, _StructuralSettings_, () => settings)) return; + else Params.TrySetData(DA, _StructuralSettings_, () => settings); if (!Params.TryGetData(DA, _Fixed_, out Types.FamilySymbol fixedSymbol)) return; if (!Params.TryGetData(DA, _Pinned_, out Types.FamilySymbol pinnedSymbol)) return; From 9c8313548c1f4fa6ee7ad58513ac2b45de054e39 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 18:58:42 +0100 Subject: [PATCH 06/13] FromElementId --- .../Components/Structure/BoundaryConditionsSettings.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs index bec9e4989..4fe15d558 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs @@ -182,24 +182,21 @@ protected override void TrySolveInstance(IGH_DataAccess DA) StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolPinned = pinnedSymbol.Id; } - Params.TrySetData(DA, "Pinned", - () => doc.Value.GetElement(settings.BoundaryConditionFamilySymbolPinned) as ARDB.FamilySymbol); + Params.TrySetData(DA, _Pinned_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolPinned)); if (rollerSymbol is object) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolRoller = rollerSymbol.Id; } - Params.TrySetData(DA, "Roller", - () => doc.Value.GetElement(settings.BoundaryConditionFamilySymbolRoller) as ARDB.FamilySymbol); + Params.TrySetData(DA, _Roller_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolRoller)); if (userSymbol is object) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolUserDefined = userSymbol.Id; } - Params.TrySetData(DA, "User", - () => doc.Value.GetElement(settings.BoundaryConditionFamilySymbolUserDefined) as ARDB.FamilySymbol); + Params.TrySetData(DA, _User_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolUserDefined)); } } } From d2fd16670c3853ff5cf7567bc671fb68bf9ea018 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 19:00:16 +0100 Subject: [PATCH 07/13] Avoid unnecessary changes. --- .../Components/Structure/BoundaryConditionsSettings.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs index 4fe15d558..1234edabc 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs @@ -163,35 +163,35 @@ protected override void TrySolveInstance(IGH_DataAccess DA) if (!Params.TryGetData(DA, _User_, out Types.FamilySymbol userSymbol)) return; if (!Params.TryGetData(DA, _Spacing_, out double? spacing)) return; - if (spacing.HasValue) + if (spacing.HasValue && settings.BoundaryConditionAreaAndLineSymbolSpacing != spacing.Value / Revit.ModelUnits) { StartTransaction(doc.Value); settings.BoundaryConditionAreaAndLineSymbolSpacing = spacing.Value / Revit.ModelUnits; } Params.TrySetData(DA, _Spacing_, () => settings.BoundaryConditionAreaAndLineSymbolSpacing * Revit.ModelUnits); - if (fixedSymbol is object) + if (fixedSymbol is object && settings.BoundaryConditionFamilySymbolFixed != fixedSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolFixed = fixedSymbol.Id; } Params.TrySetData(DA, _Fixed_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolFixed)); - if (pinnedSymbol is object) + if (pinnedSymbol is object && settings.BoundaryConditionFamilySymbolPinned != pinnedSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolPinned = pinnedSymbol.Id; } Params.TrySetData(DA, _Pinned_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolPinned)); - if (rollerSymbol is object) + if (rollerSymbol is object && settings.BoundaryConditionFamilySymbolRoller != rollerSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolRoller = rollerSymbol.Id; } Params.TrySetData(DA, _Roller_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolRoller)); - if (userSymbol is object) + if (userSymbol is object && settings.BoundaryConditionFamilySymbolUserDefined != userSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolUserDefined = userSymbol.Id; From 1ae03084c1cead42ce9ae7427395f73c01e52c8c Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 19:13:22 +0100 Subject: [PATCH 08/13] Added `Types.Document.GetElement`. --- .../Structure/BoundaryConditionsSettings.cs | 67 +++++++++---------- src/RhinoInside.Revit.GH/Types/Document.cs | 9 +++ 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs index 1234edabc..4edb7fbbe 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/BoundaryConditionsSettings.cs @@ -1,7 +1,6 @@ using System; using Grasshopper.Kernel; using Grasshopper.Kernel.Parameters; -using ARDB = Autodesk.Revit.DB; namespace RhinoInside.Revit.GH.Components.Structure { @@ -34,16 +33,6 @@ public BoundaryConditionsSettings() : base }, ParamRelevance.Occasional ), new ParamDefinition - ( - new Param_Number - { - Name = _Spacing_, - NickName = _Spacing_.Substring(0,1), - Description = "Symbol spacing for boundary conditions.", - Optional = true, - }, ParamRelevance.Primary - ), - new ParamDefinition ( new Parameters.FamilySymbol() { @@ -82,7 +71,17 @@ public BoundaryConditionsSettings() : base Description = "The FamilySymbol to represent a user defined boundary condition.", Optional = true, }, ParamRelevance.Primary - ) + ), + new ParamDefinition + ( + new Param_Number + { + Name = _Spacing_, + NickName = _Spacing_.Substring(0,1), + Description = "Symbol spacing for boundary conditions.", + Optional = true, + }, ParamRelevance.Primary + ), }; protected override ParamDefinition[] Outputs => outputs; @@ -98,15 +97,6 @@ public BoundaryConditionsSettings() : base }, ParamRelevance.Occasional ), new ParamDefinition - ( - new Param_Number - { - Name = _Spacing_, - NickName = _Spacing_.Substring(0,1), - Description = "Symbol spacing for boundary conditions.", - }, ParamRelevance.Primary - ), - new ParamDefinition ( new Parameters.FamilySymbol() { @@ -141,15 +131,24 @@ public BoundaryConditionsSettings() : base NickName = _User_.Substring(0,1), Description = "The FamilySymbol to represent a user defined boundary condition.", }, ParamRelevance.Primary - ) + ), + new ParamDefinition + ( + new Param_Number + { + Name = _Spacing_, + NickName = _Spacing_.Substring(0,1), + Description = "Symbol spacing for boundary conditions.", + }, ParamRelevance.Primary + ), }; const string _StructuralSettings_ = "Structural Settings"; - const string _Spacing_ = "Spacing"; const string _Fixed_ = "Fixed"; const string _Pinned_ = "Pinned"; const string _Roller_ = "Roller"; const string _User_ = "User"; + const string _Spacing_ = "Spacing"; protected override void TrySolveInstance(IGH_DataAccess DA) { @@ -161,42 +160,42 @@ protected override void TrySolveInstance(IGH_DataAccess DA) if (!Params.TryGetData(DA, _Pinned_, out Types.FamilySymbol pinnedSymbol)) return; if (!Params.TryGetData(DA, _Roller_, out Types.FamilySymbol rollerSymbol)) return; if (!Params.TryGetData(DA, _User_, out Types.FamilySymbol userSymbol)) return; - if (!Params.TryGetData(DA, _Spacing_, out double? spacing)) return; - if (spacing.HasValue && settings.BoundaryConditionAreaAndLineSymbolSpacing != spacing.Value / Revit.ModelUnits) - { - StartTransaction(doc.Value); - settings.BoundaryConditionAreaAndLineSymbolSpacing = spacing.Value / Revit.ModelUnits; - } - Params.TrySetData(DA, _Spacing_, () => settings.BoundaryConditionAreaAndLineSymbolSpacing * Revit.ModelUnits); if (fixedSymbol is object && settings.BoundaryConditionFamilySymbolFixed != fixedSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolFixed = fixedSymbol.Id; } - Params.TrySetData(DA, _Fixed_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolFixed)); + Params.TrySetData(DA, _Fixed_, () => doc.GetElement(settings.BoundaryConditionFamilySymbolFixed)); if (pinnedSymbol is object && settings.BoundaryConditionFamilySymbolPinned != pinnedSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolPinned = pinnedSymbol.Id; } - Params.TrySetData(DA, _Pinned_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolPinned)); + Params.TrySetData(DA, _Pinned_, () => doc.GetElement(settings.BoundaryConditionFamilySymbolPinned)); if (rollerSymbol is object && settings.BoundaryConditionFamilySymbolRoller != rollerSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolRoller = rollerSymbol.Id; } - Params.TrySetData(DA, _Roller_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolRoller)); + Params.TrySetData(DA, _Roller_, () => doc.GetElement(settings.BoundaryConditionFamilySymbolRoller)); if (userSymbol is object && settings.BoundaryConditionFamilySymbolUserDefined != userSymbol.Id) { StartTransaction(doc.Value); settings.BoundaryConditionFamilySymbolUserDefined = userSymbol.Id; } - Params.TrySetData(DA, _User_, () => Types.FamilySymbol.FromElementId(doc.Value, settings.BoundaryConditionFamilySymbolUserDefined)); + Params.TrySetData(DA, _User_, () => doc.GetElement(settings.BoundaryConditionFamilySymbolUserDefined)); + + if (spacing.HasValue && settings.BoundaryConditionAreaAndLineSymbolSpacing != spacing.Value / Revit.ModelUnits) + { + StartTransaction(doc.Value); + settings.BoundaryConditionAreaAndLineSymbolSpacing = spacing.Value / Revit.ModelUnits; + } + Params.TrySetData(DA, _Spacing_, () => settings.BoundaryConditionAreaAndLineSymbolSpacing * Revit.ModelUnits); } } } diff --git a/src/RhinoInside.Revit.GH/Types/Document.cs b/src/RhinoInside.Revit.GH/Types/Document.cs index 66aefa7b1..e8e9f2a51 100755 --- a/src/RhinoInside.Revit.GH/Types/Document.cs +++ b/src/RhinoInside.Revit.GH/Types/Document.cs @@ -724,6 +724,15 @@ public bool? HasPendingChanges #endregion #region Elements + + internal T GetElement(ARDB.ElementId id) where T : Element, new() + { + if (Value is ARDB.Document document && id.IsValid()) + return (T) Element.FromElementId(document, id); + + return id == ElementIdExtension.Invalid ? new T() : null; + } + public Element GetNamesakeElement(Element element) { if (element is object) From a7ebb2bc060716b3b0e178c8d59b57e6f8c455bc Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Fri, 20 Dec 2024 19:19:02 +0100 Subject: [PATCH 09/13] Chech for a valid fixed symbol. --- .../Components/Structure/AddBoundaryConditions-Area.cs | 5 ++++- .../Components/Structure/AddBoundaryConditions-Line.cs | 5 ++++- .../Components/Structure/AddBoundaryConditions-Point.cs | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs index 70ba559c4..f206e9da7 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Area.cs @@ -75,8 +75,11 @@ public AddAreaBoundaryConditions() : base protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; - if (!Parameters.Document.TryGetStructuralSettings(doc, out var _)) + if (!Parameters.Document.TryGetStructuralSettings(doc, out var settings) || !settings.BoundaryConditionFamilySymbolFixed.IsValid()) + { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); + return; + } ReconstructElement ( diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs index 903319e06..b566a5747 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Line.cs @@ -76,8 +76,11 @@ public AddLineBoundaryConditions() : base protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; - if (!Parameters.Document.TryGetStructuralSettings(doc, out var _)) + if (!Parameters.Document.TryGetStructuralSettings(doc, out var settings) || !settings.BoundaryConditionFamilySymbolFixed.IsValid()) + { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); + return; + } ReconstructElement ( diff --git a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs index 6f7278f66..3de5a58c8 100644 --- a/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs +++ b/src/RhinoInside.Revit.GH/Components/Structure/AddBoundaryConditions-Point.cs @@ -73,8 +73,11 @@ public AddPointBoundaryConditions() : base protected override void TrySolveInstance(IGH_DataAccess DA) { if (!Parameters.Document.TryGetDocumentOrCurrent(this, DA, "Document", out var doc) || !doc.IsValid) return; - if (!Parameters.Document.TryGetStructuralSettings(doc, out var _)) + if (!Parameters.Document.TryGetStructuralSettings(doc, out var settings) || !settings.BoundaryConditionFamilySymbolFixed.IsValid()) + { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Document does not have symbols for Boundary Conditions representation."); + return; + } ReconstructElement ( From 164411245091361f87e9d51c3b852ee1e00a9a02 Mon Sep 17 00:00:00 2001 From: kike-garbo Date: Sat, 21 Dec 2024 12:57:44 +0100 Subject: [PATCH 10/13] Fix on 'Add Revision' input order. --- src/RhinoInside.Revit.GH/Components/Sheets/AddRevision.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RhinoInside.Revit.GH/Components/Sheets/AddRevision.cs b/src/RhinoInside.Revit.GH/Components/Sheets/AddRevision.cs index 85102e1cf..2a11b6739 100644 --- a/src/RhinoInside.Revit.GH/Components/Sheets/AddRevision.cs +++ b/src/RhinoInside.Revit.GH/Components/Sheets/AddRevision.cs @@ -141,7 +141,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA) ( revision, doc.Value, - description, date, + date, description, issuedBy, issuedTo, issued, ARDB.RevisionVisibility.CloudAndTagVisible @@ -159,8 +159,8 @@ ARDB.Revision Reconstruct ( ARDB.Revision revision, ARDB.Document document, - string description, string date, + string description, string issuedBy, string issuedTo, bool? issued, @@ -170,7 +170,7 @@ ARDB.Revision Reconstruct if (revision is null) revision = ARDB.Revision.Create(document); - RevisionIssue.Invoke(this, revision, description, date, issuedBy, issuedTo, issued); + RevisionIssue.Invoke(this, revision, date, description, issuedBy, issuedTo, issued); if (visibility is object && visibility.Value != revision.Visibility) revision.Visibility = visibility.Value; From 244edfe47986079e38768ab25b3a6f43298fbc18 Mon Sep 17 00:00:00 2001 From: eirannejad Date: Sat, 21 Dec 2024 14:25:37 -0800 Subject: [PATCH 11/13] added 1.27 release notes --- docs/pages/_en/1.0/reference/release-notes.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/pages/_en/1.0/reference/release-notes.md b/docs/pages/_en/1.0/reference/release-notes.md index 637f7d824..c54b3efb1 100644 --- a/docs/pages/_en/1.0/reference/release-notes.md +++ b/docs/pages/_en/1.0/reference/release-notes.md @@ -18,6 +18,11 @@ group: Deployment & Configs {% include ltr/release_header_next.html title="Upcoming Changes" note=rc_release_notes %} +{% include ltr/release-header.html title="v1.27" version="v1.27.9121.7152" time="12/21/2024" %} + +- Includes all changes under 1.27 RC releases listed below +- Miscellaneous improvements and bug fixes + {% include ltr/release-header.html title="v1.27 RC2" version="v1.27.9101.27850" pre_release=true time="12/01/2024" %} - Added {% include ltr/comp.html uuid='7b229f5e' %} From b1182e2240ace825c004e4fd11c374f05564ea47 Mon Sep 17 00:00:00 2001 From: eirannejad Date: Sat, 21 Dec 2024 14:26:39 -0800 Subject: [PATCH 12/13] added 1.28 rc1 release notes --- docs/pages/_en/1.0/reference/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/pages/_en/1.0/reference/release-notes.md b/docs/pages/_en/1.0/reference/release-notes.md index b8d3e4a22..5b5848d1f 100644 --- a/docs/pages/_en/1.0/reference/release-notes.md +++ b/docs/pages/_en/1.0/reference/release-notes.md @@ -26,6 +26,10 @@ group: Deployment & Configs {% include ltr/release_header_next.html title="Upcoming Changes" note=rc_release_notes %} +{% include ltr/release-header.html title="v1.28 RC1" version="v1.28.9121.7332" pre_release=true time="12/21/2024" %} + +- Miscellaneous Improvements + {% include ltr/release-header.html title="v1.27" version="v1.27.9121.7152" time="12/21/2024" %} - Includes all changes under 1.27 RC releases listed below From 7bbfab68cbd4e70db4b51cf8155f97998c576526 Mon Sep 17 00:00:00 2001 From: eirannejad Date: Sat, 21 Dec 2024 14:27:38 -0800 Subject: [PATCH 13/13] upped 1.x to 1.29 --- src/Product.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Product.targets b/src/Product.targets index 74ed6a7ba..254bb4f6f 100644 --- a/src/Product.targets +++ b/src/Product.targets @@ -17,7 +17,7 @@ If `ReleaseVersion` contains "wip" the product expires. 1 - 28 + 29 0 0