GetSubComponentIds cannot get nested familyInstance information

GetSubComponentIds cannot get nested familyInstance information

Anonymous
Not applicable
1,033 Views
1 Reply
Message 1 of 2

GetSubComponentIds cannot get nested familyInstance information

Anonymous
Not applicable

I use this  family file, it has nested lamp, however, I use the follow code to get the nested lamp information.

 

ICollection<ElementId> subElemSet = familyinstance.GetSubComponentIds();

 

However, the problem is that subElemSet.count == 0, why I cannot get the lamp information from this family file?

 

Is there any other way to get the lamp information?

 

 

1,034 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

GetSubComponentIds() method works for nested families that are shared.

The "doc.EditFamily(famElement)" would get you the desired results.

 

Here's Jeremy's example:

http://thebuildingcoder.typepad.com/blog/2014/09/modifying-saving-and-reloading-families.html

 

 

Code copied from blog post:

Document doc = commandData.Application
    .ActiveUIDocument.Document;
 
  FilteredElementCollector collectorUsed
    = new FilteredElementCollector( doc );
 
  collectorUsed.OfClass( typeof( Family ) );
 
  foreach( Family f in collectorUsed )
  {
    string name = f.Name;
    Document famdoc = doc.EditFamily( f );
 
    FilteredElementCollector famcollectorUsed
      = new FilteredElementCollector( famdoc );
 
    ICollection<ElementId> textNoteTypes
      = famcollectorUsed.OfClass( typeof( TextNoteType ) )
        .ToElementIds();
 
    foreach( ElementId textNoteTypeId in textNoteTypes )
    {
      Element ele = doc.GetElement( textNoteTypeId );
      foreach( Parameter p in ele.Parameters )
      {
        if( p.Definition.Name == "Text Font" )
        {
          using( Transaction tranew
            = new Transaction( doc ) )
          {
            tranew.Start( "Update" );
            p.Set( "Arial Black" );
            tranew.Commit();
          }
        }
      }
    }
  }

 

0 Likes