# script to delete the normal data from all OBJ # files in a directory and subdirectory. Edited # file will be renamed as filename_NoNormals.obj # Strongly suggest that you work on copies of the # files rather than the originals. # written by PhilC # http://www.philc.net # Use however you like but at your own risk. import poser import os import string def main(): # get directory folder = getDirectory() #itterate through folder and subfolders os.path.walk(folder,process,0) def process(x,directory,files): print directory for name in files: if string.lower(name[-4:]) == ".obj": newName = name[:-4] + "_NoNormals.obj" existingFilePath = os.path.join(directory,name) newFilePath = os.path.join(directory,newName) lines = ReadFileToLines(existingFilePath) newLines = [] print "Processing %s" % existingFilePath for line in lines: if "vn " in line: pass else: newLines.append(line) SaveLinesToFile(newLines,newFilePath) print "File saved to %s" % newFilePath def getDirectory(): dlg = poser.DialogDirChooser(1, "Select folder", os.curdir) dlg.Show() return dlg.Path() def openFile(): Type = poser.kDialogFileChooserOpen parentDialog = 1 message = "browse for obj file" startDir = os.path.join(os.curdir,'*.obj') dlg = poser.DialogFileChooser(Type, parentDialog, message, startDir) dlg.Show() filepath = dlg.Path() return filepath def saveFile(): Type = poser.kDialogFileChooserSave parentDialog = 1 message = "save as" startDir = os.path.join(os.curdir,'*.obj') dlg = poser.DialogFileChooser(Type, parentDialog, message, startDir) dlg.Show() filepath = dlg.Path() return filepath def ReadFileToLines(filepath): singleline = 0 fd = open(filepath, 'rb') s = fd.read() fd.close() if string.find(s, '\r\n') > -1: delim = '\r\n' elif string.find(s, '\n') > -1: delim = '\n' elif string.find(s, '\r') > -1: delim = '\r' else: singleline = 1 if not singleline: lines = string.split(s, delim) else: lines = [s] return lines def SaveLinesToFile(lines, filepath): fd = open(filepath, 'wb') s = string.join(lines, '\n') fd.write(s) fd.close() main()