FindByName Method


Finds whether a global parameter with the given name exists in the input document.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 17.0.0.0 (17.0.1090.0)
Since: 2016 Subscription Update

Syntax

C#
public static ElementId FindByName(
	Document document,
	string name
)
Visual Basic
Public Shared Function FindByName ( _
	document As Document, _
	name As String _
) As ElementId
Visual C++
public:
static ElementId^ FindByName(
	Document^ document, 
	String^ name
)

Parameters

document
Type: Autodesk.Revit.DB Document
The document expected to contain the global parameter.
name
Type: System String
Name of the global parameter

Return Value

ElementId of the parameter element, or InvalidElementId if it was not found.

Remarks

No exception is thrown when no parameter with such a name exists in the document; instead, the method returns an ElementId.InvalidElementId.

Examples

Copy C#
/// <summary>
/// Tries to find a global parameter by its name. 
/// </summary>
/// <param name="document">Revit project document.</param>
/// <param name="name">Name of a global parameter.</param>
/// <returns>An Element Id of the global parameter, or InvalidElementId if none found</returns>
public ElementId GetGlobalParameterByName(Document document, String name)
{
    // Global parameters are not available in all documents.
    // They are available in projects, but not in families.
    if (GlobalParametersManager.AreGlobalParametersAllowed(document))
    {
        return GlobalParametersManager.FindByName(document, name);
    }

    // return an empty set if global parameters are not available in the document
    return ElementId.InvalidElementId;
}
Copy VB.NET
' <summary>
' Tries to find a global parameter by its name. 
' </summary>
' <param name="document">Revit project document.</param>
' <param name="name">Name of a global parameter.</param>
' <returns>An Element Id of the global parameter, or InvalidElementId if none found</returns>
Public Function GetGlobalParameterByName(document As Document, name As [String]) As ElementId
    ' Global parameters are not available in all documents.
    ' They are available in projects, but not in families.
    If GlobalParametersManager.AreGlobalParametersAllowed(document) Then
        Return GlobalParametersManager.FindByName(document, name)
    End If

    ' return an empty set if global parameters are not available in the document
    Return ElementId.InvalidElementId
End Function

Exceptions

Exception Condition
Autodesk.Revit.Exceptions ArgumentNullException A non-optional argument was NULL

See Also