Hello Dynamo Community,
Schedule Sorting Grouping worked fine in Revit 2021.
In Revit 2022 nothing happens, also no error message.
#Copyright(c) 2015, 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]
_showBlankLine = IN[2]
_footerCount = IN[3]
_footerTitle = IN[4]
_header = IN[5]
_sortOrder = IN[6]
#"Start" the transaction
TransactionManager.Instance.EnsureInTransaction(doc)
def getFieldId(schedule, name):
definition = schedule.Definition
count = definition.GetFieldCount()
for i in range(0, count, 1):
if definition.GetField(i).GetName() == name:
fieldId = definition.GetField(i).FieldId
return fieldId
def addSortingField(schedule, ssgf):
message = None
definition = schedule.Definition
try:
definition.AddSortGroupField(ssgf)
except:
message = "You can add Max of 4 sorting/grouping parameters."
pass
return message
def createSortingField(fieldId, blank, fCount, fTitle, header, sOrder):
message = None
ssgf = ScheduleSortGroupField()
ssgf.FieldId = fieldId
if blank != None:
ssgf.ShowBlankLine = blank
checkList = [fCount, fTitle]
if any(item == True for item in checkList):
ssgf.ShowFooter = True
if fCount != None:
ssgf.ShowFooterCount = fCount
if fTitle != None:
ssgf.ShowFooterTitle = fTitle
else:
ssgf.ShowFooter = False
if header != None:
ssgf.ShowHeader = header
if sOrder != None:
if sOrder == "Ascending":
sortO = ScheduleSortOrder.Ascending
ssgf.SortOrder = sortO
elif sOrder == "Descending":
sortO = ScheduleSortOrder.Descending
ssgf.SortOrder = sortO
else:
message = "Schedule Sort Order can only be \nset to Ascending or Descending.\nCheck your spelling please."
if message == None:
return ssgf
else:
return message
if type(_paramName) == list:
definition = _keySchedule.Definition
if definition.GetSortGroupFieldCount() != 0:
definition.ClearSortGroupFields()
for i,j,k,l,m,n in zip(_paramName, _showBlankLine, _footerCount, _footerTitle, _header, _sortOrder):
fieldId = getFieldId(_keySchedule, i)
ssgf = createSortingField(fieldId, j, k, l, m, n)
if type(ssgf) == str:
message = "Schedule Sort Order can only be \nset to Ascending or Descending.\nCheck your spelling please."
else:
message = addSortingField(_keySchedule, ssgf)
else:
definition = _keySchedule.Definition
if definition.GetSortGroupFieldCount() != 0:
definition.ClearSortGroupFields()
fieldId = getFieldId(_keySchedule, _paramName)
ssgf = createSortingField(fieldId, _showBlankLine, _footerCount, _footerTitle, _header, _sortOrder)
if type(ssgf) == str:
message = "Schedule Sort Order can only be \nset to Ascending or Descending.\nCheck your spelling please."
else:
message = addSortingField(_keySchedule, ssgf)
# "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'))
Any thoughts?
Kind Regards