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 clr.AddReference('RhinoInside.Revit') clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') 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 clr.ImportExtensions(Convert.Geometry) 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)
OpenDocument.gh (8.2 KB)
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 ) 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.