ImageView
The ImageView class is derived from ViewDrafting. It can be used to create rendering views containing images imported from disk. Use the static ImageView.Create() method to create new rendering views.
ViewSection
The ViewSection class can be used to create section views, detail views, callout views, reference callouts and reference sections. It also represents elevation views.
Section Views and Reference Sections
Section views cut through the model to expose the interior structure. The ViewSection.CreateSection() method creates the section view.
Code Region: ViewSection.CreateSection()
1.
public
ViewSection ViewSection.CreateSection(Document document, ElementId viewFamilyTypeId, BoundingBoxXYZ sectionBox);
The viewFamilyTypeId parameter is the Id for the ViewFamilyType which will be used by the new ViewSection. The type needs to be a
Section ViewFamily. The sectionBox parameter is the section view crop box. It provides the direction and extents which are required for the section view. Usually, another view's crop box is used as the parameter. You can also build a custom BoundingBoxXYZ instance to represent the direction and extents.
The following code shows how to create a section view. A bounding box for the section view is created at the center of a wall. The resulting section view will be located in the Sections (Building Section) node in the Project Browser.
Code Region: Creating a section view
1. // Find a section view type
2. IEnumerable<ViewFamilyType> viewFamilyTypes = from elem
in new
FilteredElementCollector(document).OfClass(
typeof
(ViewFamilyType))
3. let type = elem
as
ViewFamilyType
4. where type.ViewFamily == ViewFamily.Section
5. select type;
6.
7. // Create a BoundingBoxXYZ instance centered on wall
8. LocationCurve lc = wall.Location
as
LocationCurve;
9. Transform curveTransform = lc.Curve.ComputeDerivatives(0.5,
true
);
10. // using 0.5 and "true" (to specify that the parameter is normalized)
11. // places the transform's origin at the center of the location curve)
12.
13. XYZ origin = curveTransform.Origin; // mid-point of location curve
14. XYZ viewDirection = curveTransform.BasisX.Normalize(); // tangent vector along the location curve
15. XYZ normal = viewDirection.CrossProduct(XYZ.BasisZ).Normalize(); // location curve normal @ mid-point
16.
17. Transform transform = Transform.Identity;
18. transform.Origin = origin;
19. transform.BasisX = normal;
20. transform.BasisY = XYZ.BasisZ;
21.
22. // can use this simplification because wall's "up" is vertical.
23. // For a non-vertical situation (such as section through a sloped floor the surface normal would be needed)
24. transform.BasisZ = normal.CrossProduct(XYZ.BasisZ);
25.
26. BoundingBoxXYZ sectionBox =
new
BoundingBoxXYZ();
27. sectionBox.Transform = transform;
28. sectionBox.Min =
new
XYZ(-10,0,0);
29. sectionBox.Max =
new
XYZ(10,12,5);
30. // Min & Max X values (-10 & 10) define the section line length on each side of the wall
31. // Max Y (12) is the height of the section box// Max Z (5) is the far clip offset
32.
33. // Create a new view section.
34. ViewSection viewSection = ViewSection.CreateSection(document, viewFamilyTypes.First().Id, sectionBox);
Reference sections are sections that reference an existing view. Revit does not add a new view when you create a new reference section.
Code Region: ViewSection.CreateReferenceSection()
1.
public
ViewSection ViewSection.CreateReferenceSection(Document document,
2. ElementId parentViewId,
3. ElementId viewIdToReference,
4. XYZ headPoint,
5. XYZ tailPoint);
The parentViewId parameter is the Id of the view in which the new reference section marker will appear. Reference sections can be created in FloorPlan, CeilingPlan, StructuralPlan, Section, Elevation, Drafting, and Detail views. The viewIdToReference can be the Id of a Detail,
Drafting or Section view. The ViewFamilyType of the referenced view will be used by the new reference section. The two XYZ points will determine the location of the section marker's head in the parent view.
Detail Views
A detail view is a view of the model that appears as a callout or section in other views. This type of view typically represents the model at finer scales of detail than in the parent view. It is used to add more information to specific parts of the model. The static
ViewSection.CreateDetail() method is used to create a new detail ViewSection.
Code Region: ViewSection.CreateDetail()
1.
public
ViewSection ViewSection.CreateDetail(Document document, ElementId viewFamilyTypeId, BoundingBoxXYZ sectionBox);
The viewFamilyTypeId parameter is the Id for the ViewFamilyType which will be used by the new ViewSection. The type needs to be a
Detail ViewFamily. Just as for a standard section view, the sectionBox parameter is the section view crop box. It provides the direction and extents which are required for the section view.
When a new detail ViewSection is added, it will appear in the Detail Views (Detail) node in the Project Browser.
Elevation Views
An elevation view is a cross-section of the model where level lines are displayed. An elevation view is represented by the ViewSection class.
However, unlike the other types of section views, you cannot create elevation views using a static method on the ViewSection class. To create an elevation view, first create an elevation marker, then use the marker to generate the elevation view. The newly created elevation view will appear in the Elevations (Building Elevation) node in the Project Browser. It will be assigned a unique name.
The following example creates an elevation view based on the location of a beam.
Code Region: Creating an Elevation View
1. ViewSection CreateElevationView(Document document, FamilyInstance beam)
2. {
3. // Find an elevation view type
4. IEnumerable<ViewFamilyType> viewFamilyTypes = from elem
in new
FilteredElementCollector(document).OfClass(
typeof
(ViewFamilyType))
5. let type = elem
as
ViewFamilyType
6. where type.ViewFamily == ViewFamily.Elevation
7. select type;
8.
9. LocationCurve lc = beam.Location
as
LocationCurve;
10. XYZ xyz = lc.Curve.GetEndPoint(0);
11. ElevationMarker marker = ElevationMarker.CreateElevationMarker(document, viewFamilyTypes.First().Id, xyz, 1);
12. ViewSection elevationView = marker.CreateElevation(document, document.ActiveView.Id, 1);
13.
14.
return
elevationView;
15. }
The ElevationMarker.CreateElevation() method takes an id of a ViewPlan as a parameter. That is the ViewPlan in which the ElevationMarker is visible. The new elevation ViewSection will derive its extents and inherit settings from the ViewPlan. The last parameter is the index on the ElevationMarker where the new elevation view will be placed. The index on the ElevationMarker must be valid and unused. The view's direction is determined by the index.
Callouts and Reference Callouts
A callout shows part of another view at a larger scale. Callout views can be created using the static method ViewSection.CreateCallout().
Callouts can be created in FloorPlan, CeilingPlan, StructuralPlan, Section, Elevation, Drafting and Detail views. The resulting view will be either a ViewSection, ViewPlan or ViewDetail depending on the ViewFamilyType used and will appear in the corresponding node in the Project
Browser.
Code Region: ViewSection.CreateCallout()
1.
public
ViewSection ViewSection.CreateCallout(Document document,
2. ElementId parentViewId,
3. ElementId viewFamilyTypeId,
4. XYZ point1,
5. XYZ point2);
The parent view Id parameter can be the Id of any type of View on which callouts can be created. The point parameters determine the extents of the callout symbol in the parent view.
A reference callout is a callout that refers to an existing view. When you add a reference callout, Revit does not create a view in the project.
Instead, it creates a pointer to a specified, existing view. Multiple reference callouts can point to the same view.
Code Region: ViewSection.CreateReferenceCallout()
1.
public
ViewSection ViewSection.CreateReferenceCallout(Document document,
2. ElementId parentViewId,
3. ElementId viewIdToReference,
4. XYZ point1,
5. XYZ point2);
Creation of a reference callout is similar to creation of a callout. But rather than having the Id of the ViewFamilyType for the callout as a parameter, the CreateReferenceCallout() method takes the Id of the view to reference. The ViewFamilyType of the referenced view will be used by the new reference callout.