Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Family Document - Getting Nested Family File Paths

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
kwhite
1515 Views, 2 Replies

Family Document - Getting Nested Family File Paths

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

 

2 REPLIES 2
Message 2 of 3
jeremytammik
in reply to: kwhite

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3
kwhite
in reply to: jeremytammik

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community