That probably means it was successful because I messed up in the code on the output. Use this instead:
################### Import References ###################
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
################### Definitions ###################
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
################### Inputs ###################
#get the bool in port IN[0]...
r = tolist(IN[0])
r = r[0]
#get the sheet in port IN[1] and UnwrapElement if not already...
sht = tolist(UnwrapElement(IN[1]))
#ensure only one sheet is passed (Multiple Sheets not allowed in this example)...
#get the views in port IN[1] and UnwrapElement if not already...
views = tolist(UnwrapElement(IN[2]))
#get the points in port IN[2] (no need to unwrap as these are Dynamo Points)...
locs = tolist(IN[3])
################### Outputs ###################
outList = []
################### Script ###################
if r:
for s, vws, ls in zip(sht,views,locs):
if len(vws) == len(ls):
temp = []
for v,l in zip(vws, ls):
TransactionManager.Instance.EnsureInTransaction(doc)
try:
if Viewport.CanAddViewToSheet(doc,s.Id,v.Id):
vp = Viewport.Create(doc,s.Id,v.Id,l.ToXyz())
temp.append(vp)
except Exception, e:
temp.append(e.message)
TransactionManager.Instance.TransactionTaskDone()
outList.append(temp)
else:
outList.append("Number of Views must match the number of Locations")
OUT = outList
else:
OUT = "Set Run to True"
################### Import References ###################
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
################### Definitions ###################
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
################### Inputs ###################
#get the bool in port IN[0]...
r = tolist(IN[0])
r = r[0]
#get the sheet in port IN[1] and UnwrapElement if not already...
sht = tolist(UnwrapElement(IN[1]))
#ensure only one sheet is passed (Multiple Sheets not allowed in this example)...
#get the views in port IN[1] and UnwrapElement if not already...
views = tolist(UnwrapElement(IN[2]))
#get the points in port IN[2] (no need to unwrap as these are Dynamo Points)...
locs = tolist(IN[3])
################### Outputs ###################
outList = []
################### Script ###################
if r:
for s, vws, ls in zip(sht,views,locs):
if len(vws) == len(ls):
temp = []
for v,l in zip(vws, ls):
TransactionManager.Instance.EnsureInTransaction(doc)
try:
if Viewport.CanAddViewToSheet(doc,s.Id,v.Id):
vp = Viewport.Create(doc,s.Id,v.Id,l.ToXyz())
temp.append(vp)
else:
temp.append('CanAddViewToSheet is false')
except Exception, e:
temp.append(e.message)
TransactionManager.Instance.TransactionTaskDone()
outList.append(temp)
else:
outList.append("Number of Views must match the number of Locations")
OUT = outList
else:
OUT = "Set Run to True"
That’s what I thought. At line 45, the script does a check if you can add a view to the sheet. If you can, it does. The last code I posted will say you can’t if it says you can’t.
That is probably because you are using only one view as an input in a list, so instead of a list of list, it is just a list. Either make sure each sublist in views and locations is a list or you will have to change the python code to work using it.