Schedule borders

Schedule borders

chris.j.mckeown
Contributor Contributor
4,464 Views
11 Replies
Message 1 of 12

Schedule borders

chris.j.mckeown
Contributor
Contributor

Hello,

 

Could someone please provide an example for applying borders to schedules, in particular header borders? I know this is possible to do as I have seen APPs do this.

 

I have been following this forum: ViewSchedule cell style override (border) - help needed but there has been no resolution yet. I have also follow the processes described in this post with no luck.

 

Regards

 

Chris

0 Likes
Accepted solutions (1)
4,465 Views
11 Replies
Replies (11)
Message 2 of 12

jeremytammik
Autodesk
Autodesk

Have you looked at the TableCellStyle BorderBottomLineStyle, BorderLeftLineStyle, etc. properties?

 

Cheers

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 12

chris.j.mckeown
Contributor
Contributor

Hi Jeremy,

 

Thank you for you reply.

 

Please see the code I am using below. I am sure it is a order thing. I have tried multiple different orders but with no luck.

 

 

#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)

{

try

{

UIApplication uiapp = commandData.Application;

UIDocument uidoc = uiapp.ActiveUIDocument;

Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;

Document doc = commandData.Application.ActiveUIDocument.Document;

if (doc.IsFamilyDocument)

{

Helper.MessageInfo("Action not available in the Family environment.");

}

else

{

_ImportCategory(commandData, doc);

}

return Autodesk.Revit.UI.Result.Succeeded;

}

catch (Exception e)

{

message = e.Message;

return Autodesk.Revit.UI.Result.Failed;

}

}

private void _ImportCategory(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);

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);

}

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 = 90 * 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

0 Likes
Message 4 of 12

jeremytammik
Autodesk
Autodesk

Dear Chris,

 

Can you achieve what you want manually in the user interface?

 

If not, hopes are slim that it can be done programatically.

 

If you can, then please submit a complete minimal reproducible case so we can test with one click and hopefully analyse and fix the API issue:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 12

chris.j.mckeown
Contributor
Contributor

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

 

 

0 Likes
Message 6 of 12

chris.j.mckeown
Contributor
Contributor

Hi Jeremy,

 

Any luck with the examples I provided?

 

Regards

 

Chris

0 Likes
Message 7 of 12

jeremytammik
Autodesk
Autodesk

Dear Chris,

 

Thank you for your sample material and update.

 

I cannot really say... I was hoping someone else might jump in with more experience in this area.

 

I am passing it on to the development team now to hear what they have to say.

 

Thank you for your patience.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 12

chris.j.mckeown
Contributor
Contributor
Accepted solution

Dear team,

 

I have resolved this issue.

 

instead of:

 

tcs.BorderBottomLineStyle = styleLines.Id;

 

I needed:

 

tcs.BorderBottomLineStyle = styleLines.GraphicsStyleCategory.Id;

 

Regards

Message 9 of 12

jeremytammik
Autodesk
Autodesk

Dear Chris,

 

Thank you very much for letting us know!

 

Kudos!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 10 of 12

Anonymous
Not applicable

Hello,

 

1- While creating a Beam Schedule I want to add a "Beam Location Mark" and Slab location mark in terms of grid Similar to Column Schedule.

I want to locate Beam in form of  B1-E1 0r B1-B5. Similarly for Slab Location Mark in form of B1-D5. Can anyone help me out?

2- I also want cross Sectional Dimensions (length x width) field in Beam and Column Schedule. Please Help me out.

 

Thanks, Amit

 

0 Likes
Message 11 of 12

peterbim
Advocate
Advocate
Hello! That is actual even after years) Please tell me how can I use your code? Need to create a macro in Revit? Or some other way
0 Likes
Message 12 of 12

jeremy_tammik
Alumni
Alumni

Chris' code above is from a Revit add-in. It can easily be converted to work in a macro, and also migrated to Python for integration in a Dynamo node.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes