# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Change the PhysicalProperties (RigiBody) of all selected models.
#
# Topic: FBPhysicalProperties
#

from pyfbsdk import *

def ListObjectProperties(o):
    print "ObjectName: " + o.Name
    for each in o.PropertyList:
        print each.Name + " "

def ChangeRigidBody (obj, propertyName, newValue):
    for i in range (obj.GetSrcCount()):
        o = obj.GetSrc(i)
        if isinstance(o, FBPhysicalProperties):
            p = o.PropertyList.Find(propertyName)
            if p:
                p.Data = newValue

def SetRigidBodyState():

    lModelList = FBModelList()

    # Get the selected models.
    FBGetSelectedModels( lModelList )

    if len( lModelList ) == 0:
        FBMessageBox( "Message", "Nothing selected", "OK", None, None )
    else:
        for each in lModelList:
            ChangeRigidBody ( each, "Bounce", 0.1 )
            ChangeRigidBody ( each, "Density", 0.5 )

        lMessage = "Models modified:"
        lMessage += ''.join( map( lambda pModel: "\n" + pModel.Name, lModelList ))
        FBMessageBox( "Message", lMessage, "OK", None, None )

SetRigidBodyState()