Archive | Revit RSS feed for this section

View and Edit Revit Models: Add a Filter Using Code

17 Feb

I have recently shown you how to view and edit Revit models on the web without writing any code. I have also shown you how to filter the views using a very little SQL in your database. In this post, I will show you how, in a few lines of code, you can create a search box to filter the results in your pages.

Application Layout

In an MVC application, you have a model, controllers and views. As explained in an earlier post, The model holds the data from the table or tables selected. The controller sits between the model and view performing actions and responding to events which are sent to the model or passed to the view. The view is what you actually see when you load the page. the image below shows the layout of a simple Revit MVC Application.


I have a Revit mode, controllers for Rooms and Walls and views for the Rooms and Walls. There are separate views for each of the CRUD functions. There are other views, models and controllers that are created by .NET by default. Feel free to ignore these at the moment because we will not be using them.

To add filtering to our application, we will need to modify the Rooms View and Controller.

Rooms View

There are several views in the Rooms folder, but for our application we want to modify Index.cshtml. This is the view that returns the entire model – list of rooms in our database.  You can see in the code that the view creates a table with all the properties for each room in our model.


We want to limit the number of items in the Model returned from the controller using a search box. Let’s add the search box to the view. As in standard HTML, we can use a textbox and a button in a form. With MVC, however, we are using the Razor view engine so the code is slightly different.

@using (Html.BeginForm())
Find by name: @Html.TextBox(“SearchString”)
<input type=”submit” value=”Search” />

The code above should make sense if you are familiar with HTML. The only thing that stands out are the lines starting with the @ symbol. These are variables/expressions in Razor. The above code will create our search box.


Rooms Controller

Now that we have the form, we need to create the code in the controller that will handle the request. The first ActionResult in the code is the Get Rooms function. This is the code that returns the Index.html file we see in the view. The code below will make our search box work.

public ActionResult Index(string searchString)
var rooms = from r in db.Rooms
select r;
if (!String.IsNullOrEmpty(searchString))
rooms = rooms.Where(r => r.Name.Contains(searchString));

return View(rooms.ToList());

when we browse to the Index.html page for the first time, we will see all the rooms in the database. This is because the string searchString is empty. So rooms is equal to the contents of the entire database.

var rooms = from r in db.Rooms
select r;

Once on the page and having entered a value and clicked search, we have requested the Index.html page again, but this time with a value for searchString. Now the controller populates the value of rooms with only those records where the string is in the name.

rooms = rooms.Where(r => r.Name.Contains(searchString));

The function always ends by returning the View (the one with the same name as the controller) and passes it the values of our rooms variable – either all of them or a filtered list.

the images below show rooms filter by the word Master and even by just two letters. The code above uses Name.Contains not Name.Equals. this allows us to get results without exact matches.



This little bit of code has greatly improved our application. The code can be modified to search on additional fields and added to other views – like the Walls Index.cshtml view.



Join External Table to Revit Database

4 Feb

In my last post, I showed how to filter a table by creating a view and bringing that view in to your MVC Application. You can also join tables. In this post, I will show how to join Revit data to an external Database.

The Database

I export my Revit model to a database called RevitSample. While it appears that I can add additional tables and Revit will not overwrite them, it is probably best to stay out of the tables in the Revit Database. To avoid corruption of my Revit DB, I will create another database called AdditionalData. I will also add a table called MoreData. Below is an image of the Databases and the Table.



I now have a table that has room numbers which coincide with the numbers in my Revit Rooms table. Any data in this table can be joined to the Revit table using number as the join field. to create the join, I add a new view and enter the sql shown in the image below.


MVC Application

The additional data has been added to the Revit View. I can now create an MVC application and load my view as the model. When I am done, I will have a table like the one in the image below.


While you can view this table, because there is no primary key in the view, you cannot edit. There appear to be workarounds, but while I can make the errors go away, the save function does not work. This is acceptable as editing should take place in the correct table, not a view.


why would you want to do this? I spent many hours typing data in to Revit because we needed it in a Report and we could get it from the schedule. Being able to join the data, I can load the outside data in to a table and join it. Then I can export it to my application and it is in a schedule or report. The Revit model remain untouched and my outside data can change and if it gets corrupted, my model is safe. As long as I do not need the data in Revit to generate plans, why not attach it later. I can still query it as if it is in the same table and generate all my reports and schedules. Revit doesn’t exactly create pretty schedules for reporting purposes, so why not use the Database to do it for you using something like Crystal Reports?


View and Edit Revit Models in a Website with No Coding

3 Feb
Front page of my application. Bottom left box has links for walls and rooms.

Front page of my application. Bottom left box has links for walls and rooms.

What if I told you that you can create a website that will allow you to see the data in your Revit model and also edit that data without writing a single line of code?  You can, and I am going to show you how.

The Technology

The application (web page) requires a good amount of code, but you do not need to write it. Using modern development tools, Visual Studio Express 2013 for the web, we can have the code generated for us. The technology behind this are MVC and Entity Framework. MVC is an acronym for Model – View – Controller. The Model is the data, the Revit DB in this case, the controller handles all the manipulation of data and the view is the webpage we will be looking at. Entity Framework is the object relational mapping piece of the project. It allows us to write code against an object instead of knowing what is in the Database. This is not that important for you to understand at this point, because we are not going to write any code. Just know that it sits between our Database and code and handles a lot of the dirty work.

Putting it Together

I am not going to explain all the steps in Visual Studio but will give a brief overview and show the completed application.

First, you must create your application and load the Revit DB with the tables you would like to use. Then, you create a scaffolding (the web pages) by selecting the model and controller that will handle the work. From there, you can edit the HTML to customize your application. The editing of the HTML is the closest thing to code you would need to do, but it can be as easy as editing a document. For my sample application, I loaded the Walls and Rooms tables.

When you click the link for Rooms, you see the entire table.


At the end of each row is and option to edit, delete or view details. If you select details, you will see the page in the image below.


You can edit from this page by selecting edit below.


Once you have made your edits, you can go back to the main page and see the changes.


All of these changes can now be brought back in to Revit using the DB Link addin.

I did not write a single line of code for this application to work. All the code for querying and editing the database was done by Visual Studio. I just needed to know how to put all the pieces of technology together and maybe edit the HTML to make the default template mine.


Making Money With BIM

29 Oct

Once in a while I will post something nontechnical- a rant if you will. Today is one of those in a whiles. My experience in architecture has led me to believe that architecture firms care only about construction drawings and the tools that are immediately required to produce said drawings. That is being a bit harsh, they might throw in a render here or there. Research and development are nonexistent as is exploring new technology. Maybe I should restate my previous claim that architects care only about CDs and say that: If it ain’t billable, it ain’t doable. Architects also seem interested in selling their design services only. The economic downturn should have taught them that they possess more than design skills and there is money to be made in other areas – but I fear it did not. Let’s explore making money with BIM in light of these observations about architecture firms.

BIM is expensive – if you buy Revit – and has a learning curve. Training doesn’t come cheap and lots of firms want to hire a BIM specialist to train everyone to keep costs down. This just results in slower learning and inefficiencies in projects. Firms tend not to give the model away and can’t command higher commissions because they use BIM. The client only wants the CDs anyway so why would they pay extra for anything else? If all this is true, how do we make money with BIM?

The usual way to justify BIM is that you will save money by decreasing the number of change orders or competing your project faster. This is the old sell my design skills thinking. Why not leverage the model to sell additional services on the back end.

Architectural data a a service.

The architect has a model that can be updated throughout the lifecycle of the building. Repairs and maintenance on the building can be updated in the model and given back to the client. The BIM can be sold as a subscription based software package for facility management through a web based front end. The client doesn’t need, nor do they often want, the BIM in some proprietary format like .RVT. They want a schedule and maybe an image showing where something is. This makes the task even easier. 90% of a clients needs will be updated properties of the building – not changes to the geometry. Simplifying the job even further. Data is valuable. Data is worth $$. The architect holds more data about a building than the owner. Multiplied by the number of buildings the firm has built.

Why let a client go when a building is done? Architects need to expand their services. Architects hold data that is vital in operating the building for decades to come. The data was created and paid for during the design of the building. Any money made off of it after design is profit. How easy with all the tools available today to stand out and find additional revenue streams based off work that is already being done. It could be something as simple as handing over an HTML version of an owners manual – not a pdf. Or if a pdf, at least embed hyperlinks or other interactive features.

The future of architecture is data. Those that have it and can use it will win. Design is important, and always will be, but the services you can provide above and beyond that is where value resides for you and the client.

This concludes my rant. It is lacking in detail but it is my preliminary thoughts on the issue. The ideas need to be flushed out and elaborated on but the meat is there.

What Should Revit Be?

2 Nov

I received a comment on my post “Report Revit Unconnected Wall Heights“:

LOL… as long as you don’t mind inaccurate results! If the wall in question has door/window openings then your wall area figure is not that of the entire length of the wall. Autodesk needs to address this now – it’s ridiculous that we even have to have these conversations….. just make the damn paramter accessible!

The comment is correct, of course if there is an opening the formula is off. But it’s algebra and I assume you know that. But, this post gets at an important question: what should Revit be?

I alluded to the answer in “BIM: Split vs Merged Models.” Revit should not be what I think this commenter wants it to be – all things. I hear this a lot – Revit should do this and why can’t it do that? Because, it cannot do everything. What it does is one thing really well – model. AutoDesk has included the tools in Revit for you to make it do anything you want – the Revit API. Can’t program in .NET? Then hire someone who can and build what you want. You need to learn to modify your tools. Look at Ghery, HOK and SHoP Architects, they do. Call Case Inc – they can build it for you. But if you expect an out-of-box application to provide every functionality that only you may want – you’re SOL.

I think Revit should stick to modeling. What I would like is for Revit to allow me to export my model to a database just by clicking R–>Export–>SQL Server. And bring it back – or at least join a DB to Revit. Then I can use the database to handle the data. And I can use Crystal Reports.

We can disagree on what Revit should be, but we should be able to agree that an architect must learn to modify his/her tools and to be able to create their own tools.  If you have a pen that only writes in green – replace the cartridge, don’t cry to the manufacturer to make it in red. Want to use “sf” in Revit schedules but hate that you can’t sum in excel because the field is now text? Write a formula like INT(=LEFT(A2, LEN(A2)-2) ) to strip it. Don’t cry to AutoDesk that when you export it doesn’t export as an integer.

Architects need to learn to use information – it is the I in BIM. To learn, you need to go outside of architecture to the land of information systems, computer programming, and statistics. – they exist but outside your site boundary line. It’s alright to cross it, I promise, it’s safe…

BIM: Split vs. Merged Models

1 Nov

As we move to BIM, architects need to acquire new skills, particularly in the area of information systems. In school, magazines, and competitions, images are what matter – design is king. Design will always be important, but we are in an information age of architecture. BIM, Energy Modeling, and Form Finding using Scripts are the new architecture. Databases have become a tool of the trade and I fear that architects are lacking in their knowledge of them – if you refer to an Excel spreadsheet as a database, you are lacking. I am not advocating that architects become programmers and information systems experts, but I am suggesting that without at least basic skills you will fall behind. AutoCAD has had a LISP environment since 1986 yet the majority of architects I know would tell you that LISP is a speech impediment. How little knowledge we have of our tools. It’s like using a pencil but ignoring the eraser on the end and starting over whenever you make a mistake.


My interest today and the reason for this post is to offer my two cents on the difference between split and merged models.


Simply put, a merged model is a model with geometry and data combined. This would be a Revit model where all the data about the objects – rooms, walls, doors – exist in the model. This is the model type that Revit leads you toward. And what happens when you embed large amounts of data in to Revit? Your file size becomes massive and performance takes a hit. For what? So that you can create a schedule later or to color code a floor plan? What if you need this data for something else? Are you going to export it to CSV every time you need it? What about a client? Are they going to need Revit to update the information about their building?


A split model, on the other hand, is where the geometry and the data are in different systems. The geometry is in your Revit model and the data is in a database – SQL Server or MySQL. A split model is superior to a merged model and this is what we should be aiming for.


There are certain pieces of data that will always be in Revit. The area of a room or a wall should be determined by the geometry, not entered in a database. But the overriding point is that the model should have the geometry and an ID for each object. That is all. You should have a database with tables for Walls and Rooms and these tables should have an ID and the rest of the data – use, type, department, fire rating, load bearing.


So how do we create schedules and create fancy color coded plans without the data? We use a JOIN and connect the tables of data to the geometry based on the ID.


The data about our building will change far more often than the building. Painting walls, replacing doors or carpeting can be updated in a database. The model only needs to be updated when something is added – an addition – or removed – demolition.


Another reason for split models is that we should keep our tools separate. Do you really need a 3D modeling application to also be a full blown database application? No. We only need the ability to connect them. Let Revit do what it does best – model.


Planners use split models in GIS, programmers use a Model-View-Controller framework and web developers have been working to remove the code and logic from the design of web pages for years. This is nothing new. Architects need to look at how other professions have solved this problem and learn from their best practices. I remember a quote from an officer in the Coast Guard that went something like this: “The data about our buildings is worth more than the buildings themselves.”

Shapefiles in Revit: Method II

25 Oct

Need to get shapefiles from your GIS in to Revit? I will tell you how using open source software. But first, Revit does not like coverages of over 20 miles so you may need to crop your shapefile.

Download Qgis – a free and open source GIS.

Open your shapefile in Qgis.

It will appear in the table of contents on the left. Right click on it and select ‘Save as..’ Choose AutoCAD DXF.

You now have a DXF of your shapefile.

Want to bring AutoCAD – or Revit – to GIS? Do everything in Reverse. But first activate your plugins.

Go to ‘Plugins’ and ‘Manage Plugins’. Check DXF2SHP.

Now click DXF2SHP and select your DXF. Choose a name and location to save your shapefile. Select the type. Probably polyline.

Here is a DXF loaded

Now your CAD drawing can be used in a GIS.