CLI open a revit project

Hi all,

May I ask you is it possible to open a revit file project using CLI?
If not possible what are the costrain?

I have searched in the forum of this topic have been faced but i am not sure.

Have a look:

    pyrevit run (-h | --help)
    pyrevit run commands
    pyrevit run <script_or_command_name> [--revit=<revit_year>] [--purge] [--allowdialogs] [--import=<import_path>]
    pyrevit run <script_or_command_name> --models=<model_list_file> --revit=<revit_year> [--purge] [--allowdialogs] [--import=<import_path>]
    pyrevit run <script_or_command_name> <model_file> [--revit=<revit_year>] [--purge] [--allowdialogs] [--import=<import_path>]

    Arguments & Options:
        <script_or_command_name> Target script path or run command name
        --revit=<revit_year>     Target Revit year e.g. 2019
        <model_file>             Target Revit model file path
        --purge                  Remove temporary run environment after completion
        --import=<import_path>   Copy content of this folder into the runtime temp path.
        --allowdialogs           To allow dialogs during journal playback

simple proof of concept, I ran it on a single file

here is the code to count stuffs and write it to a csv then open it

from pyrevit import revit, DB, forms, HOST_APP
import os
import csv

uidoc = HOST_APP.uiapp.OpenAndActivateDocument(__models__[0])
doc = uidoc.Document

wall_count = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_Walls).WhereElementIsNotElementType().GetElementCount()

# export wall count to csv in same folder
csv_path = os.path.join(os.path.dirname(__file__), 'wall_count.csv')
with open(csv_path, 'w') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['wall_count', wall_count])
    print('Wall count written to csv: {}'.format(csv_path))
    # open the csv file

don’t try and use the revit UI or forms, or any kind of taskdialog unless you allow them in the CLI command

pyrevit run "C:\" "H:\whateverFileName.rvt"

1 Like

thank you :slight_smile:

this answer can be really helpful to think further and what can be done with the CLI.
thank you for being forward-looking

1 Like