NewFamilyInstance Overloads

We have discussed a number of issues with finding the right one of the numerous overloads of the NewFamilyInstance method for placing instances of a specific family. Here is another question on this, which provides a welcome opportunity to summarise what we have looked at so far:

Question: I have a case where I want to insert a series of families with a statement like this:

  FamilyInstance instance =
      location, symbol,
      StructuralType.NonStructural );

This works fine as long as it is a simple family with an insertion point. It doesn't work if the family is hosted or if the insertion requires two points. How can I determine which type of insert the family requires?

Answer: You are absolutely right. The NewFamilyInstance method has a number of overloads, and you need to select the correct one depending on various characteristics of the family you are inserting an instance from. This is discussed in the developer guide in section 12.3.5 'Creating FamilyInstance Objects'. The issue has also come up a number of times in the past here on the blog in the following situations:

The second-last post includes the definition of a method named TestAllOverloads which enables you to try out all possible overloads of the NewFamilyInstance method to see which one works best for a specific family.

The best hint of all was provided below by Rolando Hijar after the initial publication of this. He points out that the hosting behavior of a family can be determined by accessing the built-in parameter FAMILY_HOSTING_BEHAVIOR:

  int hosttype 
    = family.get_Parameter(
      BuiltInParameter.FAMILY_HOSTING_BEHAVIOR )

I hope these examples give you enough to get started with, at least!