Schedule GetCellText() returns empty strings

Hello everyone,
i’m currnetly trying to work with and understand schedules in Dynamo.
As one of the first steps i wanted to get the values of a schedule into a list in Dynamo.
Therefore i was using the GetCellText() method in the following code.

import clr
import sys
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

schedule = UnwrapElement(IN[0])


sched = schedule.GetTableData()
body = sched.GetSectionData(SectionType.Body)

row_count = body.NumberOfRows
col_count = body.NumberOfColumns

ct = []

for row in range(row_count):
    for col in range(col_count):
        cell_text = body.GetCellText(row, col)
        ct.append(cell_text)

OUT = ct

As a result i’m left with many empty strings. How does this happen and what do i need to change? I’m using the Autodesk Golden Nugget project in RVT 24.
I’ve tried it with different schedules but the outcome is the same.

Thanks for the help in advance!

You may need to utilise the “GetCellType” method then change what you do depending on its type.

EG
If its a string you do what you have done, but if its a calculated value then you use that method.

TableSectionData Class

CellType Enumeration

1 Like

Hey Brendan,
i’ve tried that as well to check.
The results where a mix of the following 3.

The empty strings are mostly from type 2 ( data bound parameter).

In that case i guess i would need to use other ways ie like the GetField() method and get the parameter value?

Hi

try to use this method for parameter values

Hi, according to the API documentation (and me trying it out) that method is only working for panel schedules, not “normal” schedules.

I’m cuurently working on a workaround and will leave an update once i have working code.

Thanks so far for the support.

Ah yes, exactly,

Your values (empty string) seem to be related to empty rows in the schedule, try this

import clr
import sys
import System
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


def read_Schedule(view_schedule):

	tabledata = view_schedule.GetTableData().GetSectionData(SectionType.Body)		
	outvalue = []
	#		
	nbrCol = tabledata.NumberOfColumns
	nbrRow = tabledata.NumberOfRows 
	for r in range(nbrRow):
		temp = []
		#get values by Rows
		for c in range(nbrCol):	
			if tabledata.GetCellType(r,c) == CellType.Text or tabledata.GetCellType(r,c) == CellType.ParameterText:
				temp.append(tabledata.GetCellText(r,c))
			elif tabledata.GetCellType(r,c) == CellType.Parameter:	
				try:
					temp.append(view_schedule.GetCellText(SectionType.Body, r, c))					
				except Exception as ex:
					print(ex)
			#
			elif tabledata.GetCellType(r,c) == CellType.CalculatedValue:
				temp.append(tabledata.GetCellCalculatedValue(r,c))	
		# if row is empty pass
		if len(temp) == 0 or all(System.String.IsNullOrEmpty(x) for x in temp):	
			pass
		else:
			outvalue.append(temp)	
	return outvalue

schedule = UnwrapElement(IN[0])

OUT = read_Schedule(schedule)
1 Like

how does the original schedule in Revit look like? What values are they?

Thank you so much! Works like a charm. I’m still trying to understand the part how it is getting the parameter values.
I see that the method used is still GetCellText() even though the Cell type is parameter.
Or is it that in the case the Cell type is parameter you are calling the view_schedule, not the table data?

There are 2 methods

  • one based on TableView class
  • another based on TableSectionData class

note from API doc

image

1 Like