Family Load error using NewFamilyInstance

Family Load error using NewFamilyInstance

Anonymous
Not applicable
541 Views
1 Reply
Message 1 of 2

Family Load error using NewFamilyInstance

Anonymous
Not applicable

I'am loading attached families through c# api code in Revit 2015. But each time I get

 

"A serious error has occurred. It is strongly recommended that you use Save As to save your work in a new file before continuing."  this message. 

Manually those families  are loaded successfully.

I can't figure out the issue.

0 Likes
542 Views
1 Reply
Reply (1)
Message 2 of 2

BIM.Frankliang
Collaborator
Collaborator

Hi chakrabortyambar,

 

     I don't know how do you use C# RevitAPI to load family. You could try to use codes below:

  public Family LoadFamily(Autodesk.Revit.DB.Document doc, string familyPath)
  {
       try
       {
           Family family = null;
           var rfaFileName = Path.GetFileNameWithoutExtension(familyPath);
           if (new FilteredElementCollector(doc).OfClass(typeof(Family)).Count(m => m.Name == 
rfaFileName) == 0) { if (!File.Exists(familyPath)) { return null; } doc.LoadFamily(familyPath, out family); if (family == null) { List<Family> families = new FilteredElementCollector(doc).OfClass(typeof(Family)).ToElements().Cast<Family>().Where(f => f.Name == rfaFileName).ToList(); if (families.Count > 0) { family = families.FirstOrDefault(); } } } else { family = new FilteredElementCollector(doc).OfClass(typeof(Family)).FirstOrDefault(m => m.Name == rfaFileName) as Family; } return family; } catch (Exception ex) { return null; } }

Note that codes must run in Transaction 🙂

 

0 Likes