How to get the parameter Discipline with Dynamo/python?

How to get the parameter Discipline with Dynamo/python?

I think is called in API something like Utility Label of the parameter but I only get the Group name under the parameter reside, but not idea of how to get the Discipline.

Just for curiosity: Is that property of the parameter only applicable to Project Parameters/Shared Parameters or is it implemented as well with the builtin parameters of Revit?

@ruben.romero Not sure what you need but see if this takes you somewhere:

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

element = UnwrapElement(IN[0])
parameterString = IN[1]

parameter = element.LookupParameter(parameterString)
unitType = parameter.Definition.UnitType
discipline = UnitUtils.GetUnitGroup(unitType)

OUT = discipline

image

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

OUT = System.Enum.GetValues(UnitGroup)
Revit API Docs

GetUnitGroup Method
UnitGroup Enumeration

3 Likes

is possible to get the parameters discipline with the input as the parameter list instead of feeding with the element and the parameter names? Thanks

I am trying to get something like OOTB nodes are doing like those examples:
image

If you have parameter as input then you can use like that

1 Like

unfortunatelly it does not work

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 8, in
AttributeError: ‘List[object]’ object has no attribute ‘Definition’

You have to loop over parameters.

unitType = [p.Definition.UnitType for p in parameter]
discipline = [UnitUtils.GetUnitGroup(i) for i in unitType]

still same result as before, identical Warning

Do you have nested lists in Element.Parameters?

no, just tried with a simple Wall Element to get list of instance parameters like this:

Ok I see the problem. We need RevitAPI Object but we feed with RevitElements.Parameter.

something weird like that? how to call that API object in the python code?

We can do like that: Parameter.Name as Input and then Using LookupParameter with looping.

@ruben.romero You can do something like this if you are working with all parameters of element(s).

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

toList = lambda x : UnwrapElement(x) if hasattr(x, '__iter__') else UnwrapElement([x])

OUT = [[UnitUtils.GetUnitGroup(para.Definition.UnitType) for para in elems.Parameters] for elems in toList(IN[0])]
2 Likes

that is awesome, although is possible to ask from the parameter ID or parameter element, instead from the element?

I never tried going that way but I think it should be possible.