Crop Region by curve

try this: http://dp-stuff.org/room-plans-non-rectangular-viewports-revit-2014/

#dp Stuff | http://dp-stuff.org | createRoomPlanViews
#this Revit Python Script batch generates Room Plan Views
#before running the script select the rooms to generate Plan Views for
 
import clr
import math
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI') 
from Autodesk.Revit.DB import * 

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
 
doc = DocumentManager.Instance.CurrentDBDocument
 
collector = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewFamilyType))
collectorVP = FilteredElementCollector(doc).OfClass(clr.GetClrType(ViewPlan)).WhereElementIsNotElementType()
vtId = 0

expandVal = 0
 
#selected room elements
selEls = UnwrapElement(IN[0])
 
#get elementId of FloorPlan viewFamilyType
for el in collector:
	if el.ViewFamily == ViewFamily.FloorPlan:
		vtId = el.Id
		break
 
TransactionManager.Instance.EnsureInTransaction(doc)
for rm in selEls:
 
	if int(BuiltInCategory.OST_Rooms) == rm.Category.Id.IntegerValue:		
		rmbox = rm.get_BoundingBox(None)
		print rmbox
		minPt = XYZ(rmbox.Min.X-expandVal, rmbox.Min.Y-expandVal, 0)
		maxPt = XYZ(rmbox.Max.X+expandVal, rmbox.Max.Y+expandVal, 0)
		rmbox.Min = minPt
		rmbox.Max = maxPt
		lev = rm.Level
 
		#create a Plan View for the room
		vp = ViewPlan.Create(doc, vtId, lev.Id)
		print vp.Name		
 
		testName = rm.GetParameters('Name')[0].AsString() + ' ' + str(rm.GetParameters('Number')[0].AsString())
 
		for el in collectorVP:
			if el.Name == testName:
				testName = testName + ' (1)'
				break
 
		vp.Name = testName
 
		#2014 custom crop view boundary block
		opt = SpatialElementBoundaryOptions()
		rmBoundarySegListList = rm.GetBoundarySegments(opt)		
		bsList = 0
		crvList = list()
		#get first BoundarySegment Loop
		for bsL in rmBoundarySegListList:
			bsList = bsL
			break
		#create a Curve Loop and make sure they are all lines
		#if a segment is not a line then we tesselate it
		for bs in bsList:
			if bs.GetCurve() is clr.GetClrType(Line):
				crvList.append(bs.GetCurve())
			else:
				#we tesselate the curve
				pts = bs.GetCurve().Tessellate()
				i = -1
				for pt in pts:
					i+=1
					if i < len(pts)-1:
						#create and add linear segments to the future CropBoundary loop
						crvList.append(Line.CreateBound(pts[i], pts[i+1]))	
					myLoop = CurveLoop.Create(crvList)
		#assign CurveLoop to the CropBox of the view
		vp.CropBoxActive = True
		cropManager = vp.GetCropRegionShapeManager()
		if cropManager.IsCropRegionShapeValid(myLoop):					
			cropManager.SetCropShape(myLoop)
		else:
			print 'Not Allowed to manage Crop for ' + vp.Name + ' :-(' 
			vp.CropBox = rmbox
		#END 2014 custom crop view boundary block
		#you can fancy this up by assigning a particular view template etc
 
TransactionManager.Instance.TransactionTaskDone()

OUT = 0
3 Likes