How to Use PyRevit CLI to Run Python Scripts Without Opening Revit?

I’m currently working on automating some tasks using PyRevit CLI and the Revit API. My goal is to run Python scripts without actually opening the Revit GUI. Specifically, I’ve written a simple script to open an IFC file and save it as an RVT file. Here’s the script:

import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')

from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *

app = __revit__.Application

ifc_doc = app.OpenIFCDocument('Room.ifc')
print("Open")
save_options = SaveAsOptions()
save_options.OverwriteExistingFile = True

ifc_doc.SaveAs('output_room.rvt', save_options)
print("Saved")

When I run this script with the command pyrevit run script.py "revitproject.rvt", Revit opens and closes again, displaying information about the execution ID, product, clone, engine, script, working directory, journal file, manifest file, and log file.

I’m looking for guidance on how to correctly use the PyRevit CLI to achieve my goal without the Revit GUI popping up. Are there any specific resources, documentation, or tutorials that could help with this?

@iminna this should help you

another possible solution is the revit batch automation tool

You mean without Revit opening at all? As far as I know you will always have the Revit window open unless you are using one of the APIs for cloud hosted models like Forge and whatever they calling the other ones now.

pyRevit will not be of any use for this.

Hi @Jean-Marc, I have a question. For example I have a script to set parameter values for some elements. If I use this way to run it, will the revit model be saved after running?

by default, no, you need to tell it to save the file
the CLI run command is a glorified revit journal execution.
It does what you tell it to do

1 Like

So do you have any ideas to save the model without openning it?

Without opening revit, design automation API on APS with cloud model is the only way that I know of.

1 Like

Thank you for your infomation.

1 Like