'List[Object]' has no attribute 'Id'

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"

i use this code, but it’s not working properly.

Output is empty.-With Flatten
Output is List Object Error -Without Flatten.

i used both condition.

Still following thris thread.
Can you please show the error from the python script ?

Use this code with flatten:

################### 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"
1 Like

Output is "CanAddViewToSheet is false"

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.

You could try to put the Transaction start before your forloop.

I would make one more if statement, just to check if the lenght of Sheet, View and Location are equal.

"
if len(sht) == len(views) == len(locs):
"
And check the space between “doc” and “DocumentManager…” in line 7. Dno if it course any problems.

see below image

29

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.

Okay
i will try doing that & will get back to you if i find any error.

According to one of the views above he is using more than one view in a list of lists so that shouldn’t be the error.

It is a new error since it wasn’t there from any of the previous responses so something had changed.

i was change Line 17. and output is Name 'Viewport is not defined’

can you give me any suggestion for this?

You still need to flatten your sheetlist.

Replace the “ElemendId” where your red circle is with a star * (then you import all from the database)

And in line 45, put the Viewport.CanAddViewToSheet(doc,s.Id,v.Id) in parenthesis like this: (Viewport.CanAddViewToSheet(doc,s.Id,v.Id))

i use Flatten Node for sheet.

and i follow your suggestion but Output is “CanAddViewToSheet is false”.

As I can see on the picture above, you are not using Flatten Node :slight_smile: ?

Interesting.

Can you show me the full graph?
There might be something wrong with your views since it calls “false”

See image below

Can you remove the 3D view and try run the graph again? :slight_smile:
Can’t see any error at the moment.

yes, i see same error.