Adjust schedule formatting

Hi,

Currently, I am trying to automate the process of making schedules in Dynamo. Creating the schedule, adding fields and setting filters is going fine. The formatting of the schedule is working to an extend. I would like to change the setting from ‘No calculation’ to ‘Calculate totals’ via Dynamo (see image below from Revit schedule settings).

image

I am able to adjust some of the fields with nodes from Archi-Lab. The code Archi-lab used is copied below. I am able to make small adjustments to the script, mainly removing some options. Unfortunately I can’t figure out how to adjust the script to set it to ‘Calculate totals’. Is it possible to adjust this field and where can I find the correct statement to change this field?

<#Copyright© 2014, Konrad Sobon

@arch_laboratory, http://archi-lab.net

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

Import DocumentManager and TransactionManager

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

Import RevitAPI

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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

from System.Collections.Generic import *

Import ToDSType(bool) extension method

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

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

_keySchedule = UnwrapElement(IN[0])
_paramName = IN[1]
_columnHeading = IN[2]
_hidden = IN[3]
_headingOrientation = IN[4]
_horizontalAlignment = IN[5]
_sheetColumnWidth = IN[6]

def getField(schedule, name):
definition = schedule.Definition
count = definition.GetFieldCount()
for i in range(0, count, 1):
if definition.GetField(i).GetName() == name:
field = definition.GetField(i)
return field

def formatColumn(field, heading, hidden, hOrientation, hAlign, sWidth):
message = None
if heading != None:
field.ColumnHeading = heading
if hidden != None:
field.IsHidden = hidden
if hOrientation != None:
if hOrientation == “Horizontal”:
ho = ScheduleHeadingOrientation.Horizontal
field.HeadingOrientation = ho
elif hOrientation == “Vertical”:
ho = ScheduleHeadingOrientation.Vertical
field.HeadingOrientation = ho
else:
message = “Schedule Heading Orientation can only \nbe set to Horizontal or Vertical. \nPlease check your spelling.”
if hAlign != None:
if hAlign == “Left”:
ha = ScheduleHorizontalAlignment.Left
field.HorizontalAlignment = ha
elif hAlign == “Center”:
ha = ScheduleHorizontalAlignment.Center
field.HorizontalAlignment = ha
elif hAlign == “Right”:
ha = ScheduleHorizontalAlignment.Right
field.HorizontalAlignment = ha
else:
message = “Schedule Horizontal Alignment can only \nbe set to Left, Center or Right. \nPlease check your spelling.”
if sWidth != None:
field.SheetColumnWidth = sWidth
return message

#“Start” the transaction
TransactionManager.Instance.EnsureInTransaction(doc)

message = None
if type(_paramName) == list:
for i, j, k, l, m, n in zip(_paramName, _columnHeading, _hidden, _headingOrientation, _horizontalAlignment, _sheetColumnWidth):
scheduleField = getField(_keySchedule, i)
message = formatColumn(scheduleField, j, k, l, m , n)
else:
scheduleField = getField(_keySchedule, _paramName)
message = formatColumn(scheduleField, _columnHeading, _hidden, _headingOrientation, _horizontalAlignment, _sheetColumnWidth)

“End” the transaction

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
if message == None:
OUT = 0
else:
OUT = ‘\n’.join(’{:^35}’.format(s) for s in message.split(’\n’))>

Nobody knows ? I want to solve the same problem and it doesn’t seem easy…
Thanks !

Came across this thread while I was searching for a way to do this, fairly simple solution.

field = schedule.Definition.GetField(column # that you’re accessing)
field.DisplayType = ScheduleFieldDisplayType.Totals

See the Revit API for the syntax for the other calculations

1 Like

image

 import clr
 clr.AddReference('RevitAPI')
 import Autodesk
 from Autodesk.Revit.DB import *
 
 clr.AddReference("RevitNodes")
 import Revit
 clr.ImportExtensions(Revit.Elements)
 from Revit.Elements import *
 clr.ImportExtensions(Revit.GeometryConversion)
 clr.ImportExtensions(Revit.GeometryReferences)
 
 clr.AddReference("RevitServices")
 import RevitServices
 from RevitServices.Persistence import DocumentManager
 from RevitServices.Transactions import TransactionManager
 
 doc = DocumentManager.Instance.CurrentDBDocument
 uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
 uiapp=DocumentManager.Instance.CurrentUIApplication
 app = uiapp.Application
 
 view = doc.ActiveView
 
 def U(elem): 
 	a = UnwrapElement(elem)
 	return a
 
 schedule = UnwrapElement(IN[0])
 colName = IN[1]
 
 
 definit = schedule.Definition
 countParameters = definit.GetFieldCount() 
 # Parameter names
 names = []
 for i in range(countParameters):
 	Parname = definit.GetField(i).ColumnHeading # Parameter Column name
 	if Parname == colName:
 		index = i
 
 field = schedule.Definition.GetField(index) # schedule field
 TransactionManager.Instance.EnsureInTransaction(doc)
 
 field.DisplayType = ScheduleFieldDisplayType.Totals
 
 TransactionManager.Instance.TransactionTaskDone()
 OUT = field

Hey can you please help me in the above script.
What are the inputs ?

IN[0] as ScheduleView
IN[1] as String

1 Like