Hello, I am using batch process to do some automatic data exports using Windows task planner.
pyrevit run “C:\Users\xxx\AppData\Roaming\pyRevit\Extensions\WYC-tools.extension\lib\BatchProcessor\batch_process.py” “C:\Users\xxx\documents\dummy2024 - 1.rvt” --revit=24.3.30.11 --purge
After the dummy project is opened I can open predefined cloud models (newdoc) and do everything I can in a regular project. But when trying to get the revit links I get nothing. Below is a simplified snippet.
cloud_models is custom class containig all nescessary information based on a Excel file.
def batch_process(cloud_models, logger):
for model in cloud_models:
modelPath = ModelPathUtils.ConvertCloudGUIDsToCloudPath(model.cloud_region, model.project_guid, model.model_guid)
openOptions = OpenOptions()
openOptions.SetOpenWorksetsConfiguration(WorksetConfiguration(WorksetConfigurationOption.OpenAllWorksets))
uidoc = HOST_APP.uiapp.OpenAndActivateDocument(modelPath, openOptions, False)
newdoc = uidoc.Document #type:Document
link_types = FilteredElementCollector(newdoc).OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(RevitLinkType)
link_instances = FilteredElementCollector(newdoc).OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(RevitLinkInstance)
for link_type in link_types:
for link_instance in link_instances:
if RevitLinkType.IsLoaded(newdoc, link_type.Id):
if link_instance.GetTypeId() == link_type.Id and ".rvt" in link_instance.Name:
logger.log(link_instance.GetLinkDocument())
When logging the last line I get nothing, but when running the same code without the batch process it works.
My initial thought to debug that would be to save to a file (outside the logger utils) every step of the way just to make sure you fetch everything th right way.
Second, the document. The initial document. How are you getting it? Through execparams?
After some further investigation it seems like the links are not loaded. link_types and link_instances do contain all links.
link_types = FilteredElementCollector(newdoc).OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(RevitLinkType)
for link_t in link_types:
log_debug.info(RevitLinkType.IsLoaded(newdoc, link_t.Id)) # Returns FALSE for all
link_instances = FilteredElementCollector(newdoc).OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(RevitLinkInstance)
for link_i in link_instances:
log_debug.info(link_i.GetLinkDocument()) # Returns None for all
I tested the same code in an open project without batch process and all links return a value. So this might be something specific to the batch process?
It seems like Revit doesn’t load the links by default when using batch process, so I tried manually loading the links using below code.
link_types = FilteredElementCollector(newdoc).OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(RevitLinkType)
for link_type in link_types:
if not RevitLinkType.IsLoaded(newdoc, link_type.Id):
load_result = link_type.Load() # or link_type.Reload() in newer APIs
logger.info(str(load_result.LoadResult))
This returns "ExternalServerMissing" for all links.
Explanation from the ApiDocs: The external add-in required to load this link model could not be found.