Format Schedule Columns to fit Text to Single Line

Format Schedule Columns to fit Text to Single Line

fdkuenneke
Enthusiast Enthusiast
1,732 Views
5 Replies
Message 1 of 6

Format Schedule Columns to fit Text to Single Line

fdkuenneke
Enthusiast
Enthusiast

Any good ways to accomplish this (title) programatically that I am missing? I am looking to change the width of columns to fit all text in each row to a single line for readability when it is printed on a sheet. My current framework for doing this feels messy, which is very similar to what is provided Here by Fair59's answer:

1. Using TableCellStyle, set to a known font name that I want to use.

2. Loop for current index, row and column.

3. Scale Column Width via ViewSchedule.Definition.GridColumnWidth by a scale factor found using font size.

I can't help but feel that this method couldn't be solved by some method I am ignorant of much more efficiently and safely. Any tips? Thanks in advance.

I'd say Revit was a chisel if it wasn't used as a hammer.
0 Likes
Accepted solutions (1)
1,733 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Frank,

 

Thank you for your query, both here and on StackOverflow:

 

https://stackoverflow.com/questions/60154776/auto-fit-text-into-single-line-of-schedule-column

 

I am not aware of any better method.

 

In most cases I have seen, Fair59 provided the optimal answer over all.

 

I'll gladly check for you with the development team to see whether they can suggest any improvement over that.

 

Best regards,

 

Jeremy

 



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

0 Likes
Message 3 of 6

fdkuenneke
Enthusiast
Enthusiast

Ah, swing and a miss. No problem, thank you for the response! I figured that FAIR59 would have had the right idea. If I have a development, I will update this thread.

I'd say Revit was a chisel if it wasn't used as a hammer.
0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Dear Frank,

 

Definitely worth a try. Thank you for your appreciation.

 

Hope you find a possibility for improvement. Looking forward to hearing about it.

 

I'll let you know if I hear back from the development team.

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 5 of 6

sensiblehira
Advocate
Advocate

was there any update to this .... the link doesn't open so I am just using the method discussed here.

0 Likes
Message 6 of 6

sensiblehira
Advocate
Advocate
for schedule in schedules:
    tableData = schedule.GetTableData()
    bodyData = tableData.GetSectionData(SectionType.Body)
    cols = bodyData.NumberOfColumns
    rows = bodyData.NumberOfRows
    definition = schedule.Definition
    for col in range(cols):
        max_char_count = 0
        for row in range(rows):
            cellText = bodyData.GetCellText(row,col)
            max_char_count = max(max_char_count, len(cellText))
        if col == 2:
            char_width_feet = 0.02
            buffer = 0.022
        else:
            char_width_feet = 0.007
            buffer = 0.007
        new_width = (float(max_char_count) * char_width_feet) + buffer
        field = definition.GetField(col)
        field.GridColumnWidth = new_width
        field.SheetColumnWidth = new_width

I am using this code but it is working for some but not all. For some schedules the size exceeds way too much while for others it falls short.

0 Likes