Python Reference Guide
 
Loading...
Searching...
No Matches
BasicOperations\FindObjectsWithWildcard.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# Shows new function to find objects with name pattern
8#
9# Topic: FBFindObjectsByName
10#
11
12
13from pyfbsdk import *
14
15import random
16
17# constant
18SEARCH_MODELS_ONLY = False
19
20def CreateDatas():
21 """ This function creates dummy datas with namespace"""
22
23 FBApplication().FileNew()
24
25 cubenames = ["ns:Cube", "ns:Cube is a troubled cube", "ns:ns1:My Cube of Doom", "ns:this is a ns:ns1:Cube", "Cube ends with be"]
26
27 for n in cubenames:
28 c = FBModelCube("dummy")
29 c.LongName = n
30 c.Visible = True
31 c.Show = True
32 c.Translation = FBVector3d(random.random()*50, random.random()*50, random.random()*50)
33
34 t = FBTexture("texture")
35 t.LongName = "my text ns:texture of doom"
36
37 t = FBTexture("texture")
38 t.LongName = "my text ns:texture doesn't end with be"
39
40 m = FBMaterial("material")
41 m.LongName = "special ns:material"
42
43
44def FindWithWildcard(pattern, byShortName):
45 """ This function finds an object (not just a model)
46 with a particular pattern in its name.
47 """
48
49 cl = FBComponentList()
50 if byShortName:
51 # First param is a pattern
52 # second param is a boolean saying if the search must be made in LongName (including namespace)
53 # third param is a boolean. If True: we search for models only, if False, we search for all objects
54 # including textures, materials, etc...
55 FBFindObjectsByName( pattern, cl, False, SEARCH_MODELS_ONLY )
56 else:
57 # This function search objects by including their namespace part (called LabelName, or LongName)
58 FBFindObjectsByName( pattern, cl, True, SEARCH_MODELS_ONLY )
59
60 if byShortName:
61 print(len(cl), "objects found matching ShortName pattern: \"" + pattern + "\"")
62 else:
63 print(len(cl), "objects found matching LongName pattern: \"" + pattern + "\"")
64
65 for o in cl:
66 print(" ", o.FullName)
67
68CreateDatas()
69
70# Pattern description:
71# Currently our patterns only support *
72# you can have as many * in you pattern
73# the * is good for as much character as you like.
74
75BY_SHORT_NAME = True
76# Find all objects whose name arbitrarily, match for all
77FindWithWildcard( "*", BY_SHORT_NAME )
78
79# Find all objects whose short name begins with "ns"
80FindWithWildcard( "ns*", BY_SHORT_NAME )
81
82# Find all objects whose short name ends with "be"
83FindWithWildcard( "*be", BY_SHORT_NAME )
84
85# Find all objects whose short name contains "Cube"
86FindWithWildcard( "*Cube*", BY_SHORT_NAME )
87
88# Find all objects whose short name contains token: "Cube" and "be" in this order
89FindWithWildcard( "*Cube*be*", BY_SHORT_NAME )
90
91BY_SHORT_NAME = False
92
93# find all objects whose long name begins with "ns"
94FindWithWildcard( "ns*", BY_SHORT_NAME )
95
96# find all objects whose long name ends with "ns"
97FindWithWildcard( "*ns", BY_SHORT_NAME )
98
99# Find all objects whose long name contains tokens: "n", "ns" and "s1" in this order
100FindWithWildcard( "*n*ns*s1", BY_SHORT_NAME )
FBApplication is used mainly to manage files.
Definition: pyfbsdk_generated.h:801
Material class.
Definition: pyfbsdk_generated.h:10458
Cube model class.
Definition: pyfbsdk_generated.h:11337
See samples: HUDElements.py, MaterialAndTexture.py, TextureAnimation.py, VideoInput....
Definition: pyfbsdk_generated.h:19477
FBFindObjectsByName(str pNamePattern, FBComponentList pList, bool pIncludeNamespace=True, bool pModelsOnly=False)
FBFindObjectsByName.