IsUniqueName Method


Tests whether a name is unique among existing global parameters of a given 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 bool IsUniqueName(
	Document document,
	string name
)
Visual Basic
Public Shared Function IsUniqueName ( _
	document As Document, _
	name As String _
) As Boolean
Visual C++
public:
static bool IsUniqueName(
	Document^ document, 
	String^ name
)

Parameters

document
Type: Autodesk.Revit.DB Document
Document in which a new parameter is to be added.
name
Type: System String
A name of a parameter being added.

Return Value

True if the given %name% does not exist yet among existing global parameters nof the document; False otherwise.

Remarks

Typically, this method is used before a new global parameters is created, for all global parameters must have their names unique in the scope of a document.

Examples

Copy C#
/// <summary>
/// Creates or finds a global parameter of a given 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</returns>
public GlobalParameter GetOrCreateAGlobalParameter(Document document, String name)
{
    GlobalParameter gp = null;

    // Global parameters are not available in all documents.
    // They are available in projects, but not in families.
    if (GlobalParametersManager.AreGlobalParametersAllowed(document))
    {
        if (GlobalParametersManager.IsUniqueName(document,name))
        {
            // if the name is not unique, the global parameter must exist already
            gp = document.GetElement(GlobalParametersManager.FindByName(document, name)) as GlobalParameter;
        }
        else
        {
            // A global parameter with such a name does not exist yet;
            // Let's create a new one (assume the type is Number)
            using (Transaction trans = new Transaction(document, "Create Global Parameter"))
            {
                trans.Start();
                gp = GlobalParameter.Create(document,name,ParameterType.Number);
                trans.Commit();
            }
        }
    }

    return gp;
}
Copy VB.NET
' <summary>
' Creates or finds a global parameter of a given 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</returns>
Public Function GetOrCreateAGlobalParameter(document As Document, name As [String]) As GlobalParameter
    Dim gp As GlobalParameter = Nothing

    ' Global parameters are not available in all documents.
    ' They are available in projects, but not in families.
    If GlobalParametersManager.AreGlobalParametersAllowed(document) Then
        If GlobalParametersManager.IsUniqueName(document, name) Then
            ' if the name is not unique, the global parameter must exist already
            gp = TryCast(document.GetElement(GlobalParametersManager.FindByName(document, name)), GlobalParameter)
        Else
            ' A global parameter with such a name does not exist yet;
            ' Let's create a new one (assume the type is Number)
            Using trans As New Transaction(document, "Create Global Parameter")
                trans.Start()
                gp = GlobalParameter.Create(document, name, ParameterType.Number)
                trans.Commit()
            End Using
        End If
    End If

    Return gp
End Function

Exceptions

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

See Also

ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →