Tasks/SelectModelsWithNameContainingSubstring.py

Tasks/SelectModelsWithNameContainingSubstring.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, FBPopupInputType, FBModelRoot, FBScene
7 #
8 from pyfbsdk import FBSystem, FBMessageBoxGetUserValue, FBPopupInputType
9 
10 # This recursive function selects the children that match the pattern and
11 # calls itself to inspect the whole hierarchy.
12 def SelectModels( pRoot, pPattern ):
13 
14  # Insure that we have a valid root and pattern.
15  if pRoot and pPattern:
16 
17  # For each children, tag it if necessary and see its own children.
18  for lChild in pRoot.Children:
19 
20  # If the pattern is not found, -1 is returned. Any other values
21  # means success.
22  if lChild.Name.find( pPattern ) != -1:
23  lChild.Selected = True
24 
25  # Recurse.
26  SelectModels( lChild, pPattern )
27 
28 # Get the substring that we want to match in the model name.
29 (lRes, lPattern ) = FBMessageBoxGetUserValue( "Enter pattern", "Enter pattern of model name to select: ", "Cube", FBPopupInputType.kFBPopupString, "OK", "Cancel" )
30 
31 # Insure that the pattern is valid (i.e. not None) and that the user clicked
32 # on the "OK" button.
33 if lPattern and lRes == 1:
34 
35  # Get the scene from the system.
36  lScene = FBSystem().Scene
37 
38  # Start the search.
39  SelectModels( lScene.RootModel, lPattern )
40 
41  # Cleanup.
42  del( lScene )
43 
44 
45 # Cleanup.
46 
47 # Cleanup local variables.
48 del( lRes, lPattern )
49 
50 # Cleanup local functions.
51 del( SelectModels )
52 
53 # Cleanup things from pyfbsdk.
54 del( FBSystem, FBMessageBoxGetUserValue, FBPopupInputType )