AnalyticalModel not accessible in Revit 2023 api.

AnalyticalModel not accessible in Revit 2023 api.

peter_sylvester
Contributor Contributor
2,301 Views
6 Replies
Message 1 of 7

AnalyticalModel not accessible in Revit 2023 api.

peter_sylvester
Contributor
Contributor

We are using AnalyticalModel to exclude Structural Elements when selecting the Elements of a Schedule in the current document.

var scheduleElements = new FilteredElementCollector(_doc, schedule.Id).Where(p => !(p is AnalyticalModel)).ToList();

 

In Revit 2023 this is not possible because AnalyticalModel was changed to 'internal'.

 

How can we exclude Structural Elements from a FilteredElementCollector in Revit 2023?

 

Thanks for your help.

P.

 

 

0 Likes
2,302 Views
6 Replies
Replies (6)
Message 2 of 7

jeremy_tammik
Alumni
Alumni

I would suggest examining such an element using RevitLookup and other means and identifying its .NET class, Revit category, and other typical characteristics that you can add to your filtered element collector.  This approach works for all kinds of elements under all circumstances, of course.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 7

revittoolkit
Explorer
Explorer

I did check it with RevitLookup and it looks to me that in relation to the .Net classes nothing changed in Revit 2023 compared to 2022 - except that that base "AnalyticalModel" class became 'internal'

 

For a little background:

As you know - every structural element in Revit come with its own Analitycal Element. See the attached "AM-beam1.png" - for the beam and its AnalyticalModelStick.

The Revit 2022 Api docs list the hierarchy as: (haven't found the 2023 api docs yet 😞

 

 

System Object
Autodesk.Revit.DB.Element
Autodesk.Revit.DB.Structure.AnalyticalModel
Autodesk.Revit.DB.Structure.AnalyticalModelStick
Autodesk.Revit.DB.Structure.AnalyticalModelSurface

 

 

RevitLookup, for both 2022 and 2023) only shows the hierarchy up to AnalitycalModel (See attached AM-Beam2.png)

 

If you create in Revit a Schedule that includes the beams in your project - and then use the schedule to highlight all the beams contained, Revit will select/highlight only the beams without their 'analytical model' representation.

Doing it through the API such a selection would be equivalent to:

 

var scheduleElements = new FilteredElementCollector(_doc, schedule.Id).ToList();

 

 

The problem with this is that this will return TWO elements, the beam and its corresponding Analytical Model.
To filter out the analytical model Element one would use:

 

var scheduleElements = new FilteredElementCollector(_doc, schedule.Id).Where(p => !(p is AnalyticalModel)).ToList();

 

 

As I've said before, the problem is that in Revit 2023 the AnalyticalModel class became internal

 

// Decompiled with JetBrains decompiler
// Type: AnalyticalModel
// Assembly: RevitAPI, Version=23.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 3F119BED-4E20-487E-A28B-0FE14139ED62
// Assembly location: C:\Work\MdskProducts\BIMrx_2\Microdesk.BIMrx_2\Product\Source\Lib\Revit\2023\RevitAPI.dll

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 224)]
internal struct AnalyticalModel
{
 ....
}

 

 

So the question remains: How can we deal with analytical elements in the Revit 2023 api?
Specifically how can we filter them out from the results of an ElementCollector ?

 

Thanks for your attention.

0 Likes
Message 4 of 7

RPTHOMAS108
Mentor
Mentor

In 2023 the analytical model changed from one that was automatically created in the background to one where the analytical elements are created separately by the user with the user then creating the association between an analytical element and a physical element. Thus in 2023 if you have a beam it doesn't have any associated analytical element until the user adds one.

 

I would suggest that if you want to add a collector based on a schedule that you can add a category filter to it also since:

OST_StructuralFraming is not the same as OST_AnalyticalMember

 

If that doesn't work due to below then you can filter out with Linq using CategoryType.

Element.Category.CategoryType <> AnalyticalModel.

 

Getting analytical members from a collector filtered by a schedule view of a non-analytical category is likely a quirk in terms of making the parameters of the analytical model available in the schedule (for associated element of non-analytical category).

 

I think both of your attached images are from versions prior to Revit 2023. In 2023 there is simply:

AnalyticalElement

--->AnalyticalMember

--->AnalyticalSurfaceBase

                --->AnalyticalOpening

                --->AnalyticalPanel

 

 

0 Likes
Message 5 of 7

jeremy_tammik
Alumni
Alumni

(haven't found the 2023 api docs yet 

   

As always, they are included in the Revit SDK. So, you have to download the Revit 2023 SDK and there they are:

 

https://www.autodesk.com/developer-network/platform-technologies/revit

   

To understand how to work with the analytical model in Revit 2023, please refer to the new Revit 2023 SDK sample ContextualAnalyticalModel.

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 6 of 7

jeremy_tammik
Alumni
Alumni

I was just pointed to a very important and helpful resource explaining the changes to the analytical model in Revit 2023:

 

Please see this help page where you can find some samples at the bottom:

 

https://help.autodesk.com/view/RVT/2023/ENU/?guid=GUID-A1157199-4E27-41F9-BF45-53A5CD79E9A1

 

A sample that describes how to access the analytical element for a given physical element is in the section named: Gets the associated analytical element for a physical one. The bottom line is that the relation between physical element and analytical element can now be edited; in the old approach this was not possible. The class which handles these relations is called AnalyticalToPhysicalAssociationManager.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 7 of 7

jeremy_tammik
Alumni
Alumni

I published some new structural API information and resources:

 

https://thebuildingcoder.typepad.com/blog/2022/04/tbc-samples-2023-and-the-new-structural-api.html

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes