Retrieve nested families

Anonymous

Retrieve nested families

Anonymous
Not applicable

Hi there, I am a bit lost in retrieving nested families. I have 3 families. Fam A,B,C.

 

I checked "Shared" for fam C.

C is nested in B. B is not shared.

B is nested in A.

So when I ask A if it has .GetSubComponentIds() it says NOPE. Which is strange, because it should report C as subcomponent, but it does not.

 

So then I thought, lets make fam B Shared aswell. Now fam A.GetSubComponentIds() finds B as subcomponent.

But when I ask if B has subcomponents it says NOPE.

 

SO, the question is, how can I get to fam C. Or does the API only have the ability to look 1 level deep?

 

 

 

0 Likes
Reply
Accepted solutions (1)
2,595 Views
3 Replies
Replies (3)

RPTHOMAS108
Mentor
Mentor
Accepted solution

I don't encounter this issue, see enclosed project file (although this is in 2018). Perhaps the non-shared nested family wasn't overwritten with the shared one when the family was reloaded? I know there are issues with swapping shared and non-shared families over in the UI, there are dialogue warnings against some forms of this if the family already exists in the project.

 

When a nested family is shared it is available directly within the project via filtering which can be good and bad. I use the members .SuperComponent and .GetSubComponentIds only for establishing hierarchy as enclosed project file.

 

Imports System
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI.Selection
Imports System.Collections.Generic
Imports System.Linq

<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _
<Autodesk.Revit.DB.Macros.AddInId("D4AE2180-CFD2-475A-9142-8C488816EA8B")> _
Partial Public Class ThisDocument

    Private Sub Module_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
	End Sub
	
    Private Sub Module_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
	End Sub
       	
    Public Sub Nest
    	Dim FEC As New FilteredElementCollector(Document)
    	Dim ECF As New ElementCategoryFilter(BuiltInCategory.OST_GenericModel)
    	Dim Els As IList(Of FamilyInstance) = _
    		FEC.WherePasses(ECF).WhereElementIsNotElementType _
    		.ToElements.Cast(Of FamilyInstance).tolist
    	
    	Dim SB As New Text.StringBuilder
    	    	
    	Dim TopLevel As FamilyInstance = nothing
    	For Each Itm As FamilyInstance In Els
    		If Itm.SuperComponent Is Nothing Then
    			TopLevel = itm
    			Exit for
    		End If
    	Next
    	If TopLevel Is Nothing Then Exit Sub Else
    	
    	While True
    		Dim J As ICollection(Of ElementId)=TopLevel.GetSubComponentIds
    		SB.Append("|")
    		SB.Append(TopLevel.Name)
    		If J.Count = 0 Then
    			SB.Append("|")
    			Exit while
    		End If
    		TopLevel =  TryCast( Document.GetElement(J(0)),FamilyInstance)
    		   		
    	End While
 	
    	TaskDialog.Show("Count",SB.ToString,TaskDialogCommonButtons.Ok,TaskDialogResult.Ok)
    	
    End Sub
  End Class

 

 

JimJia
Alumni
Alumni

Dear Remy van den Bor,

 

I tried to verify this against Revit 2019 by Revit Lookup, I didn't reproduce this either.

 

If C is nested in B, B is not shared, A.GetSubComponentIds() can report the desired C as sub component.

 

In order to explore this matter further, we will need to provide a minimal reproducible case for the development team to analyse in depth.


In order to understand exactly what you mean and be able to research possible reasons for the discrepancy between the observed and expected behaviour, they require:
· A short exact description of what you are trying to achieve.
· The behavior you observe versus what you expect, and why this is a problem.
· A complete yet minimal Revit sample model to run a test in.
· A complete yet minimal macro embedded in the sample model or Visual Studio solution with add-in manifest that can be compiled, loaded, run and debugged with a single click to analyse its behavior live in the sample model.
· Detailed step-by-step instructions for reproducing the issue, e.g. which element to pick, what command to launch etc.
· http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com

Anonymous
Not applicable

Seems like there is something wrong with the family. I have made another family and this one works as expected.

Thanls everyone for the suggestions.

0 Likes