Hey Folks,
I am looking for a way to use SQLite in RhinoPython.
Since Rhino uses IronPython 2.7 and the sqlite3 module is part of the standard library since Python 2.5, I don’t quite understand why I can’t just call:
import sqlite3
This will give me an error, since the module is not available for some reason.
Can anyone explain / help?
Yeah I also stumbled upon that yesterday.
But given my lack of knowledge regarding .NET things, I can not get it to run at all.
I tried to install it for .NET 4.0 (as I think Rhino uses 4.0 but I’m not even sure of that ) and then tried calling
import System.Data.SQLite
but other than an error I couldn’t get anything.
If someone has any knowledge about how to get SQLite running within python scripts it would be greatly apperciated!
Copy IronPython.SQLite.dll and sqlite3 into a Folder that has been added to your library search paths within RhinoPython (alternatively you could copy it anywhere you want and add the location to the library search paths)
Edit the __ini__.py File in the sqlite3 Folder and add the following two lines on the top:
import clr
clr.AddReferenceToFile(“IronPython.SQLite.dll”)
The last step ensured that the DLL is found
Now if we want to use the sqlite3 module in our script we can simply say:
import sqlite3
Sorry for resurrecting an old thread, but it addresses what I am trying to do and I can’t get it to work at present. I think I have followed the instructions, but it is still not working.
I have run the EditPythonScript command in Rhino and have identified one of the folders (by going into Tools > Options: C:\Users\myname\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib
This means that in this folder I now have the DLL and the sqlite3 folder, inside which is the __init__.py file which I have edited…
import clr
clr.AddReferenceToFile(“IronPython.SQLite.dll”)
from dbapi2 import *
I then create a component and put in
import sqlite3
However, this does not work… I get an interesting error:
Runtime error (SyntaxErrorException): unexpected token ''
Traceback:
line 1, in script
I wonder if I should be adding the sqlite3 folder to a python path?
I have created a custom folder C:\Utilities\IPythonSQLite3 and have placed the DLL and sqlite3 folder in there. I have then added the folder to the PythonScript path in Tools > Options (as above)
I have not edited the __init__.py file.
Instead I have placed the following lines in my component.
After this, I can access the sqlite3 library. However, it seems wrong to do this with every component. Can anyone point to another way of doing this? Is there a startup script that I could place this in?
Hey, sorry for getting back to you just now.
I don’t quite understand, why editing the __init__.py is not working for you. I have tried it again just now with Rhino 5 & 6 and it was working fine for me. So unfortunately I can’t really reproduce your error.
Anyway, the __init__.py inside the sqlite3 folder should work fine as you startup script, if you edit it and add…
Hi Andrew, thanks for the link.
I want to store info about my blocks (attributes, Rhino ID, volume, area, length, etc…) and make queries through a human UI interface to display the filtered info and evntually select the corresponding objects in Rhino.
It is also the basis for generation of BOM tables, fabrication drawings, etc.
Since it’s embedded in Rhino 6, I would expect a minimum of documentation from McNeel’s part ; at least a basic example of how to use in Rhino or GH.
Now that I understand what database queries can do, I feel that a lot of GH tree management mumbo-jumbo could be eliminated when needing to sort/filter data…
I’m kind of surprised to find no actual examples of definitions using Slingshot or GHPython + SQLight in this forum.