Wednesday, 23 December 2020

How to save custom colours in Revit

In this tutorial, I will show you how to save custom colour swatches in Revit so you can use them later.


Probably you are familiar with the Revit colour picker in the image above. The problem with this tool is that if you want to save a colour, you have to first select an empty square in the Custom Colors area, pick your colour on the colour picker and then click add. However, with this procedure, if you forget to click on an empty square first you will lose your colour when you click to try to save it as the colour will be reset to white.

The following trick will allow you to save colours even without selecting a square first. Note that in the image above, one of the squares has a frame around it. The trick is to move the selection frame with the keyboard instead of the mouse. Follow these steps:

  1. Select the colour that you want in the colour picker.
  2. Press the TAB key to move the selection frame to the Custom Colors area.
  3. Select the custom square where you want to save your colour using the keyboard arrow keys.
  4. Click on the Add button with your mouse.

And that's it! the saved colours will be available in every colour selector in Revit.  

For clarity, check the video below:

Sunday, 13 December 2020

How to create a macro in Revit

  In this post, I will create a simple "Hello World" message just to demonstrate how to create and run macros in Revit.

Just follow these steps:

1- Open the Macro manager (Manage > Macro Manager)
2- Create a new Module:

  Modules are just a way of grouping macros. For example, in the image below I have a category with various tools, another one for tests and another one with tools for cleaning views.

There are two kinds of modules: project modules and application modules. The project modules are saved directly into the active document and will be available for all the team working in the model. However, it won't be available for other projects. The application modules will be only available for you but you will be able to use it in any project. My personal preference is to use application modules so I can reuse easily my macros. 

For this example, click on the Application tab and then on Create > Module. Give it a name, select C# and write a description (optional). Click OK and close the macro editor that will appear on the screen.

 3- Create a new macro:

  Now select your module (MyFirstMacro) and click on Create>Macro. Give it a name and a description (optional).

When you click OK, the macro editor will appear again with some code. But we are only interested in the part shown in the image below. Our code goes between the two curly brackets.
4-Write the code:
 Now write the following code between the curly brackets (I recommend that you write it instead of copy/paste):
TaskDialog.Show("My fisrt macro","Hello world!");
 Then just press the key F8 on your keyboard to build the macro.

5- Run the macro:
Select your macro in the macro manager and just click run.
 A message like in the image below should pop up:


Explanation of the code:

 The code in this tutorial is very simple but I will explain each part.


1-  public void HelloWorld(){}

This is how you define a method in C#. In this case, the method is the macro itself. A method in C# is a block of code that performs an action/s. The words "public" and "void" are properties of the method which I will explain in another post. The code of the method must go between the curly brackets.

2- TaskDialog

TaskDialog is a class of the Revit API. For the moment you can think of a class as a group of methods and properties. The TaskDialog class is used to create messages and dialogues for the user.

3- .Show("text 1","text 2")

"Show" is a method. The dot indicates that it belongs to the TaskDialog class. This method makes the dialog visible to the user. The first text in the brackets is the title of the dialog and the second one is the message itself. 

In future posts, I will explain how to create more complex macros.