From 594debbb9542d4c9601dff3adcac0c7f9a2d8bcd Mon Sep 17 00:00:00 2001 From: Jeremy Tammik Date: Thu, 28 Apr 2022 08:04:36 +0200 Subject: [PATCH] implemented GetAnalyticalElementId --- BuildingCoder/CmdAnalyticalModelGeom.cs | 42 ++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/BuildingCoder/CmdAnalyticalModelGeom.cs b/BuildingCoder/CmdAnalyticalModelGeom.cs index 4e6e208..823dcf6 100644 --- a/BuildingCoder/CmdAnalyticalModelGeom.cs +++ b/BuildingCoder/CmdAnalyticalModelGeom.cs @@ -1,10 +1,9 @@ -#if USING_ANALYTICAL_MODEL_BEFORE_REVIT_2023 #region Header // // CmdAnalyticalModelGeom.cs - retrieve analytical model geometry // -// Copyright (C) 2011-2021 by Jeremy Tammik, Autodesk Inc. All rights reserved. +// Copyright (C) 2011-2022 by Jeremy Tammik, Autodesk Inc. All rights reserved. // // Keywords: The Building Coder Revit API C# .NET add-in. // @@ -29,11 +28,14 @@ namespace BuildingCoder [Transaction(TransactionMode.Manual)] internal class CmdAnalyticalModelGeom : IExternalCommand { +#if USING_ANALYTICAL_MODEL_BEFORE_REVIT_2023 /// /// A list of all analytical curve types. /// private static readonly IEnumerable - CurveTypes = Enum.GetValues(typeof(AnalyticalCurveType)).Cast(); + CurveTypes = Enum.GetValues(typeof(AnalyticalCurveType)) + .Cast(); +#endif // USING_ANALYTICAL_MODEL_BEFORE_REVIT_2023 /// /// Offset at which to create a model curve copy @@ -48,10 +50,28 @@ private static readonly IEnumerable //static Transform _t = Transform.get_Translation( _offset ); // 2013 private static readonly Transform T = Transform.CreateTranslation(Offset); // 2014 + ElementId GetAnalyticalElementId(Element e) + { + Document doc = e.Document; + + AnalyticalToPhysicalAssociationManager m + = AnalyticalToPhysicalAssociationManager + .GetAnalyticalToPhysicalAssociationManager( + doc); + + if (null == m) + { + throw new System.ArgumentException( + "No AnalyticalToPhysicalAssociationManager found"); + } + + return m.GetAssociatedElementId(e.Id); + } + public Result Execute( - ExternalCommandData commandData, - ref string message, - ElementSet elements) + ExternalCommandData commandData, + ref string message, + ElementSet elements) { var uiapp = commandData.Application; var uidoc = uiapp.ActiveUIDocument; @@ -86,6 +106,10 @@ public Result Execute( foreach (Wall wall in walls) { + // The analytical model changed in Revit 2023 + // This approach was possible previously: + +#if USING_ANALYTICAL_MODEL_BEFORE_REVIT_2023 var am = wall.GetAnalyticalModel(); // 2022 //AnalyticalToPhysicalRelationManager.GetCounterpartsIds @@ -106,6 +130,10 @@ public Result Execute( creator.CreateModelCurve(curve.CreateTransformed(T)); // 2014 } +#endif // USING_ANALYTICAL_MODEL_BEFORE_REVIT_2023 + + ElementId id = GetAnalyticalElementId(wall); + } tx.Commit(); @@ -114,4 +142,4 @@ public Result Execute( } } } -#endif // USING_ANALYTICAL_MODEL_BEFORE_REVIT_2023 +//#endif // USING_ANALYTICAL_MODEL_BEFORE_REVIT_2023