Just follow these steps:
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.
Now select your module (MyFirstMacro) and click on Create>Macro. Give it a name and a description (optional).
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.
No comments:
Post a comment