Shared Nested families within a Selection

Shared Nested families within a Selection

RickyBell
Enthusiast Enthusiast
991 Views
5 Replies
Message 1 of 6

Shared Nested families within a Selection

RickyBell
Enthusiast
Enthusiast

I have an add-on that loops through selected components with this code.

 

foreach (Element ele in sel.Elements)

 

I'm only getting the parent family information in my selection. 

 

Is there a way to retreive the nested components?

 

 

0 Likes
992 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

Hi, you can retreive the elementId's of nested fams like so :

 

ElementSet elemset = commandData.Application.ActiveUIDocument.Selection.Elements;

foreach (Element el in elemset)
{
FamilyInstance fi = el as FamilyInstance;

var subs = fi.GetSubComponentIds();
//subs is the list of nested families

}

 

Kind regards,

Remy.

 

0 Likes
Message 3 of 6

RickyBell
Enthusiast
Enthusiast

Thanks for the reply.  Using your code from the project, I get the same results.  Just the parent information.  I've included the component I'm working with.  This Flange Adapter has three subComponents, the last SubComponent has a subComponent of it's own.

 

Ideally, I'd like to be able to loop through all of these items.

 

Thanks again for any help!

0 Likes
Message 4 of 6

Anonymous
Not applicable

Okay, This is how it goes :

 

// nested families selecteren
ElementSet elemset = commandData.Application.ActiveUIDocument.Selection.Elements;

foreach (Element el in elemset)
{
FamilyInstance fi = el as FamilyInstance;

IList<ElementId> subs = fi.GetSubComponentIds().ToList();

Element ele = doc.GetElement(subs[0]); // okay, do null check if family has no subcomponents
Parameter par = ele.get_Parameter(buildin_parameter);  // or just loop al ele.paramters for the one you need

}

 

0 Likes
Message 5 of 6

RickyBell
Enthusiast
Enthusiast

Thanks for your help.  I was able to get it working using this code idea here:

 

http://revitapisearch.com/html/be37702c-1dcd-bc14-aa35-45f06f20210a.htm

 

ICollection was the difference.  I took my loop three layers deep to get all the SubComponents.  Thanks again!

0 Likes
Message 6 of 6

Anonymous
Not applicable
Super 🙂
0 Likes