Tuesday, March 29, 2011

[Revit API]–Revit 2012 and Vendor IDs

The NDA has lifted on Revit 2012, and Jeremy Tammik has posted a summary of the Revit API changes and additions. I hope to add some Revit 2012 information as I get stuck into it over the coming weeks, however for now I wanted to throw up a post to tell you about the new Vendor ID’s.

In Revit 2012, each add-in that you make must be associated with a ‘Vendor ID’, which is an Autodesk Registered Developer Symbol. In the .addin manifest file you must enter this vendor ID as another field. This helps to identify who made the application, and also is used for some great new features like the ‘Extensible Storage’, which lets you put some private API data in the model that only addins with your Vendor ID can use.

While you may not have started developing Revit 2012 addins yet, I recommend you go and register a Developer Symbol on the Autodesk website ASAP. Developer Symbols (aka Vendor ID) are 4 characters in length, meaning there is a limited number of combinations. In the end, it doesn’t really matter what combination you choose, but it would certainly be nice to have one that relates to your company wouldn’t it? The example Autodesk uses is ADSK for their vendor ID.

Head on over and register it today, it’s really easy, you just need to fill out a form like this:

image

Though a point to note, this page says that all fields in Bold are required, and the fax number is in bold. Before you begin on a rant on how we should be in the 21st century and a fax number should not be required, relax, this is an error – you don’t need to enter in a fax number.

Friday, March 25, 2011

[Revit]–Journal File Analyzer–Free Utility to identify Keyboard Shortcut candidates

Luke Johnson runs a great Revit blog called ‘What Revit Wants’, which is updated frequently with lots of good general Revit information. He recently issued a challenge in regards to Journal file analyzing which I have (somewhat) answered.

The result is a utility that I’ve developed that will take a look through your journal files and identify your most commonly used menu items, along with your most commonly used keyboard shortcuts. The idea is that you can run this utility and assess what commands you should add a keyboard shortcut to, in order to make your Revit usage more efficient.

To run the utility, you simply open it, enter the correct location of your Journal files and (optionally) your keyboard shortcuts.xml location (it tries to auto detect this for you, but you may need to change Structure to Architecture in the path).

Click Analyze and it will look through the journal files and tally up your 20 most commonly used commands with and without shortcuts..

image

An example output for Top Shortcuts used is as follows:

Create a straight detail line or a detail arc , DL  - 120 times
Control visibility and appearance of objects (applied only in the active view) , VG  - 116 times
Trim/Extend two lines or walls to make a corner. , TR  - 88 times
Create a line , XD  - 82 times
Create Aligned Dimensions , DD#DA  - 75 times
Create a text object , T3  - 69 times
Create a detail component , DC  - 65 times
Redraw everything as large as fits into window , ZF#ZE  - 56 times
Align references. , AL  - 39 times
Draw all lines as thin lines. This does not affect printing. , TL  - 36 times
Trim/Extend multiple lines or walls to the same bounding reference. , EX  - 34 times
Create a default 3D orthographic view. , 3D  - 34 times
Split walls and lines , ES#SPL  - 26 times
Manage Links , ML  - 24 times
Change style of selected lines , LW  - 22 times
Copy the type of one object to other objects , MT#MA  - 21 times

What this is saying, is the general name of the command, followed by the keyboard shortcut for that command (as long as you have linked in your shortcuts file) followed by how many times you used that command.

On the right is the display of the top commands used that weren’t started from a keyboard shortcut:

"Undo the last action , ID_BUTTON_UNDO" - 37 times
"Move selected objects or their copies , ID_EDIT_MOVE" - 23 times
"Show or hide recent files , ID_STARTUP_PAGE" - 20 times
"Move copies of selected objects , ID_EDIT_MOVE_COPY" - 8 times
"Finish the family , ID_END_INPLACE_FAMILY" - 8 times
"Prevent change of element position , ID_LOCK_ELEMENTS" - 8 times
"Save the active project back to the Central File , ID_FILE_SAVE_TO_MASTER_SHORTCUT" - 6 times
"Save the active project with a new name , ID_REVIT_FILE_SAVE_AS" - 5 times
"Open an existing project , ID_REVIT_FILE_OPEN" - 5 times
" , ID_FILE_CADFORMAT_LINK" - 5 times
"Finish Sketch , ID_FINISH_SKETCH" - 4 times
"Redo the next action , ID_BUTTON_REDO" - 4 times
"Save the active project , ID_REVIT_FILE_SAVE" - 3 times
" , ID_REVIT_SAVE_AS_FAMILY" - 2 times
"Pick Lines , IDC_RADIO_COPY_CURVE" - 2 times
"Review previously posted warnings , ID_REVIEW_WARNINGS" - 1 times
"Purge (delete) unused families and types , ID_PURGE_UNUSED" - 1 times
"Create a rectangle , ID_OBJECTS_CURVE_RECT" - 1 times
"Modify predefined types for this family , ID_FAMILY_TYPE" - 1 times
"Quit in place family , ID_QUIT_INPLACE_FAMILY" - 1 times

You can see here the name of the command, it’s ID and how many times you’ve used it.

The ‘Include Context Menu Entries’ checkbox is used for if you want to include commands that were fired from menus like the right click menu – which often you can’t create a keyboard shortcut for, but sometimes you can (Save To Central shows up in this listing).

To download the tool and run it on your own download it from HERE. Let me know how it goes for you!

Also, if you are interested in the source code, it’s available on GitHub. If you don’t have Git (you should check it out!) you can download the source code as a Zip. If you want to modify the code feel free to send me a Push request!

Monday, March 7, 2011

[Revit] Tic Tac Toe for Revit with online play

This is a ‘for fun’ project that I have been working on this week. It started out as something interesting to code while I was up late due to having too many coffees, but then I decided to add a few more features to it throughout the week.

The game is a version of Tic Tac Toe (naughts and crosses) using rooms in Revit as the squares.

image

The game can be played either locally, or online via sever connection.

image

The local game is intended to be played by two people sitting at the same computer, swapping the mouse between each other in between turns. When the game starts, the user must click inside the room that they wish to place their X or O in:

image

Then it is the other players turn, and so on until the game is won, or all rooms are filled. When the game is won, the text notes on the view are updated to add to the score:

image

After getting this working, I decided I could try and take it one step further, by adding online play. To play this the user selects online play when starting the game, and then they must either create or join a new session:

image

Clicking Create New Session will get a new session ID from the server.

image

That session ID must be then passed to the opponent who enters it in the textbox on the same screen. Once both people are ready, click ‘Start Game’.

The game then plays out in a similar way to the local game, but after each turn you’ll see the ‘waiting on other player’ screen:

image

When the other player takes their turn, your view will be updated with their input.

image

This continues until the game is won or board is filled.


To install the game, download it from HERE and unzip the files to C:\RevitTicTacToe\. Then move the TicTacToe-Manifest.addin file to your Revit Addins directory, which will be one of the following:

Vista/7 Users:
C:\ProgramData\Autodesk\Revit\Addins\2011

XP Users:
C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2011\

image

image

Then simply open GameBoard.rvt from C:\RevitTicTacToe\ and run the the addin from Add-Ins tab, External Tools menu:

image


While this is a bit of a silly project, it was a bit of fun, and I got to use a few cool techniques which will form the base of some blog posts to come, including manual transactions in Revit, RESTful web services in ASP.NET MVC, interacting with rooms via the API, making web requests from Revit and more.

When showing an early version of this game to some Revit users it was mentioned that they believed some of this functionality could be implemented in a Revit family, I mentioned to Jason Grant on Twitter that I’d love to see if any expert Revit Family makers can rise to the challenge and give a working version of Tic Tac Toe in a family!

Feel free to give the game a go, let me know if you find any bugs in it. If you want to take a look at the source code, it’s available on GitHub. You can download it all using the Git verison control system, or you can click on files online to view them in browser.

Wednesday, March 2, 2011

[ASP.NET MVC]–Custom DisplayFor partial view for IEnumerable<T>

-------------------------------------------------------------
Notice: This is a post related to ASP.NET MVC version 3. If you are a regular reader of this blog who is only interested in Revit API posts, please change your RSS subscription to the new ‘Revit Only Feed’ – see this post for more information.
-------------------------------------------------------------

In ASP.NET MVC, you can generate a HTML display for a model property by using Html.DisplayFor(model => model.Property); however you may want to create a custom partial view for this display rather than use the default output.

To do this, create a folder called DisplayTemplates under Views/ControllerName and add your partial view in there. To make it automatically choose this template for a certain type of object, you need to name it the name of the Type. For simple types, this is fine, but what about IEnumerable<SomeObject>? Naming your files like this is likely to have problems.

We can get around this with DataAnnotations. In your model, import the System.ComponentModel.DataAnnotations namespace and add [UIHint(“Name”)] attribute to your property, like this:

[UIHint("ProjectsList")]
public IEnumerable<Projects> ProjectsList { get; set; }

Then we can simply create a partial view called ProjectsList in the DisplayTemplates directory

image

Then in your view you can simply use:

@Html.DisplayFor(model => model.ProjectsList);

And your partial view will be used.

[ASP.NET MVC]–Defining Multiple Layout Sections with Razor View Engine

When using MasterPages in ASP.NET web forms you can create a number of ‘ContentPlaceHolder’ sections that allow you to have various editable sections in your template. One example is that you may have something like:

 
<div id="contentBackgroundTop" class="contentBackground">
    <asp:ContentPlaceHolder ID="HeadingPlaceHolder" runat="server">
    </asp:ContentPlaceHolder>
</div>
<div id="contentBackgroundMiddle" class="contentBackground">
        <asp:ContentPlaceHolder ID="PagePlaceHolder" runat="server">
        </asp:ContentPlaceHolder>
</div>

Which lets you have a separate div for your page heading text, and then a div below it for the rest of your content. I recently started using Razor view engine in ASP.NET MVC and was interested in doing a similar thing, here’s how.

The Razor equivalent of master pages is a _Layout.cshtml file. which by default has a @RenderBody() call to do the rendering of your view. However I wanted to have another section to render different text, so I added the following to my layout:

<div id="contentBackgroundTop" class="contentBackground">
    @RenderSection("Heading", false)
</div>
<div id="contentBackgroundMiddle" class="contentBackground">
    @RenderBody()
</div>

As you can see, I’ve added a called to @RenderSection, which takes 2 parameters, the first being the name of the section, the second being a boolean as to whether it’s optional or not – this is very handy as ASP.NET Web Forms forces it to be compulsory.

For my Body content, my view stays the same, except I added the following code to render the Heading section:

@section Heading
{
    <h1>
       Heading Goes Here</h1>
}
This is a nice, neat syntax which you can just add to the top of your view.