Hello guys,
I am trying to use this python script that Mostafa kindly shared long time ago but I am having a problem.
Any one can help???
Python:
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import*
clr.AddReference(‘RevitServices’)
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
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
The error you had shown in the last post said you were getting a “ViewPlan is not iterable” error, so without seeing more, I am assuming it is because you are trying to do a for loop with only one element. Meaning, the script is expecting a list of views as an input but you are only giving one. Either add in more views or try changing the python script to this:
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
v = UnwrapElement(IN[0])
lt = UnwrapElement(IN[1])
tof = IN[2]
lb = UnwrapElement(IN[3])
bof = IN[4]
count = 0
TransactionManager.Instance.EnsureInTransaction(doc)
#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)
Hello Kenny,
Thank you very much for your answer, however your script is giving me a similar problem.
I have created a list of views and used the previous graph and used yours as well and both are giving me the same problem.
IronPythonEvaluator.EvaluateIronPythonScript
operation failed.
unexpected token
See image attached…
Many thanks!!!
Sorry the error was due to copying and pasting. But the problem you are having is that you are not using the correct inputs. In the original post, he uses floors as input for IN[0], and levels as IN[1] and IN[3], in this way:
IN[0] = the view to change
IN[1] = level of top clip range, meaning you need a level as an input, not a number
IN[2] = offset of the top clip range, integer
IN[3] = level of bottom clip range, again needs a level input
IN[4] = offset of the bottom clip range, integer
As for the script for single views, the correct script is:
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
v = UnwrapElement(IN[0])
lt = UnwrapElement(IN[1])
tof = IN[2]
lb = UnwrapElement(IN[3])
bof = IN[4]
count = 0
TransactionManager.Instance.EnsureInTransaction(doc)
#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)
Thank you very much Kenny,
As you can tell I cannot read python, do you know how can include in the script the CUT PLANE OFFSET and VIEW DEPTH ASSOCIATED LEVEL and OFFSET???
Many thanks in advance
As for associated level, there is a node way and a python way. Node way would be checking parameter by name “Associated Level” but it returns a string and you would have to find the level with the string name. Python would use the GenLevel property.
I don’t know the exact command for converting Dynamo units into Revit API units but for now I have an approximation embedded into the script and it works fine. Only uses the view, top offset, and bottom offset to edit the view range.
Now works completelly fine,
I have added a new line to the python script to adjust as well the cut plane offset and seems to be working fine too.
However if I want to apply the cut plane offset based on a list, of values the python script give me an error.
Sorry for my ignorance but I have just starting getting familiar with python.
How easy is to modify the script so we can apply these changes to a list of views???
The same script should work, just change the codeblock next to ViewPlan from "Revit.Elements.Views.FloorPlanView";
to "Revit.Elements.Views.CeilingPlanView";
and then you can filter or not filter how you want. The filter part is the 2nd codeblock, where "Level"; is the word used to filter through the views. You can change it or ignore the nodes all together if you don’t want to filter.
Hi Kennyb6 i’m new learner study dynamo and code in python. i tried to run your code in my project, but i don’t understand why the result is this (in the picture). i think this code have to add a line code to python understand what is units of number you put in code… isn’t it? and how do i add it. i sorry to bother you, and i hope you reply to me. thank you very much