Here are some notes on accessing the geometry of imported or linked files from a case handled by my colleague Joe Ye:
Question: How can I access the geometry of imported or linked Revit RVT, AutoCAD DWG, and SketchUp SKP files?
For instance, I have created a file Wall.rvt containing a wall and use Import/Link to insert it into LinkWall.rvt. Now, when traversing the entities of LinkWall.rvt, I see an Autodesk.Revit.Element.Instance using a Symbol which seems to be the imported or linked Wall.rvt file. How can I access the elements from the Symbol so that I can recursively traverse the imported/linked file? Furthermore, how can I do the same for an imported or linked SketchUp or DWG file?
Answer: Each imported or linked Revit project generates a document instance in the Revit Application object's document collection Application.Documents. Each imported RVT file maps to one document. You can determine the document name from the symbol, and then traverse all documents in the collection to find the appropriate one. From the corresponding document instance, you can access its elements in the usual way, for instance using Document.get_Element or Document.get_Elements. Unfortunately, we currently have no solution for resolving the issue of two identically named linked files.
With regard to imported DWG or SKP files, there is no way to access elements in the imported or linked file.
For more details on these steps, please refer to the preceding discussions on linked files, how to hide them, and listing their elements.
Dear Jeremy,
I hope you can give me some advise on this. Based on the information in this blog I was thinking of creating a separate rvt file with all our wall system families. Then remove the wall system families from our company template. Via the API, link the rvt file with all our wall system families to a project and show these walls in a listbox. Then add the selected walls to the Revit project for further use.
Is there a more logic approach for this? If not is there a way to load an rvt file via API?
Regards,
Bas Hendriks
Posted by: Bas Hendriks | March 04, 2010 at 05:53
Dear Bas,
To start at the end, yes, for sure you can load a file via the API. Do you mean load a family into a project? That would be an RFA file, not RVT. Do you mean open an existing project? That would be an RVT file. Yes, you can open a project in the API, but it does not become visible to the user, it can only be manipulated via the API.
The rest of your ideas sound fine to me, but I am not a user, so I cannot tell whether the workflow is optimal. It sounds doable from the API point of view, as far as I can tell.
Cheers, Jeremy.
Posted by: Jeremy Tammik | March 04, 2010 at 12:38
Dear Jeremy,
Correct me if I'm wrong but as far as I know a System Familiy as in my case Walls can't reside into a project RFA file. Therefor I thought of putting the Wall System Families into a RVT file and link it to a project so I can add them if required.
Do you have an example of opening a project RVT file? Together with the code on "linked files" I can realise my idea.
Many thanks,
Bas
Posted by: Bas Hendriks | March 04, 2010 at 15:24
Dear Bas,
Oops, yes, of course, right you are, system families are built in and cannot be redefined in RFA files.
You can use the Application OpenDocumentFile method to open an RVT project file. The only example of calling it that I found off-hand is in the FamilyCreation AutoParameter sample, although it is only interested in opening family files. It is pretty straight-forward to use.
Cheers, Jeremy.
Posted by: Jeremy Tammik | March 09, 2010 at 11:15