Python Reference Guide
 
Loading...
Searching...
No Matches
Tasks\BatchExportCharacterAnimationTool.py
1# Copyright 2009 Autodesk, Inc. All rights reserved.
2# Use of this software is subject to the terms of the Autodesk license agreement
3# provided at the time of installation or download, or which otherwise accompanies
4# this software in either electronic or hard copy form.
5#
6# Script description:
7# Specify a directory where all fbx files will be loaded and all Character rig and Animation will be exported.
8#
9# Topic:FBFolderPopup, FBSystem, FBApplication, FBApplication.FileOpen, FBMessageBox, FBFbxOptions
10#
11#
12
13import os
14import re
15from pyfbsdk import FBFolderPopup, FBSystem, FBApplication, FBMessageBox, FBFbxOptions
16
17# Creating all the Constructors
18lFp = FBFolderPopup()
19lSystem = FBSystem()
20lApp = FBApplication()
21lScene = lSystem.Scene
22fbxList = []
23
24# Select directory you would like to load your FBX files in from
25# Create the popup and set necessary initial values.
26lFp.Caption = "Source Files: Select the folder containing the files you would like to export"
27
28# Set the default path. Good for a PC only... will have to be different for Mac.
29lFp.Path = r"C:\Autodesk"
30
31# Get the GUI to show.
32lRes = lFp.Execute()
33
34# If you select a folder, show its name, otherwise indicate that the selection was canceled.
35if not lRes:
36 FBMessageBox( "Warning:", "Selection canceled, cannot continue!", "OK" )
37
38else:
39 FBMessageBox( "Selected Folder Path:", "Selected folder:\n Path: '%s'" % lFp.Path, "OK" )
40
41 # Getting the names of the files in your previously selected folder
42 # Using os to get the file names from the specified folder (above) and storing names of files in a list
43 fileList = os.listdir(lFp.Path)
44 print("fileList", fileList)
45 # Setting the regular expression to only look for .fbx extenstion
46 fbxRE = re.compile('^\w+.fbx$', re.I)
47
48 # Removing any files that do not have an .fbx extenstion
49 for fname in fileList:
50 mo = fbxRE.search(fname)
51 if mo:
52 fbxList.append(fname)
53 # Exporting items in the file one at a time
54 for fname in fbxList:
55
56 # Opening the file in MotionBuilder, this replaces the current scene
57 lApp.FileOpen(lFp.Path + "\\" + fname, False)
58
59 # Saves out the character and rig animation
60 # if there are multiple characters per file you will need to change to accommodate.
61 # SaveCharacterRigAndAnimation (str pFileName, FBCharacter pCharacter, bool pSaveCharacter, bool pSaveRig, bool pSaveExtensions)
62 lOptions = FBFbxOptions(False)
63 lOptions.SaveCharacter = False
64 lOptions.SaveControlSet = True
65 lOptions.SaveCharacterExtension = False
66 if len( lScene.Characters ) > 0:
67 lApp.SaveCharacterRigAndAnimation(lFp.Path + "\\Animation_" + fname, lScene.Characters[0], lOptions)
68
69 # Closing the current file, not really necessarily needed sine the FBApplication::FileOpne replaces the current scene
70 lApp.FileNew()
71#Cleanup
72del(lFp, FBFolderPopup, lSystem, FBSystem, lRes, lApp, FBApplication, lScene, fbxList, re, os, FBMessageBox, FBFbxOptions)
73
74
75
76
FBApplication is used mainly to manage files.
Definition: pyfbsdk_generated.h:801
Customize file loading and saving.
Definition: pyfbsdk_generated.h:7400
Folder Popup (for selecting a directory).
Definition: pyfbsdk_generated.h:8126
Provides access to the underlying system, and the MotionBuilder scene.
Definition: pyfbsdk_generated.h:18771
int FBMessageBox(str pBoxTitle, str pMessage, str pButton1Str, str pButton2Str=None, str pButton3Str=None, int pDefaultButton=0, int pScrolledMessage=0)
Dialog popup box.