Python Reference Guide
 
Loading...
Searching...
No Matches
Tasks\AssignRigidBody.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# Assuming a RigidBody properties already exists in a scene, assign it to all selected models.
8#
9#
10# Topic: FBMessageBox, FBGetSelectedModel, FBModel.ConnectSrc
11#
12
13from pyfbsdk import *
14
15def IsConnectedTo(to, toConnect):
16 for i in range(to.GetSrcCount()):
17 if to.GetSrc(i) == toConnect:
18 return True
19 return False
20
21
22def AssignRigidBodyToSelectedModels(rigidBody):
23 # Get the selected models.
24 lModelList = FBModelList()
25 FBGetSelectedModels( lModelList )
26
27 if len( lModelList ) == 0:
28 FBMessageBox( "Message", "Nothing selected", "OK", None, None )
29 else:
30 modifiedmodels = []
31 for model in lModelList:
32 # Ensure that we can assign the same rigidbody only ONCE on a model
33 if not IsConnectedTo(model, rigidBody):
34 model.ConnectSrc(rigidBody)
35 modifiedmodels.append(model)
36
37 lMessage = "Models modified:"
38 lMessage += ''.join( map( lambda pModel: "\n" + pModel.Name, modifiedmodels ))
39 FBMessageBox( "Message", lMessage, "OK", None, None )
40
41
42# check the scene to see if we have a RigidBody
43for p in FBSystem().Scene.PhysicalProperties:
44 if p.ClassName() == "KxL_RigidBodyProperty":
45 # if so: assign this rigid body to all selected models
46 AssignRigidBodyToSelectedModels(p)
47 break
Provides access to the underlying system, and the MotionBuilder scene.
Definition: pyfbsdk_generated.h:18771
FBGetSelectedModels(FBModelList pList, FBModel pParent=None, bool pSelected=True, bool pSortBySelectOrder=False)
Find all models that are selected (if pSelected is true) Searches recursively from a root model for m...
int FBMessageBox(str pBoxTitle, str pMessage, str pButton1Str, str pButton2Str=None, str pButton3Str=None, int pDefaultButton=0, int pScrolledMessage=0)
Dialog popup box.