Friday, February 26, 2010

[Revit] How to make a web page that displays your standard keyboard shortcuts

As I’ve previous mentioned, the subscription pack for Revit 2010 introduced a new XML based methodology for setting up keyboard shortcuts.

In previous posts I’ve shown you what file to replace if you want to standardize this across your firm (we have a tool that users run which installs the latest API add-ins and copies the keyboard shortcuts file). I was recently asked to make a page which could display a listing of the latest keyboard shortcuts as a quick reference for our drafters to look or search through. The reason for this, is the inbuilt menu in Revit, whilst a massive step up from the text file, is not good for a quick glance over or print out.

Luckily, as the new system uses XML, this is was very easy for me to do.

I simply created a new ASP.NET web page on our intranet, with a gridview on it:

    
        <asp:GridView ID="GridView1" AllowSorting="true" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" ForeColor="#333333" 
            GridLines="None" OnSorting="GridView1_Sorting">
            <RowStyle BackColor="#E3EAEB" />
            <Columns>
                <asp:BoundField DataField="CommandName" HeaderText="CommandName" 
                    SortExpression="CommandName" />
                <asp:BoundField DataField="Shortcuts" HeaderText="Shortcuts" 
                    SortExpression="Shortcuts" />
                <asp:BoundField DataField="Paths" HeaderText="Paths" SortExpression="Paths" />
            </Columns>
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#7C6F57" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>

There is a fair bit of extra code there for styling the control, but the main part is the bound fields.

And then in the code behind, I bound the XML file (which we have stored on a network drive) to the gridview like so:

        //create a dataset from the xml
        DataSet ds = new DataSet();
        ds.ReadXml(@"\\PATH\TO\YOUR\SHORTCUT\FILE\KeyboardShortcuts.xml");

        //create it into a dataview and sort it via command name
        DataView view = new DataView(ds.Tables[0]);
        view.Sort = "CommandName";

        //bind the gridview to the dataview
        GridView1.DataSource = view;
        GridView1.DataBind();

And you will have a page which looks like this:

image

I’ve added sorting by using the AllowSorting=”true” property and binding to the event for sorting by using OnSorting=”GridView1_Sorting” as well has setting the SortExpression property in each BoundField.

The method that is called when the user tries to sort the gridview has the following code:

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        DataView view = (DataView) GridView1.DataSource;
        view.Sort = e.SortExpression;

        GridView1.DataSource = view;
        GridView1.DataBind();
    }

And there you have it – a live updating view of our company standard keyboard shortcuts XML file, great for educating drafters on shortcuts they may not have known about.

No comments: