I found a solution for batching and renaming filenames of objs using python. Sick of the pesky obj###? Check this out. It’s not pretty code but hopefully understandable for anyone looking for an answer. This code was made specifically for batch replacing geometry given a polygroup.txt file and keeping the file names of objs. The code assumes that you have saved inside a directory the following: (a python file, a windows batch file, a wrap file with the nodes set up, a polygroup.txt file, a source obj, a folder containing all the objs to batch). The code looks at all the objs inside the folder and runs wrap individually for each. The python code edits the wrap file outputs and then uses the subprocess command to call the batch file and run the edited wrap file. You just have to run the python script.
—PYTHON CODE—
import json
import sys
import os
import subprocess
import glob
#get filename directories to replace in wrap file
cwd = os.getcwd()
batchList = glob.glob(‘*.bat’)
batchPath = cwd + “\” + batchList[0]
wrapList = glob.glob(‘*.wrap’)
wrapPath = cwd + “\” + wrapList[0]
polyList = glob.glob(‘*.txt’)
polyPath = cwd + “\” + polyList[0]
polyPathNew = str(polyPath)
origObjList = glob.glob(‘*.obj’)
origObj = cwd + “\” + origObjList[0]
#create list of subdirectory paths (all folders containing objs)
subdirs =
cwdContents = os.listdir(cwd)
for item in cwdContents:
if os.path.isdir(item):
path = cwd + “\” + item
subdirs.append(path)
#create list of objs from each subdirectory
objList =
pathsList =
for folder in subdirs:
os.chdir(folder)
myObj = glob.glob(‘*.obj’)
for obj in myObj:
objList.append(obj)
pathsList.append(folder)
#change wrap file information for each obj
for num, obj in enumerate(objList):
change = pathsList[num] + “\” + obj
save = pathsList[num] + “\” + “completed” + “\” + os.path.splitext(obj)[0] + “_replaced.obj”
saveNew = str(save)
f = open(wrapPath, 'r')
project = json.loads(f.read())
project['nodes']['GeomToChange']['params']['fileNames']['value'] = [change]
project['nodes']['GeomToCopy']['params']['fileNames']['value'] = [origObj]
project['nodes']['SaveGeom']['params']['fileName']['value'] = save
project['nodes']['SelectPolygons']['params']['fileName']['value'] = polyPath
f.close()
f = open(wrapPath, 'w')
f.write(json.dumps(project))
f.close()
#run wrap for each obj
subprocess.call([batchPath, obj])
print ("SAVED NEW OBJ: " + save)
input(‘Press ENTER to exit’)
—BATCH CODE—
C:
cd C:\Program Files\R3DS\Wrap 3.4
start Wrap3.exe
wrap3cmd compute “C:\replaceTest.wrap” -s 0 -e 0