How to filter a element type by shared parameter

Hello,

I am creating a script where I want to sort through all walls which are of a given built in parameter and then loop through all of those and identify the wall type which matches a given parameter.

I have no worries using the built in parameters, but it is the shared parameters (project parameters that are causing my confusion).

I have done a lot of research and it seems that the only way to call a shared paramter is by calling its GUID, with get_Paramter(GUID). I have seen examples where this is simply hard coded in and taken from the text file.

My question is, is there an easier way where I can just pass in the name of my shared parameter as a string and then call it from there. It sounds too easy, but I just cant find any threads or infromation explaining this.

Thankyou, Sam

Element.get_Parameter(Guid), or the more recent property Element.Parameter[Guid], is the preferred way of getting a shared parameter as you can ensure that you are getting the exact parameter. However, you can also use Element.LookupParameter(string) or Element.GetParameters(string) may also be used. There are obvious drawbacks to using either of these.

Element.LookupParameter(string) returns the first parameter found by that name (or None if not found). If there are multiple parameters with that name, you won’t be able to find their values.

Element.GetParameters(string) returns all parameters with the given name, however you cannot easily deduce which parameter value is the correct one.

If you are confident that your shared parameter has a unique name, you can use the LookupParameter method and you shouldn’t have any issues.

Hi @cgartland,

Thankyou for your quick response. In this case, it should be unique.

However I am interested to understand the preferred way of with the GUID. Would this always involve hardcoding it in? and if so, where would I find the source of the hard code?

Sam

Hardcoding it is probably the most reliable way. It is possible to get the GUID programmatically, but this requires you to have the shared parameters file loaded into Revit. If each user doesn’t have the same shared parameters file loaded in, then this will not work.

Open shared parameters file, which returns a DefinitionFile

Get DefinitionGroups from DefinitionFile

Get Definitions from DefinitionsGroup

These should all be ExternalDefinitions, which each have a GUID property.

You can then use the Guid to get the exact Parameter from the Element using this syntax:

# assuming element is valid Revit Element
# assuming guid is valid .NET Guid
parameter = element.Parameter[guid]

I have simply copy and pasted a guid from my txt file and places as below:

Element.get_Parameter(d6b7c152-dcbc-4c0d-b410-b8c8d5cead34)

However, it throws an exception about a series of letters, digits half way throguh (c0d) would there be a reason for this? I assume this is what you mean by hardcoded in.

Sam

You will need to create a Guid using a string like this:

from System import Guid
guid = Guid('d6b7c152-dcbc-4c0d-b410-b8c8d5cead34')

In the documentation for the Parameter property of an Element, we can see that it requires a System Guid.

In practice, you would do something like this:

from System import Guid
guid = Guid('d6b7c152-dcbc-4c0d-b410-b8c8d5cead34')
# Assume element is a valid Element
param = element.Parameter[guid]
if param.StorageType == StorageType.String:
    value = param.AsString()
elif param.StorageType == StorageType.ElementId:
    value = param.AsElementId()
elif param.StorageType == StorageType.Double:
    value = param.AsDouble()
elif param.StorageType == StorageType.Integer:
    value = param.AsInteger()

Perfect! clear what I was missing now!