# -*- coding: utf-8 -*-
# New output.print_table() method 

from pyrevit import script # DB, forms, revit



# Management of output window
output = script.get_output()
output.set_title("New output.print_table() method")
output.set_width(1100)
output.set_height(900)
output.close_others()
output.show()


# Test data as 2D list in 4 columns
table_data_a = [
        ["444444", "longueur", "12.00", "41"],
        ["44444444", "longueur", "12.20", "01"],
        ["444444444444444444", "longueur", "22.02", "12"],
        ["4444444444444", "longueur", "11.00", "44"],
        ["444444444444444444", "longueur", "12.11", "99"],
        ["44444444444444", "longueur", "12.03", "110"],
        ["123456456", "987654", "22.45", "41"]
    ]

# Test data as 2D list in 3 columns with linkify
table_data_b=[
    [u'<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=2827&amp;show=false">L\xe9gende</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=2827&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span>', '<b>Legend 02 Wall types</b> (sur 2 feuilles)', ' '], 
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3482&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3482&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A102', 'Permit plan Zone A'],
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A103', 'Permit plan Zone B'],
    [u'<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=2803&amp;show=false">L\xe9gende</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=2803&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span>', '<b>Legend 00 Fire safety</b> (sur 2 feuilles)', ' '],
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3482&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3482&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A102', 'Permit plan Zone A'],
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A103', 'Permit plan Zone B'],
    [u'<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=2786&amp;show=false">L\xe9gende</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=2786&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span>', '<b>Legend 04 Section references</b> (sur 3 feuilles)', ' '],
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3464&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3464&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A101', 'General plan'], 
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3482&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3482&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A102', 'Permit plan Zone A'], 
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A103', 'Permit plan Zone B'], 
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A104', 'Permit plan Zone C'], 
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A105', 'Permit plan Zone D'], 
    [' ', '<span><a title="Click to select or show element" class="elementlink" style="padding-right: 3px; margin-right: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=false">Feuille</a><a class="elementlink" style="padding-left: 3px; margin-left: 0px;" href="revit://outputhelpers?&amp;command=select&amp;element[]=3509&amp;show=true"><svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20" width="14" height="14"><path fill="white" d="M 9.5 3 A 6.5 6.5 0 0 1 16 9.5 C 16 11.11 15.41 12.59 14.44 13.73 L 14.71 14 H 15.5 L 20.5 19 L 19 20.5 L 14 15.5 V 14.71 L 13.73 14.44 C 12.59 15.41 11.11 16 9.5 16 A 6.5 6.5 0 0 1 3 9.5 A 6.5 6.5 0 0 1 9.5 3 M 9.5 5 C 7 5 5 7 5 9.5 C 5 12 7 14 9.5 14 C 12 14 14 12 14 9.5 C 14 7 12 5 9.5 5 Z"></path></svg></a></span> A106', 'Permit plan Zone E']
    ]

# Column header titles
columns = ["NUMBERS", "STRINGS", "DECIMALS", "PERCENTAGE"]

# Formatting options for data cells using python string formatting
# formats = ['{}', '{}', '{}', '{}%']s
formats=['{:.5}', '{}', '', '{}%'] # According to pyRevit docs

# Example values for string formatting of data cells :
# {:.5}   # Characters 0 - 5. Works for numbers and strings
# {}%     # Add % at end. Works for numbers and strings
# {:>10}  # Might work, but probably does not override the HTML alignment
# {:.^10} # Centering with width 10 characters

# Values for column_widths are percentage or pixels, for example "20%" or "180px" (CSS)
column_widths = ["20%", "20%", "40%", "20%"]

# Text-alignment or header row titles (CSS)
column_head_align_styles = ["center", "left", "right", "center"]

# Text-alignment or header row titles (CSS)
column_data_align_styles = ["right", "left", "right", "center"]

# Option for vertical borders (horizontal are on by default) (CSS)
column_vertical_border_style = "border:black solid 1px"

# Text-style for the last row of data (CSS)
last_line_style="color:red; font-weight:bold"

# Option to repeat the header at the bottom (useful for long tables) (bool)
repeat_head_as_foot = True if len(table_data_a)>14 else False # Automatic option by table length

# Overall tablee width in percentage or pixels, for example "20%" or "180px" (CSS)
table_width_style="100%"


output.print_table(table_data_a, 
                           title="New print_table method (variable width)",
                           columns=columns,
                           column_head_align_styles=column_head_align_styles,
                           column_data_align_styles=column_data_align_styles,
                           column_widths = column_widths,
                           column_vertical_border_style=column_vertical_border_style,
                           formats=formats,
                           last_line_style=last_line_style,
                           repeat_head_as_foot=repeat_head_as_foot,
                           table_width_style=table_width_style)


columns = ["Sél/Zoomer", "Légende > Feuilles", "Nom de feuille"]

column_head_align_styles = ["center", "left", "left"]

column_data_align_styles = ["right", "left", "left"]

column_vertical_border_style = None

last_line_style=None

repeat_head_as_foot = True if len(table_data_b)>12 else False # Automatic option by table length

column_widths = ["115px", "auto", "auto"]
table_width_style="800px"
row_striping = False

output.print_table(table_data_b, 
                           title="New print_table method (fixed width) ",
                           columns=columns,
                           column_head_align_styles=column_head_align_styles,
                           column_data_align_styles=column_data_align_styles,
                           column_widths = column_widths,
                           column_vertical_border_style=column_vertical_border_style,
                           formats=None,
                           last_line_style=last_line_style,
                           repeat_head_as_foot=repeat_head_as_foot,
                           table_width_style=table_width_style,
                           row_striping=row_striping)


