Rotate crop views on sheet

Why not? It’s pretty simple. Here’s some code:

    def RotateCropBox(view, cropBox, angle):
        doc = DocumentManager.Instance.CurrentDBDocument
	bbox = view.CropBox
	center = 0.5 * (bbox.Max + bbox.Min)
	axis = Line.CreateBound(center, center + XYZ.BasisZ)
	ElementTransformUtils.RotateElement(doc, cropBox.Id, axis, angle)
	return view

Now the trick of course is to get the proper angle to rotate the view by, because I am guessing that you are looking to align it with some element in view (wall, grid etc.). To get view crop box I was using a little trick that Jeremy Tammik shared on his blog:

def GetViewCropBoxElement(view):
	doc = DocumentManager.Instance.CurrentDBDocument
	TransactionManager.Instance.ForceCloseTransaction()
	tGroup = TransactionGroup(doc, "Temp to find crop box element")
	tGroup.Start()
	trans1 = Transaction(doc, "Temp to find crop box element")
	trans1.Start()
	view.CropBoxVisible = False
	trans1.Commit()
	
	shownElems = FilteredElementCollector(doc, view.Id).ToElementIds()
	
	trans1.Start()
	view.CropBoxVisible = True
	trans1.Commit()
	
	cropBoxElement = FilteredElementCollector(doc, view.Id).Excluding(shownElems).FirstElement()
	tGroup.RollBack()
	return cropBoxElement

What happens here is that you turn off the crop box, select everything in view, then create exclusion filter for all these elements, then turn the crop box back on and select everything but previously selected things. This should leave you with the only new thing visible in view: CROP BOX.

I will leave the rest for you to figure out.

Cheers!

3 Likes