Managing Global Parameters

The GlobalParametersManager class provides access to general information and data of Global Parameter elements in a particular model.

GlobalParametersManager provides the main access point to managing global parameters in a project document. It provides static methods to access and reorder global parameters and to test for name uniqueness and Id validity.

Accessing global parameters

Global parameters are only supported in project documents, not family documents. Even with a project document, however, global parameters may be disallowed under certain circumstances, either temporarily or permanently. The AreGlobalParametersAllowed() method will indicate whether global parameters are allowed within a specified document.

If global parameters are allowed in a project document, use the methods GetAllGlobalParameters() to get all global parameters in a specified document, or GetGlobalParametersOrdered() to get an ordered list of the global parameters. When retrieving an ordered list, the order of the items corresponds to the order in which global parameters appear in the standard Global Parameters dialog in the Revit user interface.

To get a global parameter by name, call FindByName(), which will return the ElementId of the named global parameter, or ElementId.InvalidElementId if no global parameter is found with the given name. Since global parameter names must be unique, the IsUniqueName() method should be called to check a name prior to creating a new GlobalParameter.

Given an ElementId for a GlobalParameter, the IsValidGlobalParameter() will confirm that the given ElementId is a valid global parameter id.

The following example demonstrates how to get all global parameters, if global parameters are allowed in the document.

Code Region: Getting global parameters

/// <summary>
/// Returns all global parameter elements defined in the given document. 
/// </summary>
/// <param name="document">Revit project document.</param>
/// <returns>A set of ElementIds of global parameter elements</returns>
public ISet<ElementId> GetAllGlobalParameters(Document document)
{
    // Global parameters are not available in all documents.
    // They are available in projects, but not in families.
    if (GlobalParametersManager.AreGlobalParametersAllowed(document))
    {
        return GlobalParametersManager.GetAllGlobalParameters(document);
    }

    // return an empty set if global parameters are not available in the document
    return new HashSet<ElementId>();
}

Reordering global parameters

GlobalParametersManager provides methods to change the given order of the global parameters in the project document. These operations have no effect on the global parameters themselves. The rearranged order is only visible in the standard Global Parameters dialog in Revit and reflected in the GetGlobalParametersOrdered() method.

  • SortParameters() - sorts the global parameters in either ascending or descending alphabetical order, but only within the range of their respective parameter group.
  • MoveParameterDownOrder() - moves a given parameter down in the current order.
  • MoveParameterUpOrder() - moves the given parameter up in the current order.

A parameter can only be moved within its parameter group, so if a parameter can no longer move because it is at the boundary of its group, the MoveParameter methods will return False.