daily pastebin goal
19%
SHARE
TWEET

UV Edge Exporter

DrGravitas Dec 10th, 2015 1 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2.         WIP: 15_0927
  3.         Script By: Dr. Gravitas
  4.        
  5.         Given a set of edges, construct an exportable dataset for use in auto cutting UVs.
  6.        
  7.         Format:
  8.                 [ [ edgeID number , Edge Length ] , [ vertexID number, vertex Position Point ]... ]
  9.  
  10. '''
  11. import pymel.core as pm
  12. from maya import OpenMaya as om
  13. import os
  14. import fileinput
  15. import pickle
  16.  
  17. '''
  18.         Builds a list of Points
  19. '''
  20. def buildPointsList(selected):
  21.         output = []
  22.        
  23.         for edges in selected:
  24.                 #Selection may include lists of edges. Maya is funny like that.
  25.                 for edge in edges:
  26.                         #Type Check If any selected node is not actually an edge, throw an error.
  27.                         if not isinstance(edge, pm.MeshEdge):
  28.                                 pm.error(edge + ' is Type: ' + type(edge).__name__ + '. Not the required Type: '+pm.MeshEdge.__name__)
  29.                        
  30.                         edgeId = [ edge.index(), edge.getLength() ]
  31.                         edgeDef = []
  32.                         vertDef = []
  33.                        
  34.                         for vertex in edge.connectedVertices():
  35.                                 vertDef.append( [ vertex.index(), vertex.getPosition(space='world') ] )
  36.                        
  37.                         output.append( [ edgeId, vertDef ] )
  38.                
  39.         return output
  40.  
  41. def writeToFile(filename, output):
  42.         fileout = open( filename, 'w' )
  43.         #fileout.write( str(output) )
  44.        
  45.         pickle.dump( output, fileout )
  46.        
  47.         return
  48.  
  49. '''
  50.         Export list of edges to a location format is as follows:
  51.                 [ [ edgeID number , Edge Length ] , [ vertexID number, vertex Position Point ]... ]
  52.        
  53.         TODO: turn this into a dialog box that lets you configure this but auto-populates with standardDefaults
  54. '''
  55. def exportEdges(selected):
  56.         output = buildPointsList(selected)
  57.         # TODO: Replace this with the correct PyMel means of workspace file IO
  58.         dirPath = os.path.dirname( 'C:\\[Fill in the path to your project's scripts here]\\Scripts\\StoredData\\UV Cut Edges\\' )
  59.         filename = pm.date( format='YY_MMDD' ) + '_UVCutEdges' #Creates a filename based on the date and _UVCutEdges
  60.         outputFile = os.path.abspath( os.path.join( dirPath, filename ) )
  61.        
  62.         writeToFile( outputFile, output )
  63.  
  64. '''
  65.         Main Body
  66. '''
  67. selected = pm.selected()
  68. exportEdges(selected)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top