Tag Archives: Revit API

Use Dynamo to Transfer Phase Data to Bound Revit Models

This workflow was created as a request from @PhilosophyBIM on Twitter

The issue arises when binding a linked model in Revit. If you’ve ever had the task of binding a linked model that contains crucial Phase data,  you’ve run into the issue where the Phase data is lost regardless of whether the phase exists in the destination model or not. I hope this helps eliminate some tedious work for some Revit users out there!

In a nutshell, this process temporarily stores the phase data (e.g., “Existing” and “New Construction”) in Project Parameters. Once those values are stored, a second graph sets the Revit Phase data based on those parameter values.

Note that this was tested on a simple project with only two phases. Please experiment on a detached model when trying out this workflow.

Download the Dyn’s:

Dynamo - Transfer Revit Phases to Bound Model (80 downloads)

The Workflow

1. In your source model (the model to be bound), create three project parameters.

Use Project Parameters to transfer Revit phase data to bound linked Revit models

These parameters are used to temporarily store the data from Revit’s built-in Phase parameters. The third parameter is an added bonus of storing Element ID’s for simplified quality control.

  1. SourcePhaseCreated
  2. SourcePhaseDemolished
  3. SourceElementId (this is used for QC if so desired)

Use your judgement on which categories to apply the parameters to, but for the sake of simplicity, I would recommend to apply these project parameters to all categories.

2. Create a 3D View that hides all annotations.

You’ll want to make sure that all model elements are visible, because the Dynamo graph collects elements to apply the Parameter values based on what is visible in the active view.

3. Run “Store Element Id and Phase Parameters.dyn”.

Set Parameter values for mapping Revit Phases from linked model after binding

This graph does the work of taking the Phase data from Revit’s built-in parameters and storing their names in the parameters that were created in step one.

While doing some testing, I noticed that Dynamo throws an error because there are certain model elements that cannot be assigned a project parameter. As far as I could tell, this didn’t cause an issue with mapping the Phases to the Parameter values, but please let me know if you find otherwise while using these graphs.

Note that if you would like to double check that the parameters were correctly populated, I recommend to build schedules with the Phases and Parameter values and either run a quick scroll to visually check or run some conditional formatting for larger models.

4. Link the source model into your destination model, bind it, and ungroup the bound elements.

After the model is bound,  note that the Project Parameters created in step one and the values populated from step two have been brought into your destination project.

We aren’t done yet, notice that the Project Parameter values do not match the Phase parameter values.

Parameters used to store Phase data from after linked model bind

5. Finally, run “Set Phase from Phase Parameters.dyn”.

Set Revit Phase after binding linked model from Parameter Value

This graph sets your elements to the proper Phases based on the parameter values populated in step three.

Take some time to look at this graph before you run it, especially if you have more complex phasing in your project. I’ve grouped each set of nodes so that in the instance that you have several Phases, it should be easy to figure out how to duplicate the groups and create a group for as many phases as your project contains.

Download the Dyn’s:

Dynamo - Transfer Revit Phases to Bound Model (80 downloads)

Hope this helps!

Please let me know if this graph does or doesn’t work for you. All feedback is appreciated!

 

Hello Dynamo World!

In learning every new programming language, it is customary to start with a “Hello world!” application. Although visual, Dynamo is a scripting tool as well, so I thought this would be a great first step for folks who are new to Dynamo.

In this post, we demonstrate how to display “Hello world!”  in the Revit application in two ways:

  1. Displaying a TaskDialog in Revit using a combination of Dynamo and Python.
  2. Adding a TextNote to a view using only out-of-the-box (OOTB) nodes.

Hello World Using Dynamo and Python

Hello world Dynamo graph

The image above shows the completed graph (download below). Most of the work is done within the Python script which uses two inputs as variables.

Insert a Python Script node.

Once the node is placed in your graph, you will need to click the “+” button to add an additional input.

Python script node in Dynamo to show a task dialog in Revit.

After adding the second input, you should see IN[1] as shown below.

Python script in Dynamo to show a task dialog in Revit.

Add strings to your input.

For this example, I’ve shown two different nodes that you can use to output strings in Dynamo. The String node outputs a string from the value that you insert into the node (Hello). The Code Block node must include double quotes and a semicolon to output a string (“Hello world!”;).

In computer programming, a string data type is a set of characters. This can be in the form of a sentence or a file path, and can contain special characters and/or spaces. Strings are typically enclosed using double quotes.

Connect the nodes to the inputs as shown below.

Hello world Dynamo graph

Insert code to the Python Script node.

To open the code editor in Dynamo, double-click on the blank area of the node as highlighted below.

Edit a python script in Dynamo

Insert the code below to the code editor. Note that we are including the Autodesk.Revit.UI namespace in order to use the TaskDialog.Show() method from the Revit API.

I highly recommend that you type this code in rather than copy/pasting. It will help you start to understand Python’s syntax.

import clr
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import TaskDialog

windowTitle = IN[0]
windowMessage = IN[1]

messageDialog = TaskDialog
OUT = messageDialog.Show(windowTitle, windowMessage)

If your Dyn is set to run automatically (it is by default)  you should immediately see the dialog box pop up in Revit. If set to manual, click the Run button in the bottom left of Dynamo to run the script.

Here is a link to the Dynamo graph used in this example:
HelloWorld.dyn (83 downloads)

Hello World with OOTB Nodes

Dynamo BIM - Hello World in Revit

The image above is the completed graph (download below) and will create a TextNote in the Revit view of your choice.

1) TextNote.ByLocation
This node does all of the work. It will place a text element in the view that you choose. The node has several inputs, but for this example we will only use the first four inputs.

2) Views
A node that provides a drop down menu of all of the views in your project. Choose a floor plan view in your active model as you follow this example.

3) Point.ByCoordinates
This node outputs a Point based the x, y, z inputs. For this example, I’ve shown three different nodes that you can use to generate number values: 4) Number , 5) Code Block, and 6)Number Slider

7) String
The value in the String node goes into the “text” input for the content of the text note element in the Revit view.

8) String
The value in this String node goes into the “alignment input”

Here is a link to the Dynamo graph used in this example:
Hello World - Text (103 downloads)

Questions? Post your comments below!

Seattle Dynamo User Group

Rather than hosting a Dynamo training session in the greater Seattle area, we decided to organize and sponsor the Seattle Dynamo User Group Meetup! The meetup group was only formed on February 1, 2017 and we already have 17 members.

We will schedule the first meetup as soon as we have speaker and a venue in place. We are currently searching for both, so please let us know if you can help us find either of the two.

We are extremely excited to lead this community! Here’s to sharing, learning, and networking with other Dynamo users in Seattle.

Seattle Dynamo User Group

Seattle, WA
20 Members

Are you interested in using Dynamo to streamline workflows, build complex geometry, or harness BIM data? Join us to learn and share experiences about this exciting new visual …

Check out this Meetup Group →

 

[Solved] Revit can’t create a new module in the macro manager

This morning, I ran into an interesting bug in Revit 2016. I opened up my Macro Manager per the norm, but when attempting to create a new module Revit wouldn’t save the new module. It successfully opened the dialog box to let me choose a name, language, and description, however once I clicked “OK” nothing happened. Sharp Develop did not open nor did the new module appear in the Macro Manager window.

I found the suggested fix on Revitforum.org, however it did not work for me. Perhaps because this post was for an earlier version of Revit.

Here’s actually what ended up working for me:

  1. Close all Revit instances.
  2. Navigate to your Macros folder on your C drive:
    C:\ProgramData\Autodesk\Revit\Macros
  3. You may see multiple years in this folder, one per Revit version installed on your computer (e.g., 2014, 2015, 2016, 2017). Move the year of Revit that you are working in to a temporary folder like your desktop.
  4. Restart Revit.
  5. Go to your Macro Manager and create a new module.

By creating a new module, Revit recreates this directory and is able to successfully create a new module for your use.

IronPython UI Generator and Script Library for Autodesk Revit

I just stumbled on this script library for Revit users who wish to use Python with the Revit API. In it’s simplest form, it’s a folder of IronPython .py scripts for Autodesk Revit.

Check it out on GitHub: https://github.com/eirannejad/pyRevit

There is plenty of example code written in Python that you can refer to when learning to create macros or add-ins for Revit.

To use Python with Revit, you will need to install a few things:

I don’t want to get into too much detail on how to use Python with Revit in this post, but if you need help getting started, there is a very helpful guide on Productspec.

  1. Iron Python: http://ironpython.net/download/
  2. RevitPythonShell: https://code.google.com/p/revitpythonshell/
  3. Revit Software Development Kit: http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=2484975

Copy a Legend to Multiple Sheets in Revit

The good folks over at Boost Your BIM have posted a macro for copying a legend to multiple sheets. It works really well, but I wonder if anyone would like to take on the challenge of doing something similar in Dynamo.

public void legendOnSheets()
{
    Document doc = this.ActiveUIDocument.Document;
    
    // create list of element ids for the sheets that will get the legends
    List<ElementId> sheetIds = new List<ElementId>();
        
    // use SheetNumber to find the desired sheets
    // add each sheet to the list of sheet ids
    sheetIds.Add(new FilteredElementCollector(doc)
        .OfClass(typeof(ViewSheet))
        .Cast<ViewSheet>()
        .FirstOrDefault(q => q.SheetNumber == "A101").Id);
    sheetIds.Add(new FilteredElementCollector(doc)
        .OfClass(typeof(ViewSheet))
        .Cast<ViewSheet>()
        .FirstOrDefault(q => q.SheetNumber == "A102").Id);                
    sheetIds.Add(new FilteredElementCollector(doc)
        .OfClass(typeof(ViewSheet))
        .Cast<ViewSheet>()
        .FirstOrDefault(q => q.SheetNumber == "A103").Id);    
    
    // find the legend to put on the sheets
    // use ViewType.Legend and the view name to find the legend view
    Element legend = new FilteredElementCollector(doc)
        .OfClass(typeof(View))
        .Cast<View>()
        .FirstOrDefault(q => q.ViewType == ViewType.Legend && q.Name == "Legend 1");
    
    // create a transaction so that the document can be modified
    using (Transaction t = new Transaction(doc, "Legends on Sheets"))
    {
        // start the transaction
        t.Start();
        
        // loop through the list of sheet ids
        foreach (ElementId sheetid in sheetIds)
        {
            // create a new viewport for the legend on each sheet
            // place the legend view at the 0,0,0 location on each sheet
            // user will need to move the legend to the desired location
            Viewport.Create(doc, sheetid, legend.Id, new XYZ(0,0,0));
        }
        
        // commit the changes
        t.Commit();
    }
}

Revit Macro – List electrical panel schedules and the sheets that they are placed on

Revit Macro Programming in C# and Python. Create your own Revit add-in or macros.

We found a quick-and-dirty way to show what sheets your electrical panel schedules are on. Essentially, it is a schedule of schedules. We haven’t found any other way to accomplish this as of yet and we welcome any improvements to this code.

What this does is simply create a dialog box with all of your electrical panel schedules in your model and what sheets they are on. With the box open do a ctrl-c (copy to clipboard) and then paste into excel. Not very elegant but gets the job done.

For all you advanced coders out there, we could use some help in getting this to become a more elegant solution!

To create a Revit macro:

  1. Open up the macro manager and create a new C# module – name it whatever you want.
  2. With the module that you have just created selected, click the Macro button and name your macro “SchedulingSchedules”.
  3. Revit will then open “SharpDevelop”, an IDE for coding Revit macros. Look for the code block that SharpDevelop generated:
    public void SchedulingSchedules()
         {
         }
    

    and paste the code below in between the curly braces { }.

  4. Then you need to add “using System.Text;” at the top with the other using statements.
  5. Click ‘Build’ menu and then ‘Build Solution (F8)’.
  6. Switch back to Revit and you will see the “SchedulingSchedules” macro. Select the macro and click the Run button.

Code:

public void SchedulingSchedules()
         {
             UIApplication uiApp = this.Application;    
             Application app = uiApp.Application;
             UIDocument uiDoc = uiApp.ActiveUIDocument; 
             Document Doc = uiDoc.Document;
             
             StringBuilder sb = new StringBuilder(); 
             
             ElementCategoryFilter sheetcf = new ElementCategoryFilter(BuiltInCategory.OST_Sheets);
             FilteredElementCollector sheetCollector = new FilteredElementCollector(Doc); 
             IList<Element> sheetlist = sheetCollector.WherePasses(sheetcf).WhereElementIsNotElementType().ToElements(); 
         
             foreach(Element sheet in sheetlist) { 
                 ElementCategoryFilter panelcf = new ElementCategoryFilter(BuiltInCategory.OST_PanelScheduleGraphics); 
                 FilteredElementCollector panelCollector = new FilteredElementCollector(Doc, sheet.Id); 
                 IList<Element> panellist = panelCollector.WherePasses(panelcf).WhereElementIsNotElementType().ToElements(); 
                 foreach(Element panel in panellist) { 
                     sb.AppendLine(panel.Name+" \t"+sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString()); 
                 } 
             }
         
             TaskDialog.Show("Revit", sb.ToString()); 
         } 

ArchSmarter Toolbox – Free Macros for Revit to Maximize Efficiency

 

We recently stumbled onto a set of Revit macros that may be of use to all Revit users regardless of skill level. The good folks at ArchSmarter have a toolbox of Revit macros that maximize efficiency on mundane tasks such as duplicating views, aligning views on sheets, and batch linking Revit models. The best part about these macros is that they’re free – all you need to do is register on the ArchSmarter website.

We are currently working on trying these tools out, but we urge you to try them on your end and give us feedback on your experiences. We will updated this article as our experience with these Revit Macros progress.

Below is a list of the macros included in the ArchSmarter Toolbox for Revit

Join ArchSmarter to download the toolbox.