Drawing Index Sorting

Hello everyone.
I am new to dynamo and the forum and trying to create my first graph and ran into a snag.
What I am trying to do is sort/organize our drawing index based on an “ordering” parameter. However, this ordering depends on the drawing sheet prefix.

Currently we manually order our sheets based on their sequence in the drawing set.
For example…0 = General Sheets; 1 = Hazardous Materials; 2 = Site/Civil/Landscape; 3 = Structural; 4 = Architectural…and so on.

Inevitably, someone doesn’t fill this out and the drawing index is out of sorts when we plot.

What I want to do is create a graph that will do this for me, but use our standard pre-set drawing sheet prefixes. So if the drawing sheet prefix is “A”, then it will put a #4 in the parameter in the schedule.

I hope that made sense.
Thanks in advance for the help.

Without the sorting, we have an index like this

What is the name of the parameter you use to order your sheets?

The parameter is “Sheet Order” and its a project parameter

This is where I started and not sure where to go from here.
As a new user, I cannot upload my graph, so here is an image.


Here is my solution. You can just change ‘P’ and ‘M’ in the python node and output notes to the appropriate sheet prefix as well as change the sheet order numbers respectively.
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

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

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

doc1 = DocumentManager.Instance.CurrentDBDocument
list = []
output = []
sheets = FilteredElementCollector(doc1).OfCategory(BuiltInCategory.OST_Sheets).ToElements()
test = []
#if i.LookupParameter('Appears In Sheet List').AsString() == 'true':
for i in sheets:
if i.SheetNumber.startswith('M'):
list.append(i)

output.append(list)
list = []
#########copy below section for any other sheet prefixes###
for i in sheets:
if i.SheetNumber.startswith('P'):
list.append(i)
output.append(list)
list = []
############################################################

OUT = output

Thank you so much for your help!
I will give this a try.

I’m not sure where I went wrong, but I’m getting some error messages I don’t quite understand.

This is what my script looks like with all the pre-fixes set.
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

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

doc1 = DocumentManager.Instance.CurrentDBDocument
list = []
output = []
sheets = FilteredElementCollector(doc1).OfCategory(BuiltInCategory.OST_Sheets).ToElements()
test = []

########################
#if i.LookupParameter(‘Appears In Sheet List’).AsSTring() == ‘true’:
for i in sheets:
if i.SheetNumber.startswith(‘G’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘H’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘C’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘L’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘SD’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘S’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘AD’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘A’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘FP’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘FA’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘PD’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘P’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘MD’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘M’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘ED’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘E’):
list.append(i)

output.append(list)
list = []
########################
for i in sheets:
if i.SheetNumber.startswith(‘T’):
list.append(i)

output.append(list)
list = []
########################
Out = output

This is my graph. I am not sure if I did the output code block correctly or fully understood it.

What does your python code look like? I realized that the indents didnt show up when i copied mine to here so make sure you indent after the if statements like in the image I posted. you can also mouse over the yellow text bubble above the node to show the error message.

Here is a screenshot

The error over the ParameterByName is “Warning: Parameter.ParameterByName operation failed”

The error over Code Block is “Error: EOF expected”

I think you forgot to copy this into the beginning because I left it out of my code by accident.
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
Regardless all of these if statements are a mess and since i don’t know how to do switch statements in python i’ll redo this to make it less of a headache.

sheet order2.dyn (10.8 KB)

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

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

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

doc1 = DocumentManager.Instance.CurrentDBDocument
list = []
output = []
sheets = FilteredElementCollector(doc1).OfCategory(BuiltInCategory.OST_Sheets).ToElements()
test = []
#if i.LookupParameter('Appears In Sheet List').AsString() == 'true':
for i in IN[0]:
	for ii in sheets:
		if ii.SheetNumber.startswith(i):
			list.append(ii)
	output.append(list)
	list = []
for i in IN[1]:
	for ii in sheets:
		if ii.SheetNumber.startswith(i) and ii not in output:
			list.append(ii)
	output.append(list)
	list = []
OUT = output

This is an updated version that iterates through two lsits of prefixes instead of having to type the same code over and over. The lists are seperate because startswith M could contain both M and MD prefixes so that is one way to differentiate and get rid of duplicates. Hope this file works for you lol.

Thank you so much! This method worked.

I had to tweak a couple things.
First, I was still getting errors and realized we might be using different versions. I was using 1.3.
Once I changed to 2.0, the errors went away.

Second, the number sequence didn’t work at first until I realized the schedule parameter was a number type instead of a text type. So I removed the quotes from the number sequence in dynamo so it wasn’t being read as a text string.

Thanks again!

I’m glad it worked then. I should have mentioned I was using 2.0 and that the sheet order for my projects use strings but glad you could figure it out!. I suggest marking that post as a solution so that others who come here with the same issue you had can find it easier.

After some use and office feedback, it was decided to add a discipline field to the script as well. I managed to get everything to work except when it comes to demolition. for example, we label our sheets “A” for architecture and “AD” for architecture demolition and follow suit for other disciplines. As you can see from the image, I am not getting the demolition to break out as its own heading. I’m sure its something simple I overlooked. Here is the script SortDwgIndex.dyn (20.1 KB)

Revit schedules should have a built in filter function that you can use for that if I am not mistaken.