Schedule in Revit to Dynamo Data - Maintain Data Types

I am trying to expand on the python script that was posted in this post:

My Revit schedule looks like the following:

The first column will be text data and the following information will be dimensional data.
The problem that I have is all data that is called via the getcelltext() function is purely that, only text. Is there a function that can pull numerical data from a cell in the Revit API? From what I could tell there was not. I tried the obvious getcellvalue() type functions, but to no avail.

My changed code looks like the following:

table = schedule.GetTableData().GetSectionData(SectionType.Body)
nRows = table.NumberOfRows
nColumns = table.NumberOfColumns

#Collect all of data from the schedule
dataListRow = []
for row in range(nRows): #Iterate through the rows. The second row is always a blank space
	dataListColumn = []
	for column in range(nColumns): #Iterate through the columns
		if column == 0:
			dataListColumn.Add( TableView.GetCellText(schedule, SectionType.Body, row, column) )
		else:
			dataListColumn.Add( TableView.GetCell(schedule, SectionType.Body, row, column) )
	dataListRow.Add( dataListColumn );

# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()

OUT = dataListRow

All data with the default python script is string data:

Any easy workarounds to get numerical data from a cell?

Hello,
to my knowledge it is not possible to obtain the numerical data of the parameters with classes TableView and TableSectionData
If your fields of Schedule are Parameters you can try this method

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

doc = DocumentManager.Instance.CurrentDBDocument

def convert_Value(paraL):
	if paraL.StorageType == StorageType.Double : 
		value = paraL.AsDouble()
		unitType = paraL.Definition.UnitType
		formatOption = doc.GetUnits().GetFormatOptions(unitType)
		displayUnit = formatOption.DisplayUnits
		convert =  UnitUtils.ConvertFromInternalUnits(value,displayUnit)
		return convert
	elif paraL.StorageType == StorageType.String : 	
		value = paraL.AsString()
		if value is None:
			value = paraL.AsValueString()
		return value
	elif paraL.StorageType == StorageType.Integer: 	
		value = paraL.AsInteger()
		return value	
	elif paraL.StorageType == StorageType.ElementId: 	
		valueId = paraL.AsElementId()
		return doc.GetElement(valueId)

scheduleView = UnwrapElement(IN[0])

if scheduleView.ViewType == ViewType.Schedule:	
	collinview = FilteredElementCollector(doc, scheduleView.Id).OfClass(FamilyInstance).WhereElementIsNotElementType().ToElements()
	definition = scheduleView.Definition
	ids = definition.GetFieldOrder()
	paraSchNames = []
	out = []
	for id in ids:
		field = definition.GetField(id)
		if field.FieldType  == ScheduleFieldType.Instance or field.FieldType  == ScheduleFieldType.ElementType:
			paraSchNames.append(field.GetName())
	for elem in collinview:
		temp = []
		elemType = doc.GetElement(elem.GetTypeId())
		for paraSchName in paraSchNames:
			value = None
			paraelem = elem.LookupParameter(paraSchName)
			if paraelem is not None:	
				value = convert_Value(paraelem)
				temp.append(value)
			#if value is None check if it's a Parameter Type	
			if 	value is None:
				paraelemT = elemType.LookupParameter(paraSchName)
				if paraelemT is not None:	
					value = convert_Value(paraelemT)
					temp.append(value)				
		out.append(temp)

	OUT = out
else:
	OUT = "Wrong View"

Note:
the order of the output list of the Python node is not necessarily the same as the Schedule (if you apply sorting in properties of Schedule)

Thanks @c.poupin, but unfortunately, the data in my schedule is not a parameter. I am trying to use the data in my schedule to write information to parameters… kinda of silly I know.

I broke down and wrote some code to convert feet and inches to decimal feet based on string data.

1 Like

I tried to execute your code and I couldn’t the error message was “‘ScheduleView’ object has no attribute ‘GetTableData()’”, is this node named “Schedule Views” just the “Revit>Selection>Views” node renamed or is it from some package? It would be very useful to me, specially if there is another function to set the data because I’m trying to modify revit sheets using Dynamo. Thank you in advance.

Hello @luiz.costa9PEYP and welcome !

Please start a new topic, with a screenshot of your dyn script and the python code