Assign value based on sheet number

I am trying to make a Dynamo graph that will check look at the sheet numbers within a Revit file, and based on the prefix write a predefined number to a Custom Parameter to assist with sorting of drawings on an index.

I’ve been able to get it to properly work when looking for a specific string:

However in total I have over 100 possible prefixes (excessive, I know), so I would like if possible to have dynamo check an Excel file for the prefix and then populate the custom parameter. I feel like I’m close but I’m not sure how to tie it all together

The image below is a snippet of my excel file

Anyone have some suggestions?

You can use a dictionnary to match the data.
Create one using your Excel file then use your sheet to lookup the right entry.
There’s plenty of post about Dic on the forum

1 Like

I’m not sure what you’re trying to match with what. Could you give an example or 3?

an solution using pandas (Python)

code PythonNet3

import sys
import clr
import System

clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)

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

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

import pandas as pd
pd.set_option('display.max_columns', None)

xlsx_path = IN[0]

df = pd.read_excel(xlsx_path, skiprows=1,  dtype=str)
df = df.fillna(method='ffill')
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for idx, row in df.iterrows():
    prefix = row['Designator']
    # search sheets with this prefix
    sheets = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WhereElementIsNotElementType()\
            .Where(System.Func[DB.Element, System.Boolean](lambda s : s.SheetNumber.startswith(prefix) ))\
            .ToList()
            
    for sheet in sheets:
        para_to_set = sheet.LookupParameter("Sheet Sorting")
        if para_to_set is not None:
            para_to_set.Set(row['Sheet Sorting'])
            
TransactionManager.Instance.TransactionTaskDone()

OUT = df.to_string()
1 Like

This is a sample index that shows the number that needs to be applied to the sheets based on the drawing number.

The reason for it is because of how our drawings are sorted on an index is not alphabetical/numerical. For example, SD (structural demo) need to show up prior to Structural drawings. Similarly, they need to show up before E (Electrical) drawings.

I gave this a try but I’m running into the issue of no no module named Pandas. Depending on if something needs to be downloaded/installed I may not have permissions within my organization

Since the release of Revit 2024, the Pandas Python library has been included in Dynamo. Which version are you using?

1 Like

Revit version is 2023.1.8, dynamo version 2.16.4

for Revit 2023 you can use pip to install pandas (or any orther package)

Examples here

Yeah, I came across the Customizing Dynamo’s Python 3 installation page, but due to workplace restrictions I’m not able to download/install PIP, even the standalone zip.

That said, I do have Revit 2025 installed, and when running the same graph/python code again it does generate the /lib folder but comes up with a different error:

Which I feel like is just a excel formatting problem.

Either way, I’d like to limit the amount of external things that need to be done/downloaded since this will need to be distributed to quite a few people.

A dictionary is still the simplest option in my opinion. Your naming convention seems easy enough to just pull the substring before the “-” in the Sheet ID and then identify the Sheet Sorting number based on the dictionary you create. The dictionary would just be the prefix and the sorting value.

1 Like

Well if the list matching already exists, I would just use a string and have it built-in in Dynamo.I agree then with the Dictionary route.