Skip to content
  • Categories
Collapse
Solibri Society Forum
  1. Home
  2. Comments & Feedback
  3. Tech Talks
  4. Regex in autorun

Regex in autorun

Scheduled Pinned Locked Moved Tech Talks
2 Posts 2 Posters 653 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lal
    wrote on last edited by
    #1

    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 re

    ifc_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)

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vasu
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      0

      Copyright © 2025 Solibri Inc. | Powered by NodeBB

      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories