Set view range for ceiling plan

Hello,

I begun with Dyanmo no long ago and I’m having some trouble with setting the view range.
I’ve seen in an old post a python script to choose the view range and set it on one or multiples view plans. I’m not familiar with python code but I king of understand how it works.

The python block didn’t work and I realised that it’s because my views are ceiling plans and not floor plans. I tried to change the code to adapt the view range for ceiling plans but it seems that I only make it worse.

Does someone know what I could try ?

Thank you.

Python script shared by kennyb6 in the old post :

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

def modViewrange(vp,tof,bof,cof):
	v = UnwrapElement(vp)
	#getting the viewrange of the view
	viewrange = v.GetViewRange()
	asslvl = v.GenLevel
	#Setting top clip plane of the viewrange
	#	Setting level of topclip plane
	viewrange.SetLevelId(PlanViewPlane.TopClipPlane,asslvl.Id)
	#	setting offset of top clip plane
	viewrange.SetOffset(PlanViewPlane.TopClipPlane,tof)
	#Setting bottom clip plane of the viewrange
	#	Setting level of bottom clip plane
	viewrange.SetLevelId(PlanViewPlane.BottomClipPlane,asslvl.Id)
	#	setting offset of bottom clip plane
	viewrange.SetOffset(PlanViewPlane.BottomClipPlane,bof)
	viewrange.SetOffset(PlanViewPlane.CutPlane,cof)
	#Setting view depth plane of the viewrange
	#	Setting level of view depth plane
	viewrange.SetLevelId(PlanViewPlane.ViewDepthPlane,asslvl.Id)
	#	setting offset of view depth plane
	if bof < 0 or IN[3]:
		viewrange.SetOffset(PlanViewPlane.ViewDepthPlane,bof)
	else:
		viewrange.SetOffset(PlanViewPlane.ViewDepthPlane,0)
	#Applying the viewrange to the view
	v.SetViewRange(viewrange)

doc = DocumentManager.Instance.CurrentDBDocument

tof = IN[1]
bof = IN[2]
cof = IN[3]
count = 0

TransactionManager.Instance.EnsureInTransaction(doc)
if isinstance(IN[0],list):
	for vp in IN[0]:
		modViewrange(vp,tof,bof,cof)
		count += 1
else:
	modViewrange(IN[0],tof,bof,cof)
	count += 1
TransactionManager.Instance.TransactionTaskDone()

OUT = '%d view ranges altered' %(count)

Error message when I run the dynamo :

Hi,
Is this the original python script or the one you modified?
Additionally just a thought since ceiling plans are reflected, did you try to swap tof and cof inputs?

1 Like

Would it be easier to use View Templates ?

Yes this is the original script, the one I modified didn’t work and I had even more errors.

I noticed something, when I go see the view range in REVIT, I’ve got the view range for a floor plan. Maybe the error is because dynamo consider it like an ceiling plan but revit like a floor plan, is it possible ?

This is the view range I have when I go in revit :
View range impact plan

I tried to swap the 2 inputs but it don’t work.

For ceiling plan you should have a cut plane with an offset lower than the top offset since you’re looking from the bottom up.
Try to set the values manually in Revit to something that fit your needs and then we will go through code.

I’ve tried your idea but the view range I set in the view template don’t sets in the views I create.

Thank you for your help

I think I’ve found why the view range don’t work. The views that I duplicate have a view template in ceiling plan (which is a error in our template) but the duplicated views have a view template in floor, structural plan. Dynamo seems to keep the information of the orginal views so I’m going to change our template to adjust this and see if it works.