Get fields of a schedule

Hello,

i wanna get all parameters of a schedule (fields) in python:

#Template 
#DraxlA
#19.07.2023
import clr
import sys 

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#functions
def tolist(x):
    if hasattr(x,'__iter__'): return x
    else: return [x]

#collector
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Schedules)
all_elements = collector.WhereElementIsNotElementType().ToElements()

#filter 
schedule = [i for i in all_elements if i.Name == "TĂźrliste WGA_AP"]

#Preparing input from dynamo to revit
#element = UnwrapElement(tolist(IN[0]))
params = []

for i in schedule:
	params.append(i.field.GetName())

OUT = params

2023-07-31_11h16_55

my code has no error but remains empty! there should be 63 Parameters.

KR

Andreas

You have a ViewSchedule object in the error.

You want to get the list of fields; note that there isn’t a ‘Field’ property for view schedules, so you have to go on a bit of a hunt for that data.

There is a “Definition” property, the output of which is a [ScheduleDefinition] (ScheduleDefinition Class) object.

The ScheduleDefinition object has a method to GetFieldOrder(). The outputs of which are a list of ScheduleFieldId objects, which you can likely use to get the assocaited ScheduleField object.

The ScheduleField class has a ColumnHeading which I think will return the heading as it would print which may be enough. You can also get the ParameterId if it has one (count, formula, and percentage fields wouldn’t return an id so you’d get Null), which can be used to get the parameter and eventually the name as well.

Not a quick exercise, but it should provide some degree of clarity on how Schedules and Parameters (if you go that deep) are configured in the Revit file.

4 Likes

In line with using ScheduleDefinition as @jacob.small directs. You can use the definition to get the field count and a schedulefield list. Range out the count and use schedulefield getname to list out all the names of the schedulefield list. May not be the most proper way of doing it, but the code below works.

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

sched = UnwrapElement(IN[0])
fldnames=[]
fld=[]

schdef = sched.Definition
fldcnt = ScheduleDefinition.GetFieldCount(schdef)

int = range(fldcnt)

for i in int:
	fld.append(ScheduleDefinition.GetField(schdef,i))

for e in fld:
	fldnames.append(ScheduleField.GetName(e))

OUT = fldnames
1 Like