Using Command Line To Change Filename Output When Batching Wrap3

Hi,

For my pipeline I need to batch replace features on a large number of models. I follow the manual naming process shown in the wrap3 tutorials and my models are saved out as obj00 - obj19. My models are numbered and saved in the order that they are loaded in wrap so this naming convention makes it possible to determine which model is which. But I currently have to manually rename all of my models by checking the order in which they were loaded in wrap. This is time consuming since I have a very large number of models.

Is there a way to use the command line to save out my batched models with their original names? Or is there another way that I might be unaware of?

Thanks,
Adam

To add to this, here is the part of my json file with the save node:

“SaveGeom”: {
“color”: {
“a”: 0,
“b”: 0,
“g”: 0,
“r”: 0
},
“hasColor”: false,
“isAlwaysVisible”: true,
“nodeId”: 4,
“nodeType”: “SaveGeom”,
“params”: {
“fileName”: {
“dataType”: “String”,
“value”: “C:/STUFF/Scripts/Wrap3/replaced/Object###.obj”
},
“geom”: {
“connectedNodeId”: 2,
“dataType”: “Geometry”
},
“includeTransform”: {
“dataType”: “Boolean”,
“value”: true
},
“saveNormals”: {
“dataType”: “Boolean”,
“value”: false
}
},
“x”: -112.15186625573392,
“y”: 120.72434393366547
},

is there a way to take the list of obj names from my LoadGeom node and use them for the filename part of my SaveGeom node?

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