Jan 12
I saw this anydbm module and thought that it could be handy for storing certain user options. Maya already has a built in optionVar command that Python can use. There are a great many reasons to use optionVar’s. I just wanted to give an example of a built in Python library module that lets you create your own files like the optionVar file.
Note that this module creates binary files so I dont think they are as useful as creating your own asci file since asci is readable. As you can see in the example they are so easy to create and update I could see myself using them at some point.
import anydbm
# Create a new database file, use c - creating | r - reading | w - writing | n - newdatabase
db = anydbm.open('C://databasefile', 'w')
# Add new dictionary keys | values to the file
db['python'] = '1'
db['in'] = '2'
db['maya'] = '3'
# Print the data in the file
# As with all dictionarys in Python this will not print the values in order
# This is because Python is optimising how it stores the values so they can be accessed quickly
for k, v in db.iteritems():
print k, '\t', v
# This will auto overwrite the existing keys | values which makes it easy to update the file
db['python'] = 'is'
db['in'] = 'really'
db['maya'] = 'cool'
# The previous 1 2 3 values no longer exist and now maya will print the new values
for k, v in db.iteritems():
print k, '\t', v
db.close()
# Note: If no path is given files are stored as binary files in your Maya installation dirrectory
# C:\Program Files\Autodesk\Maya_version\bin\
Next on my list to show will be a Python Maya API utility node,
-RyanT
Recent Comments