in my project having around 80 schedules need to sort the schedule field data is that possible using Dynamo
hello @dhilipseshan
a solution with python
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
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
import System
from System.Collections.Generic import List
def getFieldIndex(scheduleDef, paraName):
orderedfield_Ids = scheduleDef.GetFieldOrder()
pyListfield_Ids = list(orderedfield_Ids)
for idx, field_Id in enumerate(orderedfield_Ids):
field = scheduleDef.GetField(field_Id)
if field.GetName() == paraName:
return idx, pyListfield_Ids
return None, None
toDoList = lambda x : x if hasattr(x, '__iter__') else [x]
lstView = toDoList(UnwrapElement(IN[0]))
paraName = IN[1]
indexToPlace = IN[2]
TransactionManager.Instance.EnsureInTransaction(doc)
for v in lstView:
if v.ViewType == ViewType.Schedule:
scheduleDef = v.Definition
idx, pyListfield_Ids = getFieldIndex(scheduleDef, paraName)
if pyListfield_Ids is not None:
pyListfield_Ids.insert(indexToPlace, pyListfield_Ids.pop(idx))
newOrderedfield_Ids = List[ScheduleFieldId](pyListfield_Ids)
scheduleDef.SetFieldOrder(newOrderedfield_Ids)
TransactionManager.Instance.TransactionTaskDone()
OUT = newOrderedfield_Ids
3 Likes
Thank you so much.
you have saved a lot of time since the project contains more than 80 schedules.
this script will be very useful for big project schedules. thank you so much.
its an amazing work
1 Like