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.

[Revit API] OleDB Jet Driver for interacting with Excel files in 64bit Revit

A common problem with 64bit development with Revit is the inability to use the Microsoft Jet OleDB driver to read and write to Excel files easily.

In the Getting Started With Revit API.doc file in the 2010 Revit SDK it states:

Note that there are some Microsoft components (such as OleDB provider for Microsoft Jet) that are not supported for 64-bit. All SDK samples are set up to work with either 32-bit or 64-bit Revit, except those samples that have dependencies to unsupported Microsoft components.

Basically, the problem has been that the 3rd party DLL file which is supplied by Microsoft did not have a 64bit version.

While this problem has not yet affected me in my development, I know a few people have mentioned it so I thought I’d pass on something I read today: How to get a x64 version of Jet? on MSDN blogs.

Apparently the beta of Office 2010 has the 64bit dll file everyone has been looking for, it is available HERE.

I hope this helps you out if you have run into this problem.