BOM batch/multiple export to CSV

Hi,

Is there a way to batch export multiple BOM's to csv, without selecting each table manually and exporting?

I am using the BOM manager to do the Take-off quantities for a Civil BOQ. There are multiple tables for each category such as formwork, earthworks, masonry, concrete and then some other BOM's for beams, columns, slabs etc. These csv's are then imported into master BOQ spreadsheet.

The BOM table works a lot better than the previous schedules, but having so many BOM's become tedious to export each manually.

Comments

  • Are they normal tables? You can write a script in lisp or python to write these out

    As an example this will write out every table in a drawing to excel

    import traceback
    from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed
    import openpyxl as xl

    def PyRxCmd_doit():
    try:
    db = Db.curDb()
    wb = xl.Workbook()

    tables = [Db.Table(id) for id in db.objectIds(Db.Table.desc())]
    opts = Db.TableIteratorOption.kTableIteratorSkipMerged

    for idx , table in enumerate(tables):
    ws = wb.create_sheet('BOM {}'.format(idx))
    for val in table.cellValues(opts):
    ws.cell(row=val[0]+1, column=val[1]+1, value=val[2])

    wb.save('e://ItsAliveBom.xlsx')
    except Exception as err:
    traceback.print_exception(err)

    Maybe someone can provide a lisp sample that would be easier to test with
  • When there are no tables you could use -BMBOMEXPORT in your script.
    See test project in attachment, load the lisp script in Scripts folder

    (defun c:Bomexport ()
    (command "-BMBOMEXPORT" "F" (strcat (getvar 'dwgprefix) "Schedules\\walls.bom") "F" (strcat (getvar 'dwgprefix) "Schedules\\walls.csv"))
    )
    (c:Bomexport)
    (princ)
  • Great thanks, yes they are normal tables.

    I've spent a good few hours online and with chatgpt trying to get the script to run but I keep getting error;
    from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed
    ModuleNotFoundError: No module named 'pyrx_imp'

    This is my first time using python in Bricscad so I am not familiar with calling external libraries.

    I installed python and did the PIP install for openpyxl, and then followed the instructions from https://github.com/CEXT-Dan/PyRx

    I am still getting the same error. Any guidance on installing the needed libraries?

  • Its_Alive
    edited April 19

    Hi,

    Did you follow the steps here first?

    https://github.com/CEXT-Dan/PyRx/blob/main/READMEINSTALL.md

    ~Dan

  • Hi,

    I followed all the steps, and went through all the steps again now. I did the Appload of the files below, but when i run the script I still get the error:

    from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed
    ModuleNotFoundError: No module named 'pyrx_imp'

  • how are you running the script?

    Are you typing PYLOAD, then loading the script?

    then running the new command 'doit'?

  • I would right click and run the script from project browser.


    This would be the output
    : -bimpython
    Enter Python script path: C:/Users/omnig/Ulmo Water/Ulmo Water - General/Projects/Avec La Terre
    (P2401)/BIM_Project/Scripts/Test.pyTraceback (most recent call last):
    File "C:\Users\omnig\Ulmo Water\Ulmo Water - General\Projects\Avec La Terre_(P2401)\BIM_Project\Scripts\Test.py", line 2, in <module>
    from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed
    ModuleNotFoundError: No module named 'pyrx_imp'

    When i use pyload i get this.

    : PYLOADPyErr No module named 'openpyxl' ,Traceback -
    At <module> (C:\Users\omnig\Ulmo Water\Ulmo Water - General\Projects\Avec La Terre_(P2401)\BIM_Project\Scripts\Test.py:3):
    pyload failed:

  • Its_Alive
    edited April 19

    Sorry for the confusion, PyRx is separate from Bricsys.

    You will need to pip openpyxl into Python 3.12, Probably best to use PowerShell

    python-3.12 -m pip install openpyxl

    edit: The design is for modules be run similar to lisp:

    So PYLOAD then run the command

  • Great thanks, it worked. Awesome, thanks for all the help.

    So the script is running now, but it is not doing anything. Do the BOM's need to be placed in the drawing, IE model space or paperspace?

    Ideally it would cycle through all these tables without them needing to be 'placed'

  • Its_Alive
    edited April 19

    The routine is looking for Table entities, it searches the whole drawing, so either modelspace or paperspace

    I’m actually not familiar with the BOM Manager, however it may be possible to extract this information. I will need to investigate this. do you happen to have a sample .DWG?

  • Never mind about the sample, I found one.

    I’ll investigate whether it’s possible to read the data

  • Thanks for all the help. In the meantime i will create a layout and post the tables there so the script will work. This is not too much of a workaround.