Regex in autorun
-
I’m generating a Solibri autorun XML file using Python and want to set the shortname attribute for each IFC file by extracting everything between “XXX-” and “-3D” in the filename using regex. The script runs without errors, and the XML output looks correct, but Solibri doesn’t seem to recognize or display the shortname in the interface.
I’ve tried several regex patterns and confirmed that the shortname values are unique and properly included in the XML.
Here’s a simplified version of the script:
import os
import xml.etree.ElementTree as ET
import reifc_folder = r"<path_to_ifc_folder>"
output_file = r"<path_to_output_xml>"
smc_path = r"<path_to_smc_file>"ifc_files = [os.path.join(ifc_folder, f) for f in os.listdir(ifc_folder) if f.lower().endswith(‘.ifc’)]
batch = ET.Element(“batch”, name=“Simple Batch”, default=“root”)
target = ET.SubElement(batch, “target”, name=“root”)ET.SubElement(target, “openmodel”, file=smc_path)
for ifc_file in ifc_files:
filename = os.path.basename(ifc_file)
match = re.search(r’XXX-(.+?)-3D’, filename)
shortname = match.group(1) if match else “”
ET.SubElement(target, “file”, file=ifc_file, shortname=shortname)ET.SubElement(target, “autoupdatemodels”)
ET.SubElement(target, “savemodel”, file=smc_path)
ET.SubElement(target, “exit”)tree = ET.ElementTree(batch)
tree.write(output_file, encoding=“ISO-8859-1”, xml_declaration=True) -
@lal In the current Python script, the line:
ET.SubElement(target, “file”, file=ifc_file, shortname=shortname)generates the following XML element:
<file file="modelname" shortname="shortname" />However, since there is no autorun task associated with the ‘file’ tag, this needs to be updated.
To resolve this, please modify the line to:
ET.SubElement(target, 'openmodel', file=ifc_file, shortname=shortname)Hope this helps.
Copyright © 2025 Solibri Inc. | Powered by NodeBB