from pyfbsdk import *
import random
SEARCH_MODELS_ONLY = False
def CreateDatas():
""" This function creates dummy datas with namespace"""
FBApplication().FileNew()
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"]
for n in cubenames:
c = FBModelCube("dummy")
c.LongName = n
c.Visible = True
c.Show = True
c.Translation = FBVector3d(random.random()*50, random.random()*50, random.random()*50)
t = FBTexture("texture")
t.LongName = "my text ns:texture of doom"
t = FBTexture("texture")
t.LongName = "my text ns:texture doesn't end with be"
m = FBMaterial("material")
m.LongName = "special ns:material"
def FindWithWildcard(pattern, byShortName):
""" This function finds an object (not just a model)
with a particular pattern in its name.
"""
cl = FBComponentList()
if byShortName:
FBFindObjectsByName( pattern, cl, False, SEARCH_MODELS_ONLY )
else:
FBFindObjectsByName( pattern, cl, True, SEARCH_MODELS_ONLY )
if byShortName:
print len(cl), "objects found matching ShortName pattern", pattern
else:
print len(cl), "objects found matching LongName pattern", pattern
for o in cl:
print " ", o.FullName
CreateDatas()
BY_SHORT_NAME = True
FindWithWildcard( "*", BY_SHORT_NAME )
FindWithWildcard( "ns*", BY_SHORT_NAME )
FindWithWildcard( "*be", BY_SHORT_NAME )
FindWithWildcard( "*Cube*", BY_SHORT_NAME )
FindWithWildcard( "*Cube*be*", BY_SHORT_NAME )
BY_SHORT_NAME = False
FindWithWildcard( "ns*", BY_SHORT_NAME )
FindWithWildcard( "*ns", BY_SHORT_NAME )
FindWithWildcard( "*n*ns*s1", BY_SHORT_NAME )