Hello World From Revit

Fausto Mendez

Architecture and Engineering, All, API, Revit, Tutorial, C#, Construction, Macros 0 Comment

So what better way to start my first blog post than with the classic “Hello Word”.  Well not really the normal Hello World as the one on the Walkthrough: Hello World 

but a little more exciting one that introduces some cool challenges like the one in the picture below.

In today’s post I’m going to cover two very important and useful codes. The  1st one is how to get the XYZ insertion point of a Revit family instance , and the 2nd one is how to place a family instance in a specific XYZ coordinate.

For my set up I’m going to be using the Revit macro manager  (Sharp Develop Software) for beginners. Here is an easy tutorial to get you started with Revit macros .

To get the XYZ insertion point of a Revit family instance we will need to  be able to select a family instance first. Using the following code example will allow you not only to select a single family instance, but multiple family instances  along with  pre-selected objects in to a list.

Now we need to create a list that will store our XYZ coordinates.

Next add the actual code that gets the location point of a family instance and adds them into the list.

Finally lets add a dialog to show us if the code is working correctly.

Now lets combine those codes…

When you compile the code (F8) and Run it on a selected family instance it will show a dialog like this one.

Now that we know how to get those location points, we will need to start a Revit transaction to modify the Revit document.

Between the tx.start() and the tx.commit() we need to add the “create new instance code”. This code requires the Location Point, Family Symbol and the current view.

Finally here is the complete example code for placing a family symbol in an specific XYZ coordinate.

Now it’s time to be creative,  and read those XYZ from an External CSV file —> HelloWorld.csv!

The result output will be something like the picture below. Try changing the family symbol and the XYZ values to change the appearance.

Here is the Complete source code and csv file for this example.Web Hello world Example and a link to my website.