Fill dwgprops from Excel with Python

Fill dwgprops from Excel with Python

I thought this was neat, pandas is the coolest ever : )

1, read the excel file into pandas
2, select the columns we want
3, make sure all the values are strings
4, put it in the database. Note you can transfer info from dwg to dwg
5, re-running the routine will update the values

A great tool for fields

from pyrx_imp import Rx
from pyrx_imp import Ge
from pyrx_imp import Gi
from pyrx_imp import Db
from pyrx_imp import Ap
from pyrx_imp import Ed
import traceback

import pandas as pd

path = 'path to your file'

def PyRxCmd_doit():
try:
db = Db.curDb()
df = pd.read_excel(path)

#select the columns we want
df = df.iloc[:, [1, 7]]

#this summary info wants strings
data = dict(df.values)
for key, val in data.items():
data[key] = str(val)

# get summary info instance
info = Db.Core.getSummaryInfo(db)
info.setCustomSummaryFromDict(data)
Db.Core.putSummaryInfo(info, db)

except Exception as err:
traceback.print_exception(err)

Comments

  • Can do with lisp as Bricscad can read Excel get a range then add to custom properies.
  • ALANH said:

    Can do with lisp as Bricscad can read Excel get a range then add to custom properies.

    Indeed, but why?
    Eventually, Python will replace lisp as the ultimate CAD scripting language lol.

  • ALANH
    edited April 8
    Eventually, Python will replace lisp, I doubt it no need for run time, VBA was the new flavor and never really took off despite Microsoft being behind it. Built into Excel, Word, Access etc, if they change to Python then maybe, I remember Pascal was the future. And the biggest is Autodesk want you to go to .net.

    Autodesk stated support for VBA was to end, when was that 5 Years ago ? Its still there.

    I am to old to start again 40 years of lisping.

    When Acad invented "Macro record" they ignored VBA, yes have seen Cad software with a record macro writing VBA code. I have not used Macro record basically since it was introduced so un friendly to edit to make it suit a task. If it was to write python or Autodesk bring a load uncompiled code for python then more may jump onboard.

    It would be interesting to get Bricscad support comments about this subject, future of user programming.
  • My comment was in jest, lisp is super cool! I’ve written many thousands of lines of lisp.
    That’s why I kind of see funny these days.

    “Built into Excel, Word, Access etc, if they change to Python then maybe”
    It has begun.
    https://support.microsoft.com/en-us/office/get-started-with-python-in-excel-a33fbcbe-065b-41d3-82cf-23d05397f53d

    “load uncompiled code for python”
    There’s no compiling, load the script and run it like lisp.

    “future of user programming”
    The way I see it, every highschooler around here is learning a bit of python. Microsoft sees it,
    that’s why hired Guido van Rossum out of retirement and have been investing in the Python environment, VS Code, Pylance, PyDebug… etc.

    Note, this project is open source and my comments may not represent the views of Bricsys or Autodesk.