Adding, Changing, Saving Documents/UIDocuments


I have recently started using Dynamo and am very excited by this feature but have been developing in the Revit .NET environment for several years. I am trying to accomplish infrastructure tasks within Revit (similar to BIM 42 - Bridge Design) by reading rows from an Excel workbook, where each row will need to run a Dynamo script to produce the relevant infrastructure asset based on the contents of the cells within that row. In short, each Excel row needs to produce a separate Revit project document.

To my knowledge on Dynamo (limited at this stage), it appears that Dynamo sits within a project document and despite python API calls to using the reference “RevitServices”, this cannot use the “Document.Add” or “UIApplication.OpenAndActivateDocument” calls available with the .NET environment.

Can I create new documents from with Dynamo? Can I run Dynamo scripts using the .NET? Do you have any links that are also trying to achieve this?

Any help will be greatly appreciated, regards, Tom.

Subject: Regarding [CaseNo:12633500.] Dynamo - New Document
Date: 10:08, 6th Feb 2017
From: ADN Support

Dear Tom,

Thank you for your query.

Congratulations on getting started with Dynamo. I am glad to hear you are so excited by it.

I am pretty sure that Dynamo is not tied to any specific document. It may have a predefined hook to provide direct access and interact more easily with the current document, but
Jeremy Tammik
it also has full access to the entire Revit .NET API and can thus also create new documents, just as you can from any other Revit .NET add-in.

Nope, I do not have any samples at hand that do this myself.

I would suggest that you discuss all Dynamo issues directly with the Dynamo experts in the Dynamo forum:

I hope this helps.

All Dynamo related queries should be directed there.

Furthermore, the preferred method nowadays to submit non-confidential ADN queries or requests on the standard (non-Dynamo) Revit API is via the Revit API discussion forum:

Any thread that you submit there using your email address registered as an ADN member will be recognised as such and automatically escalated to us in the ADN team.

At the same time, you will address a larger audience, more of your peers will see it, be able to chip in and help, and more people will see and be able to profit from the answers we provide.

We therefore prioritise cases from the discussion forum.

Please submit all your non-confidential non-Dynamo Revit API queries via the Revit API discussion forum.

Thank you for your understanding and cooperation.

Best regards,
​​​​​​​Jeremy Tammik.

Developer Technical Services


Now that you are here. Please post screenshots, code samples or revit/dynamo samples so that we can better see where you are at with your task and thus be able to help. Also, this is a community forum, and unfortunately your ADN status doesn’t mean much around here. With that said, I am sure that if you present an interesting issue in a clear and concise way, people here will be glad to help.



Currently (Feb 2017) this example is the only document level control available in the API. As a result I submitted an idea to the Revit Forum. Below is a typical example of changing between documents within Revit via the C#.Net environment.

public class ExtCmd1 : IExternalCommand
    private static ExternalCommandData _cachedCmdData;
    public static UIApplication CachedUiApp
            return _cachedCmdData.Application;

    #region IExternalCommand Members        
    public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
        _cachedCmdData = cmdData;
            //TODO: add your code below.

            return Result.Succeeded;
        catch (Exception ex)
            msg = ex.ToString();
            return Result.Failed;

Well in short you are looking at a workflow that does this:

  • Read Row of data from Excel File.
  • For each row, collect data from it, and use it to spawn a new Revit model.
  • Use that data to make changes to the Revit model.
  • Save the model on drive.
  • Move to next row.

Which step do you need help with?

Ps. What I would do is create an empty Revit file and open that, make changes, and then SAVE AS for every new Excel row. That way, you can create as many new files, as you want even though there might not be an API for creating new Revit Document from scratch.

If you prefer to use a template file, you could always use the below method:

1 Like