When I use the “Schedule Sorting Grouping” node to add an extra Sorting on parameter “Comments” it replaces the Sorting that was allready set to the specific schedule.
Is it possible to add the Sorting as an extra then by sorting on Comments
(or if not, is it possible to retrieve a list of all the available Sorting/Grouping of the schedule and then add an extra?
Thanks in advance
Welcome to the community @b.walravens. Yes the code behind that Archilab node checks to see if there is an existing sorting/grouping field and if there is one, it clears it out and adds the new one. I don’t think there is a node that allows you to keep the existing and add a new one. So I modified the Archilab code. Added another input for True/False if you want to remove the existing sorting/grouping fields or not. True removes and False keeps existing.
Create a python script and paste the code below into it. Use the plus button to add the necessary inputs.
#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]
_removeSort = IN[7]
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 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
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)
else:
definition = _keySchedule.Definition
fieldId = getFieldId(_keySchedule, _paramName)
ssgf = createSortingField(fieldId, _showBlankLine, _footerCount, _footerTitle, _header, _sortOrder)
TransactionManager.Instance.EnsureInTransaction(doc)
count = int(definition.GetSortGroupFieldCount())
if _removeSort == False:
definition.InsertSortGroupField(ssgf, count)
else:
definition.ClearSortGroupFields()
definition.AddSortGroupField(ssgf)
TransactionManager.Instance.TransactionTaskDone()
OUT = ssgf
1 Like
Thank you very much!
This would also be a good addition to the archilab node
1 Like