Get Project Parameters Name through Python Issue

Hello,

I’ve been tring to get the name of the project parameters through python and the API but it keeps getting me the error message: The managed object is not valid.

Here is the code:

import clr
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

res = []
iterador = doc.ParameterBindings.ForwardIterator()
while iterador.MoveNext():
	res.append(iterador.Key)
	
OUT = [a.Name for a in res]

Thanks for all your support

your code seems to work fine on my end, so i suspect is that you didnt load the correct assembly/method.

try replacing your importing part to this

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

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

EDIT: Is you didnt load in the revit api assembly :smiley:

1 Like

and also your code can be shorten by just placing a “Name” property after the Key method like this:

res = []
iterador = doc.ParameterBindings.ForwardIterator()
while iterador.MoveNext():
	res.append(iterador.Key.Name)
	
OUT = res
1 Like

I have run into this issue before specifically with ParameterBindings. I think the only way to solve this (temporarily) was to restart Dynamo and/or Revit. The code you have written is syntactically correct, but I think the error is out of your control.

1 Like

@ramoon.bandeira, how about this one?

1 Like

Thanks for your tip

I really missed the imports. The final code was:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

res = []
iterador = doc.ParameterBindings.ForwardIterator()
while iterador.MoveNext():
	res.append(iterador.Key.Name)
	
OUT = res
1 Like