Hi,
i try to use the node Sheet.ByNameNumberTitleBlockAndView in a python script, but i get the error:
Traceback (most recent call last):
File “”, line 27, in
NameError: name ‘Sheet’ is not defined
import clr
clr.AddReference("RevitAPI")
clr.AddReference("ProtoGeometry")
clr.AddReference("RevitNodes")
clr.AddReference("RevitServices")
clr.AddReference('RevitAPIUI')
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
import Autodesk
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import RevitServices
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.DB import *
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
sheetnames= IN[0]
sheetnumbers = IN[1]
titleblocks = IN[2]
viewtypes = IN[3]
sheetlist=[]
for na,nu,t,v in zip(sheetnames,sheetnumbers,titleblocks,viewtypes):
sheetlist.append(Sheet.ByNumberTitleBlockAndViews(na,nu,t,v))
OUT = sheetlist
I don’t understand the purpose of this exercise, but let’s say that you have a good reason to do that instead of just using the ACTUAL node.
Here’s how I would do it:
# Copyright(c) 2017, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
sheet_names= IN[0]
sheet_numbers = IN[1]
titleblocks = IN[2]
views = IN[3]
sheet_list=[]
try:
errorReport = None
for na,nu,t,v in zip(sheet_names,sheet_numbers,titleblocks,views):
sheet_list.append(Revit.Elements.Views.Sheet.ByNameNumberTitleBlockAndView(na,nu,t,v))
except:
# if error occurs anywhere in the process catch it
import traceback
errorReport = traceback.format_exc()
# Assign your output to the OUT variable
if None == errorReport:
OUT = 0
else:
OUT = errorReport
So first and foremost, the actual API call here is Sheet.ByNameNumberTitleBlockAndView() This particular call would match your input types. The reason you were getting the error that Sheet is not defined is because you imported the Revit namespace and then called a method that was at Revit.Elements.Views. So you either import that namespace directly or call it with the long form like I did.
Anyways, like I said, this works, but there are so many things wrong with this approach that I don’t even want to start listing them all off.