Plan views are level-based. There are three types of plan views, floor plan view, ceiling plan view, and area plan view.
Generally the floor plan view is the default view opened in a new project.
Most projects include at least one floor plan view and one ceiling plan view.
Plan views are usually created after adding new levels to the project.
Adding new levels using the API does not add plan views automatically. Use the static ViewPlan.Create() method to create new floor and ceiling plan views. Use the static ViewPlan.CreateAreaPlan() method to create a new area plan view.
Code Region: Creating Plan Views |
public static ViewPlan ViewPlan.Create(Document document, ElementId viewFamilyTypeId, ElementId levelId); public static ViewPlan ViewPlan.CreateAreaPlan(Document document, ElementId areaSchemeId, ElementId levelId); |
The viewFamilyTypeId parameter in ViewPlan.Create() needs to be a FloorPlan, CeilingPlan, AreaPlan, or StructuralPlan ViewType. The levelId parameter represents the Id of the level element in the project to which the plan view is associated.
The following code creates a floor plan and a ceiling plan based on a certain level.
Code Region: Creating a floor plan and ceiling plan |
// Find a floor plan view type IEnumerable<ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType)) let type = elem as ViewFamilyType where type.ViewFamily == ViewFamily.FloorPlan select type; // Create a Level and a Floor Plan based on it double elevation = 10.0; Level level1 = document.Create.NewLevel(elevation); ViewPlan floorView = ViewPlan.Create(document, viewFamilyTypes.First().Id, level1.Id); // Create another Level and a Ceiling Plan based on it // Find a ceiling plan view type viewFamilyTypes = from elem in new FilteredElementCollector(document).OfClass(typeof(ViewFamilyType)) let type = elem as ViewFamilyType where type.ViewFamily == ViewFamily.CeilingPlan select type; elevation += 10.0; Level level2 = document.Create.NewLevel(elevation); ViewPlan ceilingView = ViewPlan.Create(document, viewFamilyTypes.First().Id, level2.Id); |
After creating a new plan view, the Discipline for the view can be set using the Discipline parameter which is type ViewDiscipline. Options include Architectural, Structural, Mechanical, Electrical, Plumbing and Coordination.
For structural plan views, the view direction can be set to either Up or Down using the ViewFamilyType.PlanViewDirection property. Although it is a property of the ViewFamilyType class, an exception will be thrown if the property is accessed for views other than StructuralPlan views.
The view range for plan views can be retrieved via the ViewPlan.GetViewRange() method. The returned PlanViewRange object can be used to find the levels which a plane is relative to and the offset of each plane from that level. It is the same information that is available in the View Range dialog in the Revit user interface:
The following example shows how to get the top clip plane and the associated offset for a plan view
Code Region: Getting information on the view range |
private void ViewRange(Document doc, View view) { if (view is ViewPlan) { ViewPlan viewPlan = view as ViewPlan; PlanViewRange viewRange = viewPlan.GetViewRange(); ElementId topClipPlane = viewRange.GetLevelId(PlanViewPlane.TopClipPlane); double dOffset = viewRange.GetOffset(PlanViewPlane.TopClipPlane); if (topClipPlane.IntegerValue > 0) { Element levelAbove = doc.GetElement(topClipPlane); TaskDialog.Show(view.Name, "Top Clip Plane: " + levelAbove.Name + "\r\nTop Offset: " + dOffset + " ft"); } } } |