Skip to content

Instantly share code, notes, and snippets.

@aobond2
Created March 19, 2024 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aobond2/80c7088b63ea7391f7f99e7a3f9e3146 to your computer and use it in GitHub Desktop.
Save aobond2/80c7088b63ea7391f7f99e7a3f9e3146 to your computer and use it in GitHub Desktop.
Script to make this CLI (https://github.com/mml-io/avatar-tools/tree/feature/converter-cli) work on multiple files
import subprocess
import os
import sys
# TODO: Not sure if this is default folder for everyone
userFolder = os.path.expanduser('~')
avatarToolsFolder = userFolder + '\\avatar-tools'
recursiveArg = '--r'
def getArguments():
arguments = sys.argv[1:]
if len(sys.argv) < 2:
print ("Usage: python AvatarExporterCLI.py <folderPathToProcess>\n")
print ("Options:")
print ("\t--r\tSearch folder recursively")
sys.exit(1)
folderPath = sys.argv[1]
glbs = getGLBInFolder(folderPath, arguments)
if glbs:
for glb in glbs:
print (glb)
runAvatarCLIOnFile(glb)
def getGLBInFolder(folderInput, arguments):
def isGLBFile(filename):
return filename.endswith(".glb")
glbFiles = []
if recursiveArg in arguments:
for root, dirs, files in os.walk(folderInput):
glbFiles.extend(os.path.join(root, file) for file in files if isGLBFile(file))
else:
glbFiles.extend(os.path.join(folderInput, file) for file in os.listdir(folderInput) if isGLBFile(file))
return glbFiles
def runAvatarCLIOnFile(glbInput):
glbInput = glbInput.replace("\\", "/")
# TODO: make this not absolute
npmPath = "C:/Users/BondhanKimbalazani/.nvm/versions/node/v18.16.0/bin/npm.cmd"
subprocess.run([npmPath, "run", "convert", "--", "-i", glbInput, "-o", glbInput], cwd = avatarToolsFolder)
getArguments()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment