Place schedules with python script

I have been working on this dynamo script that will duplicate a schedule (the number of times the schedule is duplicated is dependent on the number of sheets that contain views), rename the schedule, and change the filter of the schedule. I am now working on placing the corresponding schedules on to sheets. I have referenced several topics in this forum to get this far. Everything is working except when I try to place the schedules to matching sheets. I get the following error. I am new to Dynamo and Python and I am not sure if I have the code indented correctly. Below is what I currently have.

here is the code I am using that I got from this thread Insert Legend in sheet
however I am new to Python and Dynamo and am not sure if I have it indented correctly, or if the problem is something else in my graph



I have attached Any help is appreciated.

TEST SCHEDULES PLACER & FILTER.01.dyn (34.8 KB)

Python doesn’t lace lists like DesignScript. You can only call properties on single objects - your code is calling it on the view object which is a list and that’s what’s throwing the exception. You therefore need to iterate the list to be able to call the ViewType property on each of its members.

1 Like

Thank you for the replay, and I think I understand what your are saying but not sure how to execute it. Do I need to change Python Script?

Yes, you’ll need to nest all the indented code from line 27 in another for loop to iterate the view list.

2 Likes

Once again thanks for the quick replay, however I am still struggling to understand what you mean by nest line 27. I tried googling the concept but am overwhelmed with trying to interpret the information.

Im not near a computer so I can’t send a code snippet nor open your file. Basically, add another for statement on line 27. Everything below that’s indented (i.e. Everything but line 46) should be indented once more so it’s part of this new loop (a loop within a loop is commonly referred to as a ‘nested loop’/statement. And loop = for statement). You can now iterate the view list.

That said I don’t know what you’re doing so this may not be the solution at all. If you have a view per sheet for example then simply change the first for loop to:

for vs, view in zip(sheets, view):

Edit: don’t name the object and your list the same like I’ve done in my example above. Rename your view variable to viewList or something

1 Like

I am not sure if I am on the right track I have added “for vs, view in zip(sheets, view):” to line 27 as suggested. It did get rid of warning from python node but returns empty list.


Thank you for your help, and I know it must be difficult to help me due to my lack of experience, but much appreciated.

@dmillerSNYXQ

If you are using schedules only you could try this:

views = [UnwrapElement(i) for i in IN[0]]
sheets = [UnwrapElement(i) for i in IN[1]]
loc = XYZ(IN[2].X, IN[2].Y, IN[2].Z)

TransactionManager.Instance.EnsureInTransaction(doc)

for view,sheet in zip(views,sheets):
	ScheduleSheetInstance.Create(doc, sheet.Id, view.Id, loc)	

TransactionManager.Instance.TransactionTaskDone()

OUT=0
1 Like

Thank you for the reply. I would simply use this to replace all items at line 8 and below of my orginal code correct.

Get rid of everything below line 15 of your previous post.

I am now getting this message

I am placing a view schedule, and have attempted at trying various schedules to see if this will work.

This is the code at this point:

import clr

clr.AddReference("RevitServices")
import RevitServices 
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

views = [UnwrapElement(i) for i in IN[0]]
sheets = [UnwrapElement(i) for i in IN[1]]
loc = XYZ(IN[2].X, IN[2].Y, IN[2].Z)

TransactionManager.Instance.EnsureInTransaction(doc)

for view,sheet in zip(views,sheets):
	ScheduleSheetInstance.Create(doc, sheet.Id, view.Id, loc)	

TransactionManager.Instance.TransactionTaskDone()

OUT=0

Any suggestions?

Ok I finally got it to work with this code:

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
sheets = IN[0]
views = IN[1]
x = IN[2]
y = IN[3]
viewsplaced = list()

TransactionManager.Instance.EnsureInTransaction(doc) # you need an active transaction as you will create elements

for number in range(len(sheets)):
	sheet = UnwrapElement(sheets[number])
	view = UnwrapElement(views[number])
	ScheduleSheetInstance.Create(doc, sheet.Id, view.Id, XYZ(x,y,0))
	viewsplaced.append(view.ToDSType(False))
	
TransactionManager.Instance.TransactionTaskDone()
OUT = viewsplaced

Can anyone help me understand why this works, but why my other attempts do not. I am glad it works but I feel that i just got lucky. I want to understand why it works or doesn’t not work.

2 Likes

I think you are doing the same thing. You are unwrapping the views/sheets inside the same for loop before to use the ScheduleSheetInstance method.

Regarding

viewsplaced.append(view.ToDSType(False))

read below.

where are those 2 ids coming from:

Can you cross check you have the same ids coming from the Get All Views node

1 Like

Does anyone have a workflow for locating a schedule on a sheet, I have one for views, but not for schedules…