I working on my Python understanding.
I am trying to use room to generate Plan and Elevation Views.
I have success with
- extracting the room boundary’s to set the crop of a plan view
- placing an elevation marker in the center point.
- create elevation view for the marker.
Where I’m getting stuck is setting the crop of the elevations.
I thought it might be straight forward, by setting the elevation View CropBox to be the room Bounding Box.
It is not. I’ve been all over the web looking to solve this, but stumped.
import clr
# import RevitNodes
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# import Revit API
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# import system.
import System
from System.Collections.Generic import *
# get the current Revit document.
doc = DocumentManager.Instance.CurrentDBDocument
#collect all levels
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
#selecte frist level in list
level = levels[0]
#repeat for rooms
#note delete unclosed rooms as selecting an unclosed room will cause errors with the curveloop for plan view
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).ToElements()
room = rooms[0]
#collect View Types.
viewTypes = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
#string Type Name for plan. -Note error may cause if elevation and plan have same type name
planview ="Floor Plan"
planViewType = [ viewType for viewType in viewTypes if viewType.LookupParameter("Type Name").AsString()==planview]
planViewType=planViewType[0]
TransactionManager.Instance.EnsureInTransaction(doc)
#create view plan view
viewPlan = ViewPlan.Create(doc,viewType.Id,level.Id)
#Extract Room Boundary curves the make into curve loop to use for crop.
options = SpatialElementBoundaryOptions()
boundloc = AreaVolumeSettings.GetAreaVolumeSettings(doc).GetSpatialElementBoundaryLocation(SpatialElementType.Room)
options.SpatialElementBoundaryLocation = boundloc
curves = []
try:
for boundarylist in room.GetBoundarySegments(options):
for boundary in boundarylist:
curves.append(boundary.GetCurve())
except: pass
roomBoundaryCurveLoop = CurveLoop.Create(curves)
#Turn on Crop view and apply crop using room boundary.
viewPlan.CropBoxActive = True
viewPlan.GetCropRegionShapeManager().SetCropShape(roomBoundaryCurveLoop)
#get mid point of room bounidng box to use for inserting elevation marker.
roomBoundingBox=room.get_BoundingBox(None)
roomMidPoint=(roomBoundingBox.Min + roomBoundingBox.Max)/2
eleView ="10mm Circle"
eleViewType = [ viewType for viewType in viewTypes if viewType.LookupParameter("Type Name").AsString()==eleView]
eleViewType=eleViewType[0]
#Place New Elevation Marker in Ceter Of room
eleMarker = ElevationMarker.CreateElevationMarker(doc,eleViewType.Id,roomMidPoint ,20)
eleView= eleMarker.CreateElevation(doc,viewPlan.Id,0)
#Attempting to use RoomBoundingBox to set crop for elevation?
cropBbox=BoundingBoxXYZ()
cropBbox.Min=roomBoundingBox.Min
cropBbox.Max=roomBoundingBox.Max
eleView.CropBoxActive = True
eleView.CropBox = cropBbox
TransactionManager.Instance.TransactionTaskDone()
OUT=level,room,viewType,viewPlan,eleViewType,roomBoundingBox,roomMidPoint