Sunday, September 2, 2012

Softimage: Batch FBX importer

I needed to import a large number of FBX files at once into a scene, then move objects of a specific prefix to zero origin. So made this little script.

#FBX Batch file importer
app = Application

counter = 0

#ask for the path or use default
defaultPath = ('D:\\Projects\\Creaky\\Doomy\\DoomAvModels\\swords\\')
importPath = XSIUIToolkit.PickFolder(defaultPath, 'FBX Batch Load')
#collect the path and find all FBX files in it
if (importPath != ""):
fbxDir  = app.FindFilesInFolder(importPath, ".*\.FBX", True, True)

#import the files individually and prepare them
for f in (fbxDir):
app.FBXImport(f, 0)
app.FBXImportMode('Add')
app.logMessage ("%s imported"%f)
  counter = counter + 1
else:
app.logMessage('Import Cancelled')

#set all objects to zero origin
objName = app.XSIInputBox('prefix name of items \n to set origin to zero', 'Item Prefix', 'Sword')
wildcard = (objName + '*')

if (objName != ""):
try:
app.logMessage('Called %s'%wildcard)
objSelect = app.selectObj(wildcard)
app.translate(objSelect,0,0,0, 'siAbsolute')
except:
app.logMessage('name doesn\'t exist')
else:
app.logMessage('Cancelled')

app.logMessage ('%s files imported from %s'%(counter,defaultPath))

If you wish to use this, be aware that you use it at your own risk. Also you may want to change the default path on the 5th line.