Tasks/SetAllCamerasBackgroundColorFromFirstSelectedCamera.py

Tasks/SetAllCamerasBackgroundColorFromFirstSelectedCamera.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: FBCamera, FBColor, FBScene
7 #
8 from pyfbsdk import FBSystem, FBModelList, FBColor, FBGetSelectedModels
9 
10 # Because FBGetSelectedModels returns only model references that cannot be
11 # changed into other types, we have this function that tries to match up
12 # the name of the model passed as a parameter, and see if there is a camera
13 # listed in the camera list with the same name. If so, we return this camera.
14 # This function returns None if no camera is found.
15 def GetCamera( pModel ):
16  lSystem = FBSystem()
17 
18  # Set the default return value.
19  lResult = None
20 
21  # Lets find a camera with the same name.
22  for lCamera in lSystem.Scene.Cameras:
23  if pModel.Name == lCamera.Name:
24  lResult = lCamera
25  break
26 
27  # Cleanup.
28  del( lSystem, lCamera )
29  return lResult
30 
31 
32 # We build the model list object that must be passed to FBGetSelectedModels.
33 lModelList = FBModelList()
34 FBGetSelectedModels( lModelList )
35 
36 # Iterate thru the list of models selected.
37 for lModel in lModelList:
38 
39  # See if the object is a camera.
40  lSelectedCamera = GetCamera( lModel )
41 
42  # If the lSelectedCamera is not None.
43  if lSelectedCamera:
44 
45  # If we do have a camera selected, use its BackGroundColor for all
46  # the other cameras in the system.
47  for lCamera in FBSystem().Scene.Cameras:
48 
49  # WARNING: Due to a problem with the implementation of the class
50  # FBPropertyAnimatableColor, we have to create a tuple from the
51  # string representation of the BackGroundColor. This tuple is then
52  # used as a parameter in the constructor of FBColor.
53  lCamera.BackGroundColor = FBColor( eval( str( lSelectedCamera.BackGroundColor )))
54 
55  # Cleanup.
56  del( lCamera )
57 
58  # Cleanup.
59  del( lSelectedCamera, lModel )
60 
61  # Once we have found a camera, we do not bother to look at the other
62  # Selected models.
63  break
64 
65  # cleanup.
66 
67 # Cleanup everything.
68 del( GetCamera )
69 del( lModelList )
70 del( FBSystem, FBModelList, FBColor, FBGetSelectedModels )