Working with Database in PyRevit

Hello, i am working on project to create an extension that needs to work with a document base database precisely tinydb . I honestly dont know how to start and i have made my reading arounding telemetry but thats not the kind of data i need to save on the db i wamt to implement in my extension

Any help please

@Toe_knee ,

trail and error…
https://tinydb.readthedocs.io/en/latest/

Documentation seems to be good.

What do you exactly? only read?

KR

Andreas

i want to extract data’s from Revit then save it on the database and from the database be able to export the data document as csv file on any desktop folder .
thanks for your time.

Hi @Toe_knee, welcome to the forum!

Do you really need to save the data to tinydb, or can you save directly to csv?

CSV export can be easily done within pyrevit thanks to the python built-in library; on the other hand, to write to a tinydb database you need to use a separate package as @andreasd811 stated. For this, you need to create a lib extension for tinydb, which fortunately doesn’t have dependencies, but you have to use the version 3 to be able to use it with ironpython 2.7 (or use cpython 3).

Other than this, I suggest you to embrace the “programmer’s mindset” and break down your problem into smaller ones, and be more specific about each of them.

  1. you want to extract data from revit. This statement is too generic, if you want us to point you in the right direction you need to be more specific:
    • Are you interested in all elements, or just some categories of elements, or only the selected ones? Or sheets, views, schedules…?
    • do you want to extract parameters? Built-in or shared? Or maybe their insertion point, bounding box, dimensions?
      Once you figured out what you need, you will easily find the answer in other discussion on this forum, the documentation or the various tutorials (check the pinned quickstart guide for links)
  2. You want to save them to tinydb (if you cannot avoid that). The only thing needed, apart from the issues I mentioned above, is to save the data from point one as dictionaries. The rest is accomplished by following the user guide or some tutorials.
  3. You want to export csv files. This works even without tinydb, instead of fetching the documents from the database you can just use the dictionaries to build the csv thanks to the csv.DictWriter class. There are plenty of tutorials to learn how to use it (and it all boils down to a few lines of code).
2 Likes

hello @sanzoghenzo thanks for the reply
along the line of my research I was able to overcome by integrating csv to act as the database by using the append to file function (‘a’). all parameter extracted from the model will append to the csv file. i ll provide a sample of the code on request.
thanks for your time

1 Like

Hi, can u share sample of the code, please
I try extract data from revit model to csv, too

Hi @Andr_T, welcome to the forum!

There are plenty of examples out there on how to write a CSV file with python; After the Official python documentation, a good guide is Real python one.

As per the data extraction, as I stated previously: