Pyrevit run - journal file could not be run to completion

Hello,

I have a script that runs every night using windows scheduler. Whenever I check in the morning below error appears. A few models have been processed tho.
After closing Revit, and manually opening the model, it opens without issues.

Here is the .bat command:

pyrevit run "C:\Users\Wietse_D\AppData\Roaming\pyRevit\Extensions\WYC-tools.extension\lib\BatchProcessor\script.py" "C:\Users\Wietse_d\WYCKAERT ROBERT NV\Digital Construction - Documenten\Beheer applicaties (software)\Revit\RBP\script\dummy2024.rvt" --revit=24.2.0.63

This opens a dummy project from where I batch process some cloud models.

for model in models:
  modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(model.cloud_region, model.project_guid, model.model_guid)
  
  openOptions = OpenOptions()
  openOptions.SetOpenWorksetsConfiguration(WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets))
  newdoc = __revit__.Application.OpenDocumentFile(modelPath, openOptions)
  
  elements = get_all_owned_model_elements(newdoc)
  
  trans = Transaction(newdoc, "Update WYC Parameters")
  trans.Start()
  
  run_batch_process(newdoc, elements)
  
  trans.Commit()
  
  
  transact = TransactWithCentralOptions()
  synch = SynchronizeWithCentralOptions()
  synch.Comment = "WYC Tools"
  relinquishOptions = RelinquishOptions(True)
  relinquishOptions.CheckedOutElements = True
  synch.SetRelinquishOptions(relinquishOptions)
  
  newdoc.SynchronizeWithCentral(transact, synch)
  newdoc.Close()

Have you checked what the journal file of this run command outputs?
I suggest catching errors for each steps of your script.py and store it somewhere as they pop to help you debug or use the pyrevit debugger

Unfortunately the error appears while opening the model, so there is not much I can log or debug.
newdoc = __revit__.Application.OpenDocumentFile(modelPath, openOptions)

I have run the batch process again on 13 models, without any issues. So it seems like this happens occasionally.
I’ll keep an eye on the journal files if it happens again.

Any resources on pyrevit debugger I can read into? Can’t seem to find much on Google.

This is caused by some UI window popping up and interrupting. You have to know what windows to expect and automate clicking the appropriate button. I haven’t used pyrevit run before, but that enter interactive mode popup is same I’ve seen when dropping journal file on the revit shortcut to run them.

I have found using OpenAndActivateDocument instead of OpenDocumentFile fixes this issue.
But this makes it the active model, which can’t be closed. So every new model that opens I have to close the previous one.

....
prev_doc = None
for model in models:
    if model.revit_version == RVT_VERSION:
        modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(model.cloud_region, model.project_guid, model.model_guid)

        openOptions = OpenOptions()
        openOptions.SetOpenWorksetsConfiguration(WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets))
        uidoc = HOST_APP.uiapp.OpenAndActivateDocument(modelPath, openOptions, False)
        newdoc = uidoc.Document #type:Document
        if prev_doc is not None:
            prev_doc.Close()
        prev_doc = newdoc
....

1 Like