Set View Range Parameters

I would like to set certain parameters for the View Range of specific views (ie Top Offset, Cut Plane, etc.). I know how to setup the views I want to collect and all that and I read through a post on retrieving the view range parameters but not setting them. Thus, I was wondering if anyone could help me figure out a way to set those parameters.

If using python, this is what I’d like to do:

import clr

Import RevitAPI

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

Import ToDSType(bool) extension method

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
elements = []
for i in IN[0]:
elements.append(UnwrapElement(i))

for i in elements:
a=[]
a.append(elements[i].SetViewRange().SetOffset(PlanViewPlane.TopClipPlane))
#Assign your output to the OUT variable.
OUT = [a]

ERROR 1: I don’t know much about .SetViewRange() and if this is the way to go.

ERROR 2: I want to make it so I can run it with multiple views and not just once. Hence, the for loops ,however, this portion of the code:

for i in elements:
a=[]
a.append(elements[i].

does not work. Any ideas?

Hi @Dynamonkey

here are some elements that can help you :

in order to use SetViewRange, you first need to get the viewrange of the view (GetViewRange) and set some of its parameters . Here is a code that sets the parameters of the top clipping plane and the bottom clipping p

1. Import RevitAPI, TransactionManager and DocumentManager

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

doc = DocumentManager.Instance.CurrentDBDocument


views = UnwrapElement(IN[0])
ltop = UnwrapElement(IN[1])
toffset = IN[2]
lbottom = UnwrapElement(IN[3])
boffset = IN[4]
count = 0

TransactionManager.Instance.EnsureInTransaction(doc)

for v,lt,tof,lb,bof in zip(views,ltop,toffset,lbottom,boffset):

2. Getting the viewrange of the view

    viewrange = v.GetViewRange()

3. Setting the parameters of the viewrange

* Setting level of topclip plane

 viewrange.SetLevelId(PlanViewPlane.TopClipPlane,lt.Id)

* setting offset of top clip plane

  viewrange.SetOffset(PlanViewPlane.TopClipPlane,tof)

* Setting level of bottom clip plane

   viewrange.SetLevelId(PlanViewPlane.BottomClipPlane,lb.Id)

* setting offset of bottom clip plane

   viewrange.SetOffset(PlanViewPlane.BottomClipPlane,bof)

* Applying the viewrange to the view

    v.SetViewRange(viewrange)
    count = count +1

TransactionManager.Instance.TransactionTaskDone()


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

you can set the level and offset for :

I gave inputs for plane levels and offsets but these can be determined from the viewplans themselves…

1 Like

Here’s an easier to copy paste version of the code :slight_smile:

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

doc = DocumentManager.Instance.CurrentDBDocument


views = UnwrapElement(IN[0])
ltop = UnwrapElement(IN[1])
toffset = IN[2]
lbottom = UnwrapElement(IN[3])
boffset = IN[4]
count = 0

TransactionManager.Instance.EnsureInTransaction(doc)

for v,lt,tof,lb,bof in zip(views,ltop,toffset,lbottom,boffset):


	#getting the viewrange of the view
	viewrange = v.GetViewRange()

	#Setting top clip plane of the viewrange
	#	Setting level of topclip plane
	viewrange.SetLevelId(PlanViewPlane.TopClipPlane,lt.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,lb.Id)
	#	setting offset of bottom clip plane
	viewrange.SetOffset(PlanViewPlane.BottomClipPlane,bof)


	#Applying the viewrange to the view
	v.SetViewRange(viewrange)
	count = count +1

TransactionManager.Instance.TransactionTaskDone()


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

Thanks @Mostafa_El_Ayoubi this looks promising. I however cannot get it to run properly. To simplify I am only testing the top offset with 2 inputs.
IN[0] being a list of views and IN[1] being the top offset value which I’ve tried using a number slider, integer slider, string in all dimensional formats such as x’ x" but yet I get an error pointing to the for loop

for v,lt,tof,lb,bof in zip(views,ltop,toffset,lbottom,boffset):

which for this exercise I adjusted again only for top offset:

for v,tof in zip(views,toffset):

not sure if the for loop is the error but it points to that line and reads Typeerror: ___ not iterable

Perhaps there is a way to input the desired height offset properly.
Any thoughts?

If you want to use the same offset value for all view ranges , then you should only iterate through the list of views :

for v in views :
.
.
.

If you want a specific offset for each view than you must give the python node a list of offset values (same number of values as there are views)

@Mostafa_El_Ayoubi many thanks!

Hello Mostafa,
I am trying to use your python script but there is a problem.
Any help would be really appreciated.

Untitled-2

Since you’ve made a new post I’m going to close this (it’s over a year old anyway) and let the conversation continue there.