Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / File Handling-Python?
  RSS 2.0 ATOM  

File Handling-Python?
Rate this thread
 
40603
 
Permlink of this thread   Subscribe to this thread
avatar
  • jsells20
  • Posted: 10 March 2010 05:48 PM
  • Location: Savannah
  • Total Posts: 39
  • Joined: 08 December 2008 10:40 AM

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 TruerootDirectory True)
    
    
if mc.optionVar(exists "dialogDefaultDirectory"):
        
defaultDirectory mc.optionVar(query "dialogDefaultDirectory")
        
    userFile 
mc.fileDialog(mode 0directoryMask ("%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:
                
0
                
for count in lineSplit[1:]:
                    
genreCounts[i].append(float(count))
                    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 3point 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()


Replies: 0
avatar
  • THNKR
  • Posted: 11 March 2010 03:43 AM

this works for me

import maya.cmds as mc
def movieGenre()
:
 
#import re
 
defaultDirectory mc.workspace(query TruerootDirectory True)
 
if mc.optionVar(exists "dialogDefaultDirectory"):
 
defaultDirectory mc.optionVar(query "dialogDefaultDirectory")  
 userFile 
mc.fileDialog(mode 0directoryMask ("%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:
 
0
 
for count in lineSplit[1:]:
 
(icountlineCount )
 points
.append(v)
 
#print points
 
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 3point points)
             curves
.append(curve)
     
 
print "# Curves made from %s:" (userFile[userFile.rfind("/"1:])
 
for curve in curves:
 print 
"#   %s" curve
    
 file
.close()


Replies: 0
avatar
  • jsells20
  • Posted: 16 March 2010 01:50 PM

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 TruerootDirectory True)
    
if mc.optionVar(exists "dialogDefaultDirectory"):
        
defaultDirectory mc.optionVar(query "dialogDefaultDirectory")  
        
    userFile 
mc.fileDialog(mode 0directoryMask ("%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:
                
0
                
for count in lineSplit[1:]:
                    
(icountlineCount )
                    points
.append(v)
#print points
                    
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 1point points)
            curves
.append(curve)
     
    
print "# Curves made from %s:" (userFile[userFile.rfind("/"1:])
    
for curve in curves:
        print 
"#   %s" curve
    
    file
.close()


Replies: 0
avatar
  • jsells20
  • Posted: 03 April 2010 05:02 PM

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.



Replies: 0




   
  Settings Choose Theme color: