Get parameter value by GUID

Hi everyone.
Can anyone point me what I’m doing grong?

I’m trying to get the value of a shared parameters base on it’s GUID.

The Revit API, says that the method get_Parameter() is the safest ways to do that, but when I’m trying o got an error saying that get_Parameter is not a valid method for Family Instance.

import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')

from RevitServices.Persistence import DocumentManager
from System import Guid
import Autodesk.Revit.DB as DB

doc = DocumentManager.Instance.CurrentDBDocument

elements= UnwrapElement(IN[0])

guids = [Guid(g) for g in IN[1]]

result = []
for el in elements:
    values = []
    for g in guids:
        p = el.get_Parameter(guids)
        values.append(p.AsString())
    result.append(values)

OUT = result

The inputs are
IN[0]

A list of strings that represents the GUID

IN[1]

A list of elements.

Thank you all for your time.

havent tried not at dyn…, but guess a shared parameter can have many values and be assigned to many categories,

yes, but still has the same GUID

yeah :slight_smile: and if i remember the same guid no matter instance or type parameter…probably wrong


guid.dyn (13.3 KB)

Exactly, the problem here is that no matter which categories are applied the parameter, the point here is get the values of the parameter of the selected elements, in this case the elements are Family Instances.

According to the Revit API, should be possible to get the values. :frowning: but don’t known what I’m doing wrong.

Get and SetParameterByParameterGUID has be a wish for a long time.

You’re looking at the documentation that exists to direct you to the recommended alternative there, but you want the API call itself.

Note that the call is element.Parameter[guid], and that syntax isn’t valid in Python. As such the method you use to access it will have to change based on your selected Python engine. That python engine will change further based on your Revit release. All of this paragraph is exactly why C# has become so much more valuable while Python so much less than it was from 2015 to 2021(ish).

For now you can parse your options to get what you are after from the element using OUT = dir(element), then you can explore one of those options using OUT = element.MethodYouAreInteresterIn.__doc__

This very helpfull.

I notice that get_Patameter method is available.
It it needs a System.Guid

I’m still working whit this.

Keep you update.

You’re pretty close now…

Try OUT = guids.__class__ to see what type of object guids is in your original code.

Then try OUT = guids.__class__, guids[0].__class__ to see something else.

As you said, depends on which python enginee you use, the result is different.

I’m working whit a CableTray
IronPython2
dir(element) = IronPython.Runtime.Types.PythonType

CPython3
TypeError

Do you have a resource to understand, in deep, why this is happening.

You’re trying to get the parameter with a list here (replace guids with g)

The TypeError is quite odd, I’ve not seen dir error like that - can you type the element? What version of Revit / Dynamo?

I have been able to get parameters via Guids with Cpython3 and IronPython2
Example code using Autodesk Architectural Sample file

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument

shared_params = (
    FilteredElementCollector(doc)
    .OfClass(SharedParameterElement)
)

entourage = (
    FilteredElementCollector(doc)
    .OfCategory(BuiltInCategory.OST_Entourage)
    .OfClass(FamilySymbol)
)

enscape_asset_id = [sp for sp in shared_params if sp.Name == "EnscapeAssetId"][0]

guid = enscape_asset_id.GuidValue

OUT = (
    str(guid),
    [(p.Definition.Name, p.AsString()) for p in map(lambda e: e.get_Parameter(guid), entourage)],
)

It’s a cable tray. Might be the wrapper is missing something that the class isn’t converting from C# to C completely.

There are a few posts on the topic, but to understand ‘why’ you have to dig very deep into how computers process code.

Basically things are processed as machine code - 1s and 0s. A step above that is assembly which some humans can work with readily, but not many. A step or two above that is C which humans can use but it requires a good bit of extra work as you have to manually do stuff like clean up your memory. And a step or two above that is C# which does a lot of the stuff which C required you manually do. Before you run code it has to be compiled into content which can be passed though a series of interpreters to get down to machine code so that it can be executed.

Scripting languages (Python, Dynamo, anything which doesn’t have to be compiled before you run it) pass what we write though a virtual machine which does the interpretation at one of the levels of code noted above.

Dynamo works in C#. Revit’s API is also C#. Python’s main implementation works in C natively (CPython).

As a result of those changes in level each Revit object you want to use in the default Python environment needs to be translated from C# to C to so Python can use it, then translated a few times down to machine code to be processed, then the results are translated back up to C for use in Python, then they have to be translated to C# for you to get them.

Imagine sitting in a room with 3 people who want to have a conversation. Person 1 speaks English only, person 2 speaks English and Swedish, and person 3 speaks only Swedish. Person one says something and person 2 can translate to Swedish without much issue, and then person 3 can understand most of what was said. But if this game of translation telephone were to continue in a loop over five or six people… things would get lost in translation. That is likely what is happening here with your CPython.

But by changing to IronPython you trade off security (IronPython2 is unsupported and will cease to run in a future release of Dynamo) for reduced translation efforts thereby keeping more of the components working through the loop.

Works for me. Revit 2024

The model itself may be different causing the issue, there may be an environment configuration (i.e. what Revit/Dynamo customizations) breaking things, or something as crazy as an infosec policies could be at play… Really hard tos ay without the source model and more direct troubleshooting.