Hi Jeremy,
Yes this can be done in the user interface.
Please see attached a a 2015 Revit file with 2 schedules and a sheet.
The schedule called "Created in Revit" is the schedule I am aiming for with Hidden lines as the borders.
The schedule called "Generic Model Schedule" is created via the code below. When I try apply the hidden lines as the line style they end up greyed out in when editing the schedule, as if the Hidden line type is not recognised.
#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Windows.Forms;
#endregion
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
class tableHeaderTest : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Document doc = commandData.Application.ActiveUIDocument.Document;
scheduleHeader(commandData, doc);
return Autodesk.Revit.UI.Result.Succeeded;
}
private void scheduleHeader(ExternalCommandData commandData, Document doc)
{
Transaction trans = new Transaction(doc, "Create schedule");
trans.Start();
ViewSchedule schedule = null;
try
{
FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(GraphicsStyle));
GraphicsStyle styleLines = collector.Cast<GraphicsStyle>().FirstOrDefault<GraphicsStyle>(gs => gs.Name.Equals("<Hidden>"));
schedule = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_GenericModel));
foreach (ElementId id in ViewSchedule.GetAvailableParameters(doc, new ElementId(BuiltInCategory.OST_GenericModel)))
{
if (new ElementId(BuiltInParameter.DOOR_NUMBER) == id)
schedule.Definition.AddField(new SchedulableField(ScheduleFieldType.Instance, id));
}
ScheduleFilter sf = new ScheduleFilter(schedule.Definition.GetField(0).FieldId, ScheduleFilterType.Equal, "");
schedule.Definition.AddFilter(sf);
sf = new ScheduleFilter(schedule.Definition.GetField(0).FieldId, ScheduleFilterType.NotEqual, "");
schedule.Definition.AddFilter(sf);
TableSectionData header = schedule.GetTableData().GetSectionData(SectionType.Header);
ScheduleField field = schedule.Definition.GetField(0);
field.ColumnHeading = "";
int rows = 10;
int columns = 10;
for (int i = 0; i < rows - 1; i++)
{
header.InsertRow(1);
}
for (int i = 0; i < columns - 1; i++)
{
header.InsertColumn(1);
}
double totalWidth = 0;
for (int col = 0; col < header.NumberOfColumns; col++)
{
totalWidth = totalWidth + (20 / 304.8);
header.SetColumnWidth(col, 20 / 304.8);
}
field.GridColumnWidth = totalWidth;
for (int col = 0; col < header.NumberOfColumns; col++)
{
for (int row = 0; row < header.NumberOfRows; row++)
{
try
{
header.SetCellText(row, col, "text");
TableCellStyle tcs = new TableCellStyle();
TableCellStyleOverrideOptions options = new TableCellStyleOverrideOptions();
options.FontSize = true;
options.BackgroundColor = true;
options.Bold = true;
options.BorderLineStyle = true;
options.BorderBottomLineStyle = true;
options.BorderLeftLineStyle = true;
options.BorderRightLineStyle = true;
options.BorderTopLineStyle = true;
options.Font = true;
options.FontColor = true;
options.HorizontalAlignment = true;
options.Italics = true;
options.TextOrientation = true;
options.Underline = true;
options.VerticalAlignment = true;
tcs.SetCellStyleOverrideOptions(options);
tcs.BackgroundColor = new Autodesk.Revit.DB.Color(255, 244, 10);
tcs.BorderBottomLineStyle = styleLines.Id;
tcs.BorderLeftLineStyle = styleLines.Id;
tcs.BorderRightLineStyle = styleLines.Id;
tcs.BorderTopLineStyle = styleLines.Id;
tcs.FontHorizontalAlignment = HorizontalAlignmentStyle.Right;
tcs.FontVerticalAlignment = VerticalAlignmentStyle.Top;
tcs.IsFontBold = true;
tcs.IsFontItalic = true;
tcs.TextColor = new Autodesk.Revit.DB.Color(0, 0, 0);
tcs.TextOrientation = 0 * 10;
tcs.TextSize = 10;
header.SetCellStyle(row, col, tcs);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
trans.Commit();
MessageBox.Show("Complete.");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
Regards
Chris