Created views upside down; Rotate crop?

I am trying to automate the creation of sheets with 3 section views(top side front) of windows. I used Dieter Vermeulens code to create the section views.

To place the views on a sheet I used code from Daniel_Woodcock1.

But currently I am running into a problem; the section Side(top) created by Dieter Vermeulens script is upside down, I tried changing various things in the element view creation code but could not manage to get it with the right way upwards.

I then realised I could also make it work by rotating the viewport on sheet, however revit only allows up to 90 degrees rotation on sheets. I tried using the code from the link below but it didn’t do what I desire

I am now trying to rotate the cropview, effectively rotating the view. But even this I can’t get to work and now I pretty much ran out of ideas.

So I’m wondering can Dieter Vermeulens code be changed in such a way that the side(top) view rotates 180*. Or if that is not possible can crop views be rotated to effectively rotate the view?

This is what I currently have:

And this is the result I’m looking for:

Thank you in advance

@Konrad_K_Sobon @Dieter_Vermeulen

I’ve noticed the same thing and have been looking on how to flip it.

Are you creating views the same way as I am? Because I managed to get them oriented the right direction by playing with the vectors until I got the correct result.
If not, I’m not sure how to rotate the crop regions. I might have managed to rotate them but don’t quite remember.

I will have to play with them and see if I can get them to face the correct direction. Thanks it’s been driving crazy with everyone complaining.

Hey,

This works, hopefully you can make use of it…

Happy Christmas,

Mark

#all thanks to Konrad @ Archi-lab, Jeremy Tammik and pretty much everyone else on the forum!  No credit goes to me for this.

import clr

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

rot = IN[0]
viewport = UnwrapElement(IN[1])

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
	
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)
    TransactionManager.Instance.EnsureInTransaction(doc)
    ElementTransformUtils.RotateElement(doc, cropBox.Id, axis, angle)
    TransactionManager.Instance.TransactionTaskDone()
    
    return view

crpbx = GetViewCropBoxElement(viewport)
crpbxRt = RotateCropBox(viewport, crpbx, rot)

OUT = crpbx, crpbxRt

image

2 Likes

This is awesome, Thanks!
Is it possible to feed in a list of viewports?

No worries, apologies I can’t test it right now, but amending it to something like…

For v in viewport:
    crpbx = GetViewCropBoxElement(v)
    crpbxRt = RotateCropBox(v, crpbx, rot)

should work? have a play with it :slight_smile:

Cheers,

Mark

2 Likes

Hi! When I try this code, the view rotates but not the crop box…any ideas?

Thanks!!

1 Like