Message 1 of 4
File Handling-Python?
Not applicable
03-10-2010
10:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I just delved into Python after some studies in MEL and I got this far in making a python run the .txt file that you can view and download from the website. What I'm caught up on now is making the curves for this data to create a visual in Maya.
I want to have a row of curves displaying the range of data on each from the genres and genreCounts.
This could be done either on the x, y or z axis but I'm not sure how.
--J
Link to the data
http://manyeyes.alphaworks.ibm.com/manyeyes/datasets/movie-genres-1888-2012-count/versions/1.txt
I want to have a row of curves displaying the range of data on each from the genres and genreCounts.
This could be done either on the x, y or z axis but I'm not sure how.
--J
Link to the data
http://manyeyes.alphaworks.ibm.com/manyeyes/datasets/movie-genres-1888-2012-count/versions/1.txt
import maya.cmds as mc
def movieGenre():
#import re
defaultDirectory = mc.workspace(query = True, rootDirectory = True)
if mc.optionVar(exists = "dialogDefaultDirectory"):
defaultDirectory = mc.optionVar(query = "dialogDefaultDirectory")
userFile = mc.fileDialog(mode = 0, directoryMask = ("%s/*.txt" % defaultDirectory))
if not len(userFile):
print "# No file selected."
return
print "# The user selected %s" % userFile
mc.optionVar(stringValue = ("dialogDefaultDirectory",
userFile) )
file = open(userFile, "r")
#pattern = re.compile('-*\d+\.\d+')
points = []
curves = []
genres = []
genreCounts = []
# converts data to set up for curves.
lineCount = 0
for line in file:
lineCount = lineCount + 1
line = line.strip()
lineSplit = line.split()
if len(line):
if lineCount == 1:
genres = line.split()
for genre in genres:
genreCounts.append([])
else:
i = 0
for count in lineSplit:
genreCounts.append(float(count))
i = i + 1
# make curves from the data stored in genreCounts
# make the curve, record its name and prepare for another curve
curve = mc.curve(name = "curveData", degree = 3, point = points)
curves.append(curve)
points = []
# curve = mc.curve(name = "curveData", degree = 1, point = points)
# curves.append(curve)
print "# Curves made from %s:" % (userFile)
for curve in curves:
print "# %s" % curve
file.close()