|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
|
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.c...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[0:userFile.rfind("/")]) )
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()[1:]
for genre in genres:
genreCounts.append([])
else:
i = 0
for count in lineSplit[1:]:
genreCounts[i].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[userFile.rfind("/") + 1:])
for curve in curves:
print "# %s" % curve
file.close()
|
|
|
|
this works for me
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[0:userFile.rfind("/")]) )
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:
print line
points = []
lineCount = lineCount + 1
line = line.strip()
lineSplit = line.split()
if len(line):
if lineCount == 1:
genres = line.split()[1:]
for genre in genres:
genreCounts.append([])
else:
i = 0
for count in lineSplit[1:]:
v = (i, count, lineCount )
points.append(v)
#print points
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)
print "# Curves made from %s:" % (userFile[userFile.rfind("/") + 1:])
for curve in curves:
print "# %s" % curve
file.close()
|
|
|
|
I’m pretty sure I got the indention set right but I may be wrong. When I run the following code after I select the file I get this error.
# The user selected /Users/jsells20/Desktop/Movie Genres 1888-2012 Count.txt
Year Action Adult Adventure Animation Biography Comedy Crime Documentary Drama Family Fantasy FilmNoir GameShow History Horror Music Musical Mystery News RealityTV Romance SciFi Short Sport TalkShow Thriller War Western
# Error: Need at least (degree + 1) control vertices to create a curve span
# Traceback (most recent call last):
# File “<maya console>”, line 1, in <module>
# File “<maya console>”, line 49, in movieGenre
# RuntimeError: Need at least (degree + 1) control vertices to create a curve span
# #
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[0:userFile.rfind("/")]) )
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:
print line
points = []
lineCount = lineCount + 1
line = line.strip()
lineSplit = line.split()
if len(line):
if lineCount == 1:
genres = line.split()[1:]
for genre in genres:
genreCounts.append([])
else:
i = 0
for count in lineSplit[1:]:
v = (i, count, lineCount )
points.append(v) #print points
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 = 1, point = points)
curves.append(curve)
print "# Curves made from %s:" % (userFile[userFile.rfind("/") + 1:])
for curve in curves:
print "# %s" % curve
file.close()
|
|
|
|
Any useful information that may lead me in the right direction will be great. I’m sure someone out there knows what I’m trying to do.
|
|
|
|
| Settings
| Choose Theme color:
|
|
|
|
|
|
|
|
|