Tasks/RemoveSuffixFromNameOfSceneElements.py

Tasks/RemoveSuffixFromNameOfSceneElements.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: FBMessageBoxGetUserValue, FBComponent.Name
7 #
8 
9 from pyfbsdk import FBSystem, FBMessageBoxGetUserValue, FBPopupInputType
10 
11 # Get the value of the suffix to remove from the user.
12 (lRes, lSuffix ) = FBMessageBoxGetUserValue( "Enter suffix", "Enter suffix to remove: ", "_1", FBPopupInputType.kFBPopupString, "OK", "Cancel" )
13 
14 # Insure that the suffix is valid (i.e. not None) and that the user clicked
15 # on the "OK" button.
16 if lSuffix and lRes == 1:
17 
18  # Get the scene from the system.
19  lScene = FBSystem().Scene
20 
21  # Now iterate the flat list of components in the system.
22  for lComponent in lScene.Components:
23 
24  # Insure that we have a valid component.
25  if lComponent:
26 
27  # Let's see if the name of the component ends with the
28  # suffix to be removed.
29  if not lComponent.Name == None:
30  if lComponent.Name.endswith( lSuffix ):
31 
32  # Rename the component when necessary.
33  lComponent.Name = lComponent.Name.replace( lSuffix, "" )
34 
35  # Cleanup.
36  del( lComponent )
37 
38  # Cleanup.
39  del( lScene )
40 
41 
42 # Cleanup.
43 
44 # Cleanup local variables.
45 del( lRes, lSuffix )
46 
47 # Cleanup things from pyfbsdk.
48 del( FBSystem, FBMessageBoxGetUserValue, FBPopupInputType )