Python Reference Guide
 
Loading...
Searching...
No Matches
Tasks\RenameFirstTakeOnMultipleFiles.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# Topic: FBFolderPopup, FBTake, FBApplication.FileOpen
7#
8from pyfbsdk import FBApplication, FBSystem, FBFolderPopup
9from os import listdir
10
11# Create global objects needed for our work...
12lApplication = FBApplication()
13lSystem = FBSystem()
14
15# Let the user select the folder where the FBX files are...
16lFolderPopup = FBFolderPopup()
17lFolderPopup.Caption = "Select the folder where all the FBX files are located"
18
19if lFolderPopup.Execute():
20 lFileList = listdir( lFolderPopup.Path )
21
22 for lFile in lFileList:
23 if lFile.endswith( '.fbx' ):
24
25 lFileFullPath = "%s\\%s" % ( lFolderPopup.Path, lFile )
26
27 # Open the FBX file
28 print("Message: Opening file '%s'" % lFileFullPath)
29 lApplication.FileOpen( lFileFullPath )
30
31 # First obtain the name of the current FBX file, and
32 # remove the trailing '.fbx' extention.
33 lName = lFile.replace( ".fbx", "" )
34
35 # The use that name for the first take in the list of takes...
36 # If the takes have not been re-ordered and renamed, it will be
37 # the take named 'Take 001' that will be renamed.
38 print("Message: Renaming take '%s' to '%s'" % ( lSystem.Scene.Takes[0].Name, lName ))
39 lSystem.Scene.Takes[0].Name = lName
40
41 # Save the new file.
42 # Warning: media will not be embedded!
43 print("Message: Saving file '%s'\n" % lFileFullPath)
44 lApplication.FileSave( lFileFullPath )
45
46 # Clear the scene.
47 lApplication.FileNew()
48
49 # Cleanup local variables
50 del( lName, lFileFullPath )
51
52 # Cleanup local variables
53 del( lFileList, lFile )
54
55# Cleanup
56
57# Cleanup things from pyfbsdk
58del( FBApplication, FBSystem, FBFolderPopup )
59
60# Cleanup things from nt
61del( listdir )
62
63# Cleanup local variables
64del( lApplication, lSystem, lFolderPopup )
FBApplication is used mainly to manage files.
Definition: pyfbsdk_generated.h:801
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