Rename schedule header 2023

Hi All, I found a node ‘Schedule Formatting’ but can’t seem to work. Any advise on the matter?

Welcome to the community! Looks like there is an issue in the code not being able to iterate through a bool for the hidden input and an integer for the column width input. You may can try searching for an update to the archilab package. Or if you are only wanting to rename the column header, then you can use the code below. Input the schedule, the header name to be replaced and the name to change it to.

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument

sched = UnwrapElement(IN[0])
names = IN[1]
newNames = IN[2]

fields = sched.Definition


TransactionManager.Instance.EnsureInTransaction(doc)

for number in range(fields.GetFieldCount()):
	colHead = fields.GetField(number).ColumnHeading
	for n, newName in zip(names, newNames):
		if colHead == n:
			sched.Definition.GetField(number).ColumnHeading = newName
			
TransactionManager.Instance.TransactionTaskDone()

OUT = sched
1 Like

Many thank for the code! But I can’t make it work, please advise!

Hi,

here is a solution with a dictionary and Python

code Python (compatible with all engines)

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def toList(x):
    if isinstance(x, list):
        return x
    elif hasattr(x, "GetType") and x.GetType().GetInterface("IEnumerable") is not None:
        return x
    else :
        return [x]
        
        
viewsSchedules = toList(UnwrapElement(IN[0]))
repDsDict = IN[1]
try:
	#convert DynamoDictionary to PythonDictionnary
	repPyDict = dict(zip(repDsDict.Keys, repDsDict.Values))
except:
	repPyDict = repDsDict
TransactionManager.Instance.EnsureInTransaction(doc)
for view in viewsSchedules:
	if view.ViewType == ViewType.Schedule:
		schedulDef = view.Definition
		lstfieldId = schedulDef.GetFieldOrder()
		for fieldId in lstfieldId:
			scheduleField = schedulDef.GetField(fieldId)
			valuefromdict = repPyDict.get(scheduleField.ColumnHeading)
			if valuefromdict is not None:
				scheduleField.ColumnHeading = valuefromdict
TransactionManager.Instance.TransactionTaskDone()				

OUT = viewsSchedules
3 Likes

Thank very much!

Glad you have a solution.

I should have added a pic to help clarify. The code I provided has to be copied into a python script and not a code block.

1 Like