Skip to content
Jan Christel edited this page Jul 21, 2021 · 28 revisions

Welcome to the SampleCodeRevitBatchProcessor wiki!

Code sample provided in this repository fall into one of two categories:

  • Reading and exporting model data without affecting the actual Revit model (script file name starts with: 'Report')
  • Modifying the Revit model (script file name starts with 'Modify')

All python sample scripts can be used with either the GUI version of the batch processor (BatchRvtGUI.exe) or the command line (BatchRvt.exe) version.

Repository Structure

Python files starting with:

  • Pre_ are scripts executed as the pre processing step
  • Post_ are scripts executed as the post processing step

Pre and Post processing are available in the User Interface once Show Advanced Options is checked.

Batch files

Batch scripts located in the /BAT directory assume that the command line version of the batch processor is used. These scripts demonstrate how to:

  • Run multiple sessions of the batch processor in parallel running the same task script on a number of files: modify parallel simple

Used cases: Simple tasks, which do not require any post processing, applied to a bigger number of files needs to be sped up. The sample shows how to start 2 processes but it could be any number of sessions your hardware (RAM) supports. Note the few second wait in between batch processor instances being started: this allows for separate log files per instance.

Use cases: in scenarios where multiple steps need to be applied to Revit files which cannot be done in one step. i.e. Step 1) A revision is created and added to a splash screen (executed in parallel running sessions in batch processor to speed things up), followed by step 2, which only starts when step 1 for all parallel running instances of batch processor is completed. Step 2 may for instance detach same models and prepare them for distribution. After all instances of the batch processor have completed step 2, a post process is started. This is done outside the batch processor interface since it can not be guaranteed which instance of the batch processor finishes last and is therefore the one which could be running the post process.

Use cases: in scenarios where a pre process requires a separate user interface to allow for input (i.e. a file selection) followed by multiple steps needing to be applied to Revit files which cannot be done in one step. This is than followed by a post process script executed after all parallel running task processes are finished.


Batch files and Revit Worksharing Monitor glitch

I noticed the other day that, in some cases, the Revit Worksharing Monitor is locking one of the temp lock files the batch scripts create to check whether a process is still running or not. This seems to happen in situations where an instance of Worksharing Monitor is automatically started together with Revit through Batch Processor. While Revit Batch Processor kills the actual Revit session it started, it will not kill Revit Worksharing Monitor which, in turn, maintains the lock and the batch file will not proceed at this point.

Workarounds:

  • Manually close any Worksharing Monitor session popping up at the beginning of a batch run (not great)
  • Close all Worksharing Monitor sessions once the batch script appears to have locked up. It will keep on going once the offending Worksharing Monitor session is closed. (not much better)
  • Disable Worksharing Monitor at Revit start up
  • Use WorksharingMonitorProcess library to kill any running Worksharing monitor sessions

UI Samples

These scripts located in the /UI folder show, as a sample, a task file selection user interface which currently needs to be run as a separate pre process outside of batch processor.

Batch file sample is provided above.

Typical Task Script Structure

Typically the sample scripts provided here follow this structure:

  • GPL License block
  • Short description of what the script does
  • import statements block
  • debug flag: I use the Revit Python Shell to debug scripts. Since the modules associated with the batch processor are not available in my version of that environment I needed a way to disable import statements associated with the Revit batch processor.
# flag whether this runs in debug or not
debug_ = False
  • Path and import of libraries these sample scripts rely on. In the moment I have multiple copies of these scripts and their libraries scattered around multiple project location. Not ideal, but it allows for customisation and tinkering without introducing breaking changes to all project versions.
# path to library modules
commonLibraryLocation_ = r'C:\temp'
# path to directory containing this script (in case there are any other modules to be loaded from here)
scriptLocation_ = r'C:\temp'

# set path to library and this script
import sys
sys.path += [commonLibraryLocation_, scriptLocation_]

#import common libraries
import RevitCommonAPI as com
  • Another import block (could probably be moved to the top one)
  • Output method (My Python knowledge is not that advanced and I struggled to move this code into a separate library without creating dependency problems)
  • My code section: contains utility methods specific to this task script.
# -------------
# my code here:
# -------------
  • Main section: Usually entry point or method of script.
# -------------
# main:
# -------------

Libraries

The sample scripts provided make use of some utility libraries. A list of currently used libraries and their content is below:

Name Content
BatchProcessorLogUtils Utility functions to process logs created by batch processor and check for any exceptions
RevitCommonAPI Utility functions covering: transactions, element worksets and deletion, Revit file Syncing, saving
Revit...Someting Utility functions relating to the element category in the module name
SolibriIFCOptimizer Utilities to run Solibri IFC optimizer
SystemProcess Utilities around system processes
Result Class storing the outcome of a method as true or false, any user readable message to go with it and any object needing returning
Utility Utility functions covering: general file modifications (copy, delete, rename), date stamps, combine text files
WorksharingMonitorProcess Utility functions to kill work sharing monitor application
timer a timer class
Clone this wiki locally