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 cut through the model to expose the interior structure. The ViewSection.CreateSection() method creates the section view.
Code Region: ViewSection.CreateSection() |
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 |
// Find a section view type IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType)) let type = elem as ViewFamilyType where type.ViewFamily == ViewFamily.Section select type; // Create a BoundingBoxXYZ instance centered on wall LocationCurve lc = wall.Location as LocationCurve; Transform curveTransform = lc.Curve.ComputeDerivatives(0.5, true); // using 0.5 and "true" (to specify that the parameter is normalized) // places the transform's origin at the center of the location curve) XYZ origin = curveTransform.Origin; // mid-point of location curve XYZ viewDirection = curveTransform.BasisX.Normalize(); // tangent vector along the location curve XYZ normal = viewDirection.CrossProduct(XYZ.BasisZ).Normalize(); // location curve normal @ mid-point Transform transform = Transform.Identity; transform.Origin = origin; transform.BasisX = normal; transform.BasisY = XYZ.BasisZ; // can use this simplification because wall's "up" is vertical. // For a non-vertical situation (such as section through a sloped floor the surface normal would be needed) transform.BasisZ = normal.CrossProduct(XYZ.BasisZ); BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = transform; sectionBox.Min = new XYZ(-10,0,0); sectionBox.Max = new XYZ(10,12,5); // Min & Max X values (-10 & 10) define the section line length on each side of the wall // Max Y (12) is the height of the section box// Max Z (5) is the far clip offset // Create a new view section. 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() |
public ViewSection ViewSection.CreateReferenceSection(Document document, ElementId parentViewId, ElementId viewIdToReference, XYZ headPoint, XYZ tailPoint); |
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() |
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.
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 |
ViewSection CreateElevationView(Document document, FamilyInstance beam) { // Find an elevation view type IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType)) let type = elem as ViewFamilyType where type.ViewFamily == ViewFamily.Elevation select type; LocationCurve lc = beam.Location as LocationCurve; XYZ xyz = lc.Curve.GetEndPoint(0); ElevationMarker marker = ElevationMarker.CreateElevationMarker(document, viewFamilyTypes.First().Id, xyz, 1); ViewSection elevationView = marker.CreateElevation(document, document.ActiveView.Id, 1); return elevationView; } |
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.
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() |
public ViewSection ViewSection.CreateCallout(Document document, ElementId parentViewId, ElementId viewFamilyTypeId, XYZ point1, XYZ point2); |
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() |
public ViewSection ViewSection.CreateReferenceCallout(Document document, ElementId parentViewId, ElementId viewIdToReference, XYZ point1, 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.
Only cropped views can be referenced, unless the referenced view is a Drafting view. Drafting views can always be referenced regardless of the parent view type. Elevation views can be referenced from Elevation and Drafting parent views. Section views can be referenced from Section and Drafting parent views. Detail views can be referenced from all parent views except for in FloorPlan, CeilingPlan and StructuralPlan parent views where only horizontally-oriented Detail views can be referenced. FloorPlan, CeilingPlan and StructuralPlan views can be referenced from FloorPlan, CeilingPlan and StructuralPlan parent views.
The following example creates a new callout using a Detail ViewFamilyType and then uses the new callout view to create a reference callout.
Code Region: Creating a callout and reference callout |
public void CreateCalloutView(Document document, View parentView) { // Find a detail view type IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType)) let type = elem as ViewFamilyType where type.ViewFamily == ViewFamily.Detail select type; ElementId viewFamilyTypeId = viewFamilyTypes.First().Id; XYZ point1 = new XYZ(2, 2, 2); XYZ point2 = new XYZ(30, 30, 30); ElementId parentViewId = parentView.Id; // a ViewPlan View view = ViewSection.CreateCallout(document, parentViewId, viewFamilyTypeId, point1, point2); ViewSection.CreateReferenceCallout(document, parentViewId, view.Id, point1, point2); } |