How to get Schedule Fields?

hi All new to Python and no experience at all but im trying to Get Scheduled Fields through python but im not really sure what im doing …Thanks for your help.!

Capture2|136x194

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])

OUT = ScheduleField

Are you just trying to get the list of parameters that are scheduled fields in a particular schedule? If so, you can use the OTB node ScheduleView.Fields and input your schedule view into that

1 Like

Hi thanks for quick response I’ll have to check, is that available using 1.2 version?

I’m looking at the parameters (fields) that is in particular schedule.

I’m actually trying to look at API but my lack of knowledge translating it into python is driving me crazy :joy:

Sorry, that first link I sent was for the wrong thing. This should be a good starting place: http://www.revitapidocs.com/2018/fe88f8dc-4926-4ff4-4490-7aee58d5a3f4.htm

The nice thing about Python is it doesn’t require a lot of “translating” just simplification. I’m still fairly new to Python and coding in general but it’s not difficult to learn. All the methods and properties you need to get the parameters in your schedule are pretty straight forward. I suggest attempting this one member at a time. Get the schedule definition. Get the parameter Ids in the schedule. Convert the Ids to parameters. Then get the parameter names. Start writing out some code and see where it gets you. If you get stuck, post back here with your code and we can work it out.

hi Nick i think im stuck now. :confused: dont know what to do next

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

sschedule = UnwrapElement(IN[0])

def getField(schedule, name):
definition = schedule.Definition
count = definition.GetFieldCount()
for i in range(0, count, 1):
if definition.GetField(i).GetName() == name:
field = definition.GetField(i)
return field

#“Start” the transaction
TransactionManager.Instance.EnsureInTransaction(doc)

	scheduleField = getField(sschedule, i)

“End” the transaction

TransactionManager.Instance.TransactionTaskDone()

OUT = scheduleField

Could you try reposting your code using the preformatted text option? Just select all your code and click the </> button in the toolbar above.

    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

    sschedule = UnwrapElement(IN[0])

    def getField(schedule, name):
    	definition = schedule.Definition
    	count = definition.GetFieldCount()
    	for i in range(0, count, 1):
    		if definition.GetField(i).GetName() == name:
    			field = definition.GetField(i)
    	return field
    	
    #"Start" the transaction
    TransactionManager.Instance.EnsureInTransaction(doc)

    		scheduleField = getField(sschedule, i)

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

    OUT = scheduleField`

You have your input defined as sschedule but you call schedule in the definition line. You also have an if statement with no else line. I don’t think you need a transaction either since you’re just pulling data but it’s not going to hurt anything either.

Try something like this. It’ll return the parameters (names) for that schedule, which you can query for a specific parameter if you want.

keyschedule = UnwrapElement(IN[0])
definition = keyschedule.Definition
ids = definition.GetFieldOrder()
names = []

for id in ids:
	param = definition.GetField(id)
	names.append(param.GetName())
1 Like

Thanks Nick I’ll try it later today. Cheers!

thanks nick!

In my opinion that’s a better answer. @awilliams :+1:

OOTB nodes support SchedulableFields and Fields. The former is a list of all Parameters that can be scheduled for the given category/schedule, while former is a list of currently added/being scheduled fields. Please use OOTB nodes as much as possible over Python - especially if you are just learning. There is no reason to add to the complexity by trying to learn Python + Revit API on top of Dynamo. I would only resort to Python when OOTB doesn’t support functionality.

1 Like

Thanks @Konrad_K_Sobon yeah I would its just in this case I cannot just upgrade into dynamo version 1.3 as the corporate standard didn’t release yet the latest one, so I have to find another way to work in my current project :slight_smile:

Please make that clear when you are asking the question. Also, please make sure to format any code appropriately. I will fix that for now, but in the future you should do that yourself.

@Konrad_K_Sobon once you get schedule fields, how can I identify the parameters of that field names? I want to know more about the Fields, for example if those are type or instance parameters, project/family/shared/global/builtin parameters. I am creating new post to ask that question more specific. Thanks