Tasks/RenameFirstTakeOnMultipleFiles.py

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 #
8 from pyfbsdk import FBApplication, FBSystem, FBFolderPopup
9 from os import listdir
10 
11 # Create global objects needed for our work...
12 lApplication = FBApplication()
13 lSystem = FBSystem()
14 
15 # Let the user select the folder where the FBX files are...
16 lFolderPopup = FBFolderPopup()
17 lFolderPopup.Caption = "Select the folder where all the FBX files are located"
18 
19 if 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
58 del( FBApplication, FBSystem, FBFolderPopup )
59 
60 # Cleanup things from nt
61 del( listdir )
62 
63 # Cleanup local variables
64 del( lApplication, lSystem, lFolderPopup )