Get "Element" From Key Schedule

I am looking to set a Key Schedule Parameter for Rooms based on their Name.

  1. Collect All Rooms
  2. Check their name against a list
  3. If in the list, apply a specific “Occupancy Group” to them via a Key Schedule Parameter

The problem I have is that I am unable to get a “List” of available Parameters for that Schedule as Elements. I am open to Python and/or nodes just looking for some help here on the Parameter as Element part.
I am getting the Information, just not as Elements to Sort / Filter and Set.
image

Here is what the Key Schedule looks Like
image

Solution to this was found here from @Konrad_K_Sobon from over 4 years ago… I have a long ways to go!

https://forums.autodesk.com/t5/revit-api-forum/key-schedule-revit-api/td-p/5449134

import clr

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

#Preparing input from dynamo to revit
viewSchedule = UnwrapElement(IN[0])

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

elements = FilteredElementCollector(doc, viewSchedule.Id).ToElements()

params = []
names = []
for i in elements:
    params.append(i.Parameters)
    names.append(i.Name)

TransactionManager.Instance.TransactionTaskDone()

OUT = elements, names

While I was at it, I figured why not ZTN it:

5 Likes

This may be of interest to you.

http://dynamobim.org/forums/topic/read-revit-key-parameter-value-set-new-key-parameter-value/

1 Like

Hello Sean,
which node is it ? i mean Revit elements get key schedule elements.

That was a Zero Touch Node I made for my in house package, but the Python code provided should get you to the same place if someone else hasn’t developed a node at this point.

1 Like

If I want to get the parameter itself of that field of key schedule, how would be the script output?

If I ask as output: params, I get results like that: Autodesk.Revit.DB.Parameter, but can I get the parameter?

basically I want to know more about the parameter that is a field, I do not care about any element

image

Take a look at the Crumple package because I think @GavinCrump put some nodes in there around Key Schedules specifically.

You could also try getting it by the GUID of the pram.

1 Like

This should do it… excuse the sloppy variable management in the code blocks.

# Boilerplate text
import clr

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

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

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Define list/unwrap list functions
def uwlist(input):
	result = input if isinstance(input, list) else [input]
	return UnwrapElement(input)

# Preparing input from dynamo to revit
element = uwlist(IN[0])
sdef = element.Definition

fparams, pids, pnames = [],[],[]

# Do some action in a Transaction
count = sdef.GetFieldCount()

TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(0, count, 1):
	field = sdef.GetField(i)
	pids.append(field.ParameterId)
	ele = doc.GetElement(field.ParameterId)
	fparams.append(ele)
	try:
		pnames.append(ele.Name)
	except:
		pnames.append(None)
	
TransactionManager.Instance.TransactionTaskDone()

# Preparing output to Dynamo
OUT = fparams, pnames, pids

Looks like they can’t be passed as wrapped elements so you’ll need to combine them later in a Python script to check their properties probably.

2 Likes

is possible to get the Schedulable Fields of the schedule instead of the Fields that are already there? if that works for a list of schedules as input would be great as well. Many thanks for your help

This gets you the possible fields by Id, but it looks to be a lot of them (more than the UI sees):

# Preparing input from dynamo to revit
element = uwlist(IN[0])
sdef = element.Definition
fids = []

# Do some action in a Transaction
fields = sdef.GetSchedulableFields()

for f in fields:
	fid = f.ParameterId
	fids.append(fid)

# Preparing output to Dynamo
OUT = fids

1 Like

I tested both python scripts, the first that gets the IDs of the Fields on schedule gets all Nulls in output fparams and pnames, although pids gets right result, which is what I am looking for.

@GavinCrump wether if I get the scheduled fields or schedulable fields of the schedule, the ID -1152353 is not found in the builtin parameters of Revit, why? I am questioning if the clockwork node is missing some builtin parameters.

null : -1152353

What is the goal here?

2 Likes

@jacob.small from a schedule to get elements, but also parameter IDs of the schedule fields, because no idea if the parameters are builtin, custom and where are they coming from, a family parameter or what?

@GavinCrump Interesting, your package node gets parameters as elements, but is possible to retieve more information about them with Dynamo OOTB nodes? what is possible to do with them?
image

I found Orchid package node ID to Parameter, unfortunately does not work in that example
image

I get what you are after, but was more curious to know why is this important? What is the goal of having this?

I want to make sure that the data defined to use in a project will be usable when the time comes, for example I know subcategories of bolts, anchors, plates, etc have lack of common data structure.

Those parameters are either user defined or shared. Builtin parameters don’t appear to be define-able in Dynamo in the same way. They’re passable as Revit.db elements I think, so can be fed into Python nodes or held within them for further analysis.

I’d suggest digging into Clockwork and Genius Loci which have heaps of parameter based nodes that can check instance/type etc., as well as searching in the Revit API (I know you said you’re not experienced with Python, but if you’re trying to do stuff like this then it is time for this as well I’d say). Look into the Revit lookup tool as well to snoop their properties.

Noting we have addressed the initial query in this thread as well, it would be better to do some research now and come back next time you hit a road block.

1 Like