-1

I've been having issues with the following snippet of code when working with my addin:

doc.LoadFamilySymbol(@"[filepath here]", "[filename here]", out FamilySymbol symbol);
doc.Create.NewFamilyInstance(mid, symbol, d, GetLevelInformation(d), StructuralType.NonStructural);

As far as I can tell while debugging, the FamilySymbol variable symbol is null after I pass the first line. mid, d, and GetLevelInformation all work and contain the expected values, so I suspect the problem lies within the first line.

Paxy
  • 1
  • 5

2 Answers2

0

Looking at the LoadFamilySymbol method overloads, I see none that takes the two arguments you specify. To load a specific family symbol, you need to specify at least the family name and the family type name you need. What version of Revit are you working with?

To solve this, please look at some of the immense amount of sample code available, e.g., in the Revit SDK samples and in The Building Coder topic group on loading a family.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Sorry, that was a documentation error. I do have 3 arguments, and I am using the ```LoadFamilySymbol(String, String, FamilySymbol ) ``` method. However, as one issue was fixed another arose. I am getting the error: _A sub-transaction can only be active inside an open Transaction._ stemming from what I believe to be the LoadFamilySymbol line. The variable ```doc``` is declared as follows: ```UIApplication uiapp = commandData.Application; Document doc = uiapp.ActiveUIDocument.Document;``` Thanks Jeremy! – Paxy Jan 13 '20 at 13:04
  • Just search for a working sample add-in, base your code on that and all will be fine. https://www.google.com/search?q=LoadFamilySymbol&as_sitesearch=thebuildingcoder.typepad.com – Jeremy Tammik Jan 14 '20 at 17:04
0

Figured I'd update this thread for those with similar problems since I did end up solving my issue. The answer was that I was attempting to load a Family using the Name parameter while what I was really looking for was a FamilyName parameter.

The fix for this was changing x.Name to x.FamilyName as seen below:

FilteredElementCollector collector = new FilteredElementCollector(doc);
            FamilySymbol symbol = collector.OfClass(typeof(FamilySymbol))
                .WhereElementIsElementType()
                .Cast<FamilySymbol>()
                .First(x => x.FamilyName == "[Family Name]");

There is a difference! Thanks for the responses, Jeremy.

Paxy
  • 1
  • 5