Get ProjectParameters with Python

Hello all,

Since I don’t have much experience with Python, I would like to ask your help for the following.

In Dynamo 2.6 I had a Python script that could retrieve the ProjectParamters in my project.

in Dynamo 2.16 (Revit 2023) I get an error with this same script. See image.

Who can help me solve this?

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

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
params =
cats =
iterator = doc.ParameterBindings.ForwardIterator()
while iterator.MoveNext():
params.append(iterator.Key.Name)
thesecats =
for cat in iterator.Current.Categories:
thesecats.append(Revit.Elements.Category.ById(cat.Id.IntegerValue))
cats.append(thesecats)
OUT = (params,cats)

Try install package IronPython instead
(now you run Cpython)

image

1 Like

Hi manhgt214,

Thank you for your response.

I have tried both IronPython2 and CPython3 and both to no avail.

Hey @Fernand77
Also for future reference, use the Preformatted text option when providing your code.
image

3 Likes

what error?
I tested your code, work on CPython
Check indentation level in loop.

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

params = []
cats = []

iterator = doc.ParameterBindings.ForwardIterator()

while iterator.MoveNext():
	params.append(iterator.Key.Name)
	thesecats = []
	for cat in iterator.Current.Categories:
		thesecats.append(Revit.Elements.Category.ById(cat.Id.IntegerValue))
	cats.append(thesecats)
OUT = (params,cats)

Hi manhgt214,

I still get the message in my project.

In a new empty project, it works fine…

You can use: try except to ignore exception

import clr
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

params = []
cats = []

iterator = doc.ParameterBindings.ForwardIterator()

while iterator.MoveNext():
	params.append(iterator.Key.Name)
	thesecats = []
	for cat in iterator.Current.Categories:
		try:
			thesecats.append(Revit.Elements.Category.ById(cat.Id.IntegerValue))
			cats.append(thesecats)
		except:
			pass
OUT = (params,cats)