BasicOperations/RigiBody.py

BasicOperations/RigiBody.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 # Change the PhysicalProperties (RigiBody) of all selected models.
8 #
9 # Topic: FBPhysicalProperties
10 #
11 
12 from pyfbsdk import *
13 
14 def ListObjectProperties(o):
15  print "ObjectName: " + o.Name
16  for each in o.PropertyList:
17  print each.Name + " "
18 
19 def ChangeRigidBody (obj, propertyName, newValue):
20  for i in range (obj.GetSrcCount()):
21  o = obj.GetSrc(i)
22  if isinstance(o, FBPhysicalProperties):
23  p = o.PropertyList.Find(propertyName)
24  if p:
25  p.Data = newValue
26 
27 def SetRigidBodyState():
28 
29  lModelList = FBModelList()
30 
31  # Get the selected models.
32  FBGetSelectedModels( lModelList )
33 
34  if len( lModelList ) == 0:
35  FBMessageBox( "Message", "Nothing selected", "OK", None, None )
36  else:
37  for each in lModelList:
38  ChangeRigidBody ( each, "Bounce", 0.1 )
39  ChangeRigidBody ( each, "Density", 0.5 )
40 
41  lMessage = "Models modified:"
42  lMessage += ''.join( map( lambda pModel: "\n" + pModel.Name, lModelList ))
43  FBMessageBox( "Message", lMessage, "OK", None, None )
44 
45 SetRigidBodyState()