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.

Hello @Sam73

try this

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
	viewrange.SetLevelId(PlanViewPlane.TopClipPlane,asslvl.Id)
	viewrange.SetOffset(PlanViewPlane.TopClipPlane,tof)
	#Setting bottom and cut clip plane of the viewrange
	viewrange.SetLevelId(PlanViewPlane.BottomClipPlane,asslvl.Id)
	viewrange.SetOffset(PlanViewPlane.BottomClipPlane,cof)
	viewrange.SetLevelId(PlanViewPlane.CutPlane,asslvl.Id)
	viewrange.SetOffset(PlanViewPlane.CutPlane,cof)
	#Setting view depth plane of the viewrange
	viewrange.SetLevelId(PlanViewPlane.ViewDepthPlane,asslvl.Id)
	viewrange.SetOffset(PlanViewPlane.ViewDepthPlane,tof)
	#Applying the viewrange to the view
	v.SetViewRange(viewrange)
1 Like

Hello,

Thank you very much, this is working for ceiling plan.

I have an other question a little off topic but it have a link with the view range I want to set :
I’ve notice that the views I want to modify are ceiling plan in the Dynamo that duplicate the views
Dans GA-Impact
But when I select them in a new Dynamo, they are structural plans
Dans nouveau
It’s our template that “says” to the view to be structural plan (by looking down) so it is normal that they are structural plans when I select them in a new Dynamo but, I don’t understand why in the original dynamo (where I duplicate my views) they’re not.
Do you know why ?

Hello
A structural view with an upward direction is equated to a type of Ceiling view in Revit API
Up

No problem with a down direction
Down

Thanks, I understand know from where it comes.