Thursday, July 15, 2010

Random Materials/Colors

This will be my first post and will show you how to use some random coloring in Revit.


It can actually be used for all sorts of elements and in this example I'll use a Column family. In order to use this technique you'll need the Revit 2011 DB Link extension which can be downloaded from Subscription Center.


Below I've created a Grid and placed a total of 84 (7x12) Columns:


In the Column family I added  a shared parameter called MaterialColor as instance parameter. For this color randomizing to work you need to use an instance parameter. The shared parameter is also needed to be able to export to an Access Database through RDB Link.


Shared Parameter MaterialColor:


Then I used the same basic Paint 1 material for them all:


Now comes an important part because you need to define the range of different materials/colors in one go from beginning to end. This is because we'll use a certain range later in Access to randomly generate materials for each Column.


So I created a range of 9 different materials, Paint 1 to 9, with different colors:


Now comes the part when we'll use RBD Link to export the objects from the Revit file to a Microsoft Access mdb file. After installing you can find RDB Link in Revit under Add-Ins from the Revit ribbon:

I exported the Revit elements through the MS Access tab in RDB Link:

Then we will open up the exported Dbase and preview the exported data. I'm using MS Access 2007 in this example. When you open up the .mdb file it shows you a lot of tables and mostly these come in paires of two. The first provides information from all visible elements in Revit where the second table provides information about the different family types.

Let's check out the contents of the Colums table:

It provides information about each Column. Every single Column receives an unique ID in this table which we'll need later. The interesting part in this tabel is that every Column also has the shared parameter MaterialColor attached:


We only see numbers in the column MaterialColor and it's the same for every Column object which is true because each Column in Revit has the same Paint 1 material attached. So we know that Paint 1 is actually 149427 in this table.

Then we'll investigate another tabel, called Materials:

After some filtering in this table we see each Named material and it's Id. Here we also notice that the Paint 1 material has the Id number 149427. We also have a clue now about the range of Id's from the Paint 1 to Paint 9 material in Revit. It is the range from 149427 to 149435. This information is important to be able to randomly generate the material colors later in this example.

Now we'll use the possibilities in Access to randomly update all -MaterialColor- entries in the Column table. This part is the interesting part because it opens up a whole new world of possibilities to drive Revit parameters with a certain randomness.

In order to do this we need an update Query in Access:

We need to update the Column table so we include that table:

And for the interesting part we'll use the following Update Query in the -Update To- field:

"149427"+(Int(9*Rnd([Id])))

What this does is actually start with the lowest Paint 1 material in the total range and then add a random integer based on a series of 9. The Rnd([Id]) function took me some time to figure out because when you only use Rnd() in Access you get a random number but this is added for every record. When you add the [Id] argument you'll end up with a different random integer every time you run this Query.


So let's run this Query now:

This will give us the following results in the MaterialColor column:



So, as you can see the Update Query has updated several entries in the MaterialColor column. Not all have been changed because the original material (149427) was also part of the total range of 9 materials and it was also generated randomly.

I guess, you want to see this now in Revit...let's import these changes back into Revit through RDB Link. You can select the same connection and press -Edit and Import-:

You see an import dialog from RDB Link and can view every Table apart before import, you can even change the values if needed here. But when we take a look in the Column table we can clearly see that all values have been changed like we saw in Access. So we hit the -OK- button and voila, here it is:


RDB Link also generates an html report for you to review when finished. In this report it provides info about the changed records and possible faults that were not updated to Revit or cannot be used to update:

Now let's hit the Update Query a couple of times more and check out the results in Revit:


I hope this post opened up your imagination and you can start to use the Random Touch in Revit!

No comments:

Post a Comment