Set Elbow Fitting Type

Here is a simple question with a simple solution on setting the type of a family instance:

Question: I read your post on cable tray orientation and fittings and also looked at the AutoRoute SDK sample. I am using NewElbowFitting too.

The problem is that the fittings created automatically are of the family 'Rectangle Elbow - Mitered: Standard'. If I want to create instances of another family, say 'Rectangle Elbow - Radius: 1W', how could I achieve that?

Answer: How about creating them first, in whatever way you can, and then accessing the new family instance and setting its type as you like after it has been created. Does that work?

Response: Thanks for your suggestion. It works!

I implemented the idea as follows:

1. Find the target type element id using the following code:

  ICollection<ElementId> iElementIds 
    = fi.GetValidTypes();
 
  if( iElementIds != null && iElementIds.Count > 0 )
  {
    string typeInfo = "";
    foreach( ElementId eid in iElementIds )
    {
      Element elem = doc.get_Element( eid );
      if( elem != null )
      {
        FamilySymbol fs = elem as FamilySymbol;
        typeInfo += fs.Family.Name + "  " 
          + elem.Name + "  " 
          + eid.IntegerValue.ToString() + "\n";
      }
    }
    TaskDialog.Show( "revit", typeInfo );
  }

2. Use the ChangeTypeId method to change the FamilyInstance type:

  fi.ChangeTypeId( new ElementId( 133158 ) );