How to programmatically load a new symbol from an existing Family in a Revit project

By Gopinath Taget

You will find that neither of the following overloaded methods will work for you:

public bool Document::LoadFamilySymbol(string filename, string name)

public bool Document::LoadFamilySymbol(string filename, string name, out FamilySymbol symbol)

You will have to use the third version of this overloaded method:

public bool Document::LoadFamilySymbol(string filename, string name, IFamilyLoadOptions familyLoadOptions, out FamilySymbol symbol)

In order to use this though, you will have to implement the IFamilyLoadOptions interface like this:

class FamilyOption : IFamilyLoadOptions

{

    public bool OnFamilyFound(

        bool familyInUse,

        out bool overwriteParameterValues)

    {

        overwriteParameterValues = true;

        return true;

    }

 

    public bool OnSharedFamilyFound(

        Family sharedFamily,

        bool familyInUse,

        out FamilySource source,

        out bool overwriteParameterValues)

    {

        source = FamilySource.Family;

        overwriteParameterValues = true;

        return true;

    }

}

 
Next use the instance of this class with the right version of the LoadFamilySymbol method like this:

document.LoadFamilySymbol(familyFile, symbolName, new FamilyOption(), out gotSymbol)


Comments

One response to “How to programmatically load a new symbol from an existing Family in a Revit project”

  1. Michel de Wit Avatar
    Michel de Wit

    Hello Gopinath,
    What does document.LoadFamilySymbol(familyFile, symbolName, new FamilyOption(), out gotSymbol) do when a FamilySymbol is already loaded and is unchanged ? Does it load it again from disk and overwrite the current FamilySymbol, or does it skip the loading as it is already there ?
    And secondly, if it does skip the loading in this case, can I leave out the (time consuming) checking for loaded Families and FamilySymbols before calling document.LoadFamilySymbol() and let this method sort that out ?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading