GroupHeaders Method (Int32, Int32, Int32, Int32, String)


Groups schedule header cells.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2014

Syntax

C#
public void GroupHeaders(
	int top,
	int left,
	int bottom,
	int right,
	string caption
)
Visual Basic
Public Sub GroupHeaders ( _
	top As Integer, _
	left As Integer, _
	bottom As Integer, _
	right As Integer, _
	caption As String _
)
Visual C++
public:
void GroupHeaders(
	int top, 
	int left, 
	int bottom, 
	int right, 
	String^ caption
)

Parameters

top
Type: SystemInt32
The index of the top row of the selected headers.
left
Type: SystemInt32
The index of the left column of the selected headers.
bottom
Type: SystemInt32
The index of the bottom row of the selected headers.
right
Type: SystemInt32
The index of the right column of the selected headers.
caption
Type: SystemString
The header caption.

Examples

CopyC#
public static void CreateSingleCategoryScheduleWithGroupedColumnHeaders(Document doc)
{
    using (Transaction t = new Transaction(doc, "Create single-category with grouped column headers"))
    {
        // Build the schedule
        t.Start();
        ViewSchedule vs = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Windows));

        AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.WINDOW_HEIGHT));
        AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.WINDOW_WIDTH));
        AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.ALL_MODEL_MARK));
        AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.ALL_MODEL_COST));

        doc.Regenerate();

        // Group the headers in the body section using ViewSchedule methods
        vs.GroupHeaders(0, 0, 0, 1, "Size");
        vs.GroupHeaders(0, 2, 0, 3, "Other");
        vs.GroupHeaders(0, 0, 0, 3, "All");

        t.Commit();
    }
}

/// <summary>
/// Adds a single parameter field to the schedule
/// </summary>
public static void AddRegularFieldToSchedule(ViewSchedule schedule, ElementId paramId)
{
    ScheduleDefinition definition = schedule.Definition;

    // Find a matching SchedulableField
    SchedulableField schedulableField =
        definition.GetSchedulableFields().FirstOrDefault<SchedulableField>(sf => sf.ParameterId == paramId);

    if (schedulableField != null)
    {
        // Add the found field
        definition.AddField(schedulableField);
    }
}
CopyVB.NET
Public Shared Sub CreateSingleCategoryScheduleWithGroupedColumnHeaders(doc As Document)
    Using t As New Transaction(doc, "Create single-category with grouped column headers")
        ' Build the schedule
        t.Start()
        Dim vs As ViewSchedule = ViewSchedule.CreateSchedule(doc, New ElementId(BuiltInCategory.OST_Windows))

        AddRegularFieldToSchedule(vs, New ElementId(BuiltInParameter.WINDOW_HEIGHT))
        AddRegularFieldToSchedule(vs, New ElementId(BuiltInParameter.WINDOW_WIDTH))
        AddRegularFieldToSchedule(vs, New ElementId(BuiltInParameter.ALL_MODEL_MARK))
        AddRegularFieldToSchedule(vs, New ElementId(BuiltInParameter.ALL_MODEL_COST))

        doc.Regenerate()

        ' Group the headers in the body section using ViewSchedule methods
        vs.GroupHeaders(0, 0, 0, 1, "Size")
        vs.GroupHeaders(0, 2, 0, 3, "Other")
        vs.GroupHeaders(0, 0, 0, 3, "All")

        t.Commit()
    End Using
End Sub

' <summary>
' Adds a single parameter field to the schedule
' </summary>
Public Shared Sub AddRegularFieldToSchedule(schedule As ViewSchedule, paramId As ElementId)
    Dim definition As ScheduleDefinition = schedule.Definition

    ' Find a matching SchedulableField
    Dim schedulableField As SchedulableField = definition.GetSchedulableFields().FirstOrDefault(Function(sf) sf.ParameterId = paramId)

    If schedulableField IsNot Nothing Then
        ' Add the found field
        definition.AddField(schedulableField)
    End If
End Sub

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsArgumentException Headers could not be grouped.
Autodesk.Revit.ExceptionsArgumentNullException 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 →