Is it possible to open a revit model via Rhino Inside?

Hi !
I am curious if it’s possible to open a revit model from scratch via Rhino Inside, Suppose that a revit app is running.
This way one could automate some tasks.

The following code does something like that(?). I am flexing my Python skills with Revit API, excuse me if there is a mistake.

__author__ = "mbgoker"
__version__ = "2021.09.09"

import clr


import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
from RhinoInside.Revit import Revit, Convert
# add extensions methods as well
# this allows calling .ToXXX() convertor methods on Revit objects
from Autodesk.Revit import DB
from Autodesk.Revit import ApplicationServices

# access the active document object
doc = Revit.ActiveDBDocument
app = Revit.ActiveDBApplication
# a few utility methods
def show_warning(msg):
    ghenv.Component.AddRuntimeMessage(RML.Warning, msg)

def show_error(msg):
    ghenv.Component.AddRuntimeMessage(RML.Error, msg)

def show_remark(msg):
    ghenv.Component.AddRuntimeMessage(RML.Remark, msg)

#This is for converting single items to list so we can loop through it.
FilePath = FilePath if isinstance(FilePath, list) else [FilePath]

Document = []

OpenOptions = DB.OpenOptions()

if FilePath:
    for file in FilePath:
        ModelPath = DB.ModelPathUtils.ConvertUserVisiblePathToModelPath(file)
        document = ApplicationServices.Application.OpenDocumentFile(app, ModelPath, OpenOptions)
        Document.append(document) (8.2 KB)

1 Like

There are a lot of variables (version, central…) that go into opening a revit file. The best resource for this at the moment is pyRevit CLI.

“Opening a model is a complex process and has many configurations e.g. Opening central or detached, Workset configurations, etc. The run command uses a simple journal file to bootstrap Revit and avoids using complex journal structures to provide configurations on opening models since journals are heavily GUI based and could easily break in the future. Revit API provides ample functionality on opening models. It’s best practice to open the model inside your script.”

This is correct. The code that I shared opens local (I think) files in the background and returns the document.

Thank you !
I started an emoty revit, started RIR , ran your GH , got no error but I can’t see that the revit model is actually open . From the node output I get : Autodesk.Revit.DB.Document.

I don’t know whether if you can actually open files from API. (need an expert in here :sos:) what I shared opens it in the background so you can connect it to the Document input of nodes.

Ok , so in the background means may be that Rhino inside can’t see it right?

It can see. You can query elements, do whatever you want but it is not visible in the Revit UI.

I work on a pretty big and complex project with around 20 revit files. I need to extract and write matching data to all the files. Opening all of them takes ages. For the test, I opened 14 Revit files in 50 seconds using script from this post. Thank you! @mucahitbgoker

Now to my question. Do you plan implementing something similar which would allow me to open central models, make changes inside of them and synchronize the files?

There are a lot of considerations so i’m not sure what that would look like, but I’ve added the feature request referencing this post.

1 Like

Do you, or somebody else, by any chance have a script that would also close files? I need to stroll through many models to export some data and your file-opening script makes it easier. However, I need to close them also because I quickly clog the Revit with all those models opened in the background.