I am trying to get the file path of nested families within a Family document. I can retrieve the host family filepath without problem, but I cannot seem to get the filepath of the nested family(ies). Any suggestions or help would be appreciated. The code snippet below should provide some insight into what I am trying to do. I am having issues with the bolded section.
FilteredElementCollector famCollector = new FilteredElementCollector(doc);
ElementCategoryFilter catFilter = new ElementCategoryFilter(BuiltInCategory.OST_SpecialityEquipment);
ICollection<Element> famCollection = famCollector.OfClass(typeof(FamilySymbol)).WherePasses(catFilter).ToElements();
foreach (Element e in famCollection)
{
FamilySymbol fs = e as FamilySymbol;
string filePath = fs.Document.PathName.ToString(); // does not return the correct file path. returns the path of the host family.
TaskDialog.Show("test", filePath); // used to let me see the filepath in a dialog on screen
doc.LoadFamily(filePath);
}
Any help would be appreciated.
Keith
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Dear Keith,
Thank you for your query.
Here are a couple of posts on nested family instances that may help provide some background information for you:
When you query fs.Document, it will obviously return the current document, since that is where the family symbol fs lives.
To query the path of nested families, you would have to open each individual family document using EditFamily and query the path of the families embedded within that.
Here is the latest sample of making a call to the EditFamily method:
http://thebuildingcoder.typepad.com/blog/2014/09/modifying-saving-and-reloading-families.html
If you have specific top level root directories and all your family files live in subdirectories of those, you could also simply use the (hopefully unique) family name (and possibly Revit version) and a recursive file search algorithm through the subdirectory structure to determine their full paths.
By the way, I can suggest two improvements for your sample code snippet:
1. No need to instantiate a new ICollection<Element> container for the elements, because you can iterate directly over the filtered element collector. That saves the duplicate memory allocation and copy process and improves perfomance.
2. You can use the OfCategory shartcut instead of explicitly instantiating a separate ElementCategoryFilter. That saves code and complexity.
http://thebuildingcoder.typepad.com/blog/2012/09/findelement-and-collector-optimisation.html
I hope this helps.
Best regards,
Jeremy
Thanks Jeremy for the reply and the helpful information. I will review the posts you suggest from your blog (which is usually my first resource anyway...) and the changing of the code to make it more efficient. I appreciate your time and will report back any additional issues I might encounter.
Keith