Geometry Viewers
The previous post provided an overview of the Revit geometry library and very briefly mentioned some geometry viewers provided in the Revit SDK samples. We will discuss these a little bit more before moving on to some own example code dealing with geometry.
The Revit SDK currently includes the following viewers:
- AnalyticalViewer
- ElementViewer
- RoomViewer
- RevitViewer
- ObjectViewer
All the viewers query a selected Revit element for some specific geometry, traverse it, break it down into simple line segments, and render those into a .NET System.Windows.Forms PictureBox. They can all be classified as pretty basic samples. The first four of these are all located in the subdirectory Viewers and are implemented in VB. They were introduced early on in the Revit API, with version 8.0. Of these four, the RevitViewer is a helper class, which implements the actual viewer window which is used by the other three to present three different views of certain subsets of the building model. ObjectViewer was introduced later, in the Revit 9.0 SDK, is written in C#, and defines its own rendering window. Below is an example of the form defined by RevitViewer; in this case, it is being driven by the ElementViewer sample and displaying a wall with a door and two little windows in it. The wall has been generated by the external command defined by Lab2_0_CreateLittleHouse in the Revit API introduction labs. The form looks identical when driven by the AnalyticalViewer and RoomViewer samples, only the content displayed differs:
The AnalyticalViewer is for Revit Structure, to view the analytical building model. The analytical model is generally a simplified approximation of the building structure for structural analysis purposes, which is of most interest to the structural engineer. Revit Structure maintains the analytical model in parallel with the physical model, which is what architects and most other people are interested in.
ElementViewer is designed for all flavours of Revit and displays the standard element geometry.
RoomViewer is a viewer for displaying the two-dimensional outline of a room boundary.
Just like the three viewers, just discussed, ObjectViewer demonstrates viewing elements. It allows the user to select between the analytical and physical model, and also which view to display. You might thus say that it is a combination of the AnalyticalViewer and the ElementViewer with some additional features.
ObjectViewer includes both generic functionality usable in all Revit flavours, as well as some Revit Structure specific functionality. It displays a selected single element in a preview window and retrieves geometry from either the analytical or physical model. It also includes some additional useful odds and ends such as defining an own error message exception handling class and some unit handling functionality. ObjectViewer was originally introduced in Revit 9. Another very similar sample named ObjectViewerII was introduced in 9.1. ObjectViewerII was removed in the 2008.2 SDK update, being very similar to ObjectViewer.
For all of the viewers, the steps to run are similar: simply select the element whose geometry or the room whose boundary to display and start the external command. The analytical viewer will check whether any analytical model is available, which requires Revit Structure functionality. In the case of the ObjectViewer, all display views are listed, the detail level can be selected, and analytical and physical model can be switched.
Now that we have looked a bit at some basic information on the Revit geometry and SDK samples, let us finally move on to some own example code dealing with geometry.



Subscribe
Hi Jeremy,
I want to get the FamilyInstance geometry hierarchy, but I only can get Solid inside FamilyInstance geometry.
for example:
FamilyInstance F include one Column C0 , include FamilyInstance F1 and F2,
F1 include two Column C1,C2, F2 include two Column C3,C4.
I use below prototype code to get the geometry of FamilyInstance F :
Autodesk.Revit.Geometry.Element geoElement = FamilyInstance .get_Geometry(opts)
geoElement .Objects; // this will return one Autodesk.Revit.Geometry.Instance
Autodesk.Revit.Geometry.Instance instance = geoElement .Objects[0];
Autodesk.Revit.Geometry.Element instanceGeo = instance.SymbolGeometry;
instanceGeo.Objects
// this will return 5 Solid, C0,C1,C2,C3,C4, but we don't know which Solid is C0,
//which Solid is C1, and so on, because Autodesk.Revit.Geometry.Solid has no
//useful property to indicates which Column the Solid belong to.
What i wanted result is:
How can i get the geometry that has the hierarchy:
F
|.___C0
|
|.___F1
|.........|___C1
|.........|___C2
|
|___F2
..........|___C3
..........|___C4
Can you help me, thanks in advance.
Benson
Posted by: Ben | April 28, 2009 at 00:43
Dear Benson,
I am afraid I do not understand how your family instance F can include both a column and other family instances F1 and F2. How has this hierarchy been defined and constructed? Please provide some additional information on the context of the whole situation and how the family instances have been created. That might give us a hint on how to identify which solid belongs to which column. From the information you provide so far, I really cannot say.
Cheers, Jeremy.
Posted by: Jeremy Tammik | April 28, 2009 at 11:25
Dear Jeremy,
Thanks for your reply so quickly.
Below is my steps to create the familyInstance:
1. Run Revit2009
2. Click Menu File->New->Family, then select one Metric Template,such as Metric Funiture.rft, then click Open button.
3. Delete all object in the new Family project, switch to 3D view.
4. Click Mneu File->Load from Library->Load Family, go to directory : c:\Document and Setting\All User\Application Data\Autodesk\RAC 2008\Metric Library\Columns
(maybe the directory not the same as your machine)
then select one rfa file, click Open button on load family dialog.
5. Now, we can find the Column under Project browser Panel->Families->Columns
6. Select this Column, then click right mouse, then click pop-up menu "Create Instance", then draw it to the created family project.
do again of step6, now we have two columns in the family project.
7. Save the project as myFamily1.rfa, then click File->Save as to myFamily2.rfa.
Now, we have two family project myFamily1.rfa and myFamily2.rfa, .
8. Do step2,step3,
step4 (add column family, myFamily1,myFamily2).
9. create instance of column,myFamily1,myFamily2 to the current family project like step6
10. Save the project as myFamily3.rfa.
11. Create one normal project, name project1.rvt , click menu File->New->Project
12. Load Family myFamily3.rfa like step4
13. Add instance of myFamily3 like step6
Now, the project structure like:
F (myFamily3)
|.___C0 (Column)
|
|.___F1 (myFamily1)
|.........|___C1 (Column)
|.........|___C2 (Column)
|
|___F2 (myFamily2)
..........|___C3 (Column)
..........|___C4 (Column)
First way:
In current project project1.rvt , I can get myFamily3 instance via API, the class is Autodesk.Revit.Elements.FamilyInstance.
Then i try to get its geometry:
Autodesk.Revit.Geometry.Element geoElement = FamilyInstance.get_Geometry(opts);
Autodesk.Revit.Geometry.GeometryObjectArray geometries = geoElement.Objects;
//geometries include one Autodesk.Revit.Geometry.Instance , then get its geometry
Autodesk.Revit.Geometry.Instance geoInstance = geometries[0];
Autodesk.Revit.Geometry.Element symbolGeo = geoInstance.SymbolGeometry;
Autodesk.Revit.Geometry.GeometryObjectArray symbolGemetries = symbolGeo.Objects;
// Now symbolGemetries has 5 Solid.
//But I can't find out which solid is belong to which Column, it has no relation
// between Solid to FamilyInstance.
Another way:
Autodesk.Revit.Elements.FamilyInstance.Symbol.Family.Components
I use this class to get FamilyInstance:
foreach(Autodesk.Revit.Element elem in Autodesk.Revit.Elements.FamilyInstance.Symbol.Family.Components)
{
// there are 3 Autodesk.Revit.Elements.FamilyInstance , it is Column, myFamily1, myFamily2
//then we can loop myFamily1, myFamily2 also.
// then get all the Column geometry
// But all the Column's position is the same, because the geometris are gotten from Symbol.
// Not the actually position in project1.rvt
}
So, the first way can get the right position, but can't get the right structure.
the second way can get the right structure, but can't get the right position.
What I want is the right structure and right position.
Best regards,
Benson
Posted by: Ben | April 28, 2009 at 18:41
Dear Benson,
Thank you very much for the detailed description. I started exploring and answering your question, and ended up writing rather a lot of text and sample code, so I will pack it up into a new post for the near future. I'll send you a draft of the post for review and additional exploration.
Cheers, Jeremy.
Posted by: Jeremy Tammik | April 30, 2009 at 07:33