Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 67020

Re: Family info

$
0
0

I suggest you check whether the family is already loaded before trying to load it (again).

 

It is so simple.

 

Here is an example method, from 

 

https://thebuildingcoder.typepad.com/blog/2014/04/instancevoidcututils-and-need-for-regeneration.html

 

    /// <summary>
    /// Retrieve cutting symbol, 
    /// loading family if needed.
    /// </summary>
    static FamilySymbol RetrieveOrLoadCuttingSymbol(
      Document doc )
    {
      FilteredElementCollector a
          = new FilteredElementCollector( doc )
            .OfClass( typeof( Family ) );
      Family family = a.FirstOrDefault<Element>(
        e => e.Name.Equals( FamilyName ) )
          as Family;
      if( null == family )
      {
        // It is not present, so check for 
        // the file to load it from:
        if( !File.Exists( FamilyPath ) )
        {
          ErrorMsg( string.Format(
            "Please ensure that the void cutter "
            + "family file '{0}' is present.",
            FamilyPath ) );
          return null;
        }
        // Load family from file:
        using( Transaction tx = new Transaction(
          doc ) )
        {
          tx.Start( "Load Family" );
          doc.LoadFamily( FamilyPath, out family );
          tx.Commit();
        }
      }
      FamilySymbol cuttingSymbol = null;
      foreach( FamilySymbol s in family.Symbols )
      {
        cuttingSymbol = s;
        break;
      }
      return cuttingSymbol;
    }

  

Cheers,

  

Jeremy

  


Viewing all articles
Browse latest Browse all 67020


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>