BasicOperations/FindPropertiesWithWildcard.py

BasicOperations/FindPropertiesWithWildcard.py
1 # Copyright 2016 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 properties in an object using a name pattern
8 #
9 # Topic: FindPropertiesByName
10 #
11 
12 
13 from pyfbsdk import *
14 
15 import random
16 
17 def CreateDatas():
18 
19  FBApplication().FileNew()
20 
21  c = FBModelCube("dummy")
22  c.Visible = True
23  c.Show = True
24  c.Translation = FBVector3d(random.random()*50, random.random()*50, random.random()*50)
25 
26  return c
27 
28 def FindWithWildcard(cube, pattern, alsoUseUIName):
29  """ This function finds a propery with a particular pattern in its name."""
30 
31  cl = list()
32  cube.PropertyList.FindPropertiesByName( pattern, cl, alsoUseUIName )
33 
34  if alsoUseUIName:
35  print len(cl), "properties found with internal/UI name matching the pattern: \"" + pattern + "\""
36  else:
37  print len(cl), "properties found with internal name matching the pattern: \"" + pattern + "\""
38 
39  for o in cl:
40  print " ", o.GetName()
41 
42 cube = CreateDatas()
43 
44 # Pattern description:
45 # Currently our patterns only support *
46 # you can have as many * in you pattern
47 # the * is good for as much character as you like.
48 
49 # Find all properties whose name matches the pattern
50 FindWithWildcard( cube, "*", True ) #will find all properties
51 
52 FindWithWildcard( cube, "*Negative *", True ) #will try to find properties that contain "Negative " in its internal/UI name.
53  #UI name is "Negative Shape Value" for "NegativePercentShapeSupport"
54 FindWithWildcard( cube, "*Negative *", False ) #will try to find properties that contain "Negative " in its internal name only
55 
56 FindWithWildcard( cube, "Trans*", True ) #will try to find properties that start with "Trans" in the internal/UI name
57 FindWithWildcard( cube, "*Trans", False ) #will try to find properties that end with "Trans" in its internal name only
58 FindWithWildcard( cube, "*Trans*", False ) #will try to find properties that contain "Trans" in its internal name only