Python Reference Guide
 
Loading...
Searching...
No Matches
BasicOperations\CustomProperty.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# Create custom properties and attached them to all selected models.
8#
9# Topic: FBPropertyType, FBProperty
10#
11
12from pyfbsdk import *
13
14# Create an empty FBModelList object.
15lModels = FBModelList()
16
17# Obtain the list of selected models.
19
20# List of Properties to create
21
22lProperty = (('My Integer', FBPropertyType.kFBPT_int, 'Integer', True, True, None),
23 ('My Bool', FBPropertyType.kFBPT_bool, 'Bool', True, True, None),
24 ('My Float', FBPropertyType.kFBPT_float, 'Float', False, True, None), # Not animatable
25 ('My Double', FBPropertyType.kFBPT_double, 'Number',True, True, None),
26 ('My Chrptr', FBPropertyType.kFBPT_charptr, 'String', False, True, None), # Not animatable
27 ('My Enum', FBPropertyType.kFBPT_enum, 'Enum', True, True, None),
28 ('My Time', FBPropertyType.kFBPT_Time, 'Time', True, True, None),
29 ('My Obj', FBPropertyType.kFBPT_object, 'Object', False, True, None ), # Not animatable
30 ('My Stringlist', FBPropertyType.kFBPT_stringlist, 'StringList', False, True, None), # Not animatable
31 ('My Vector4D', FBPropertyType.kFBPT_Vector4D, 'Vector4', True, True, None),
32 ('My Vector3D', FBPropertyType.kFBPT_Vector3D, 'Vector', True, True, None),
33 ('My Vector2D', FBPropertyType.kFBPT_Vector2D, 'Vector2', True, True, None),
34 ('My Colour', FBPropertyType.kFBPT_ColorRGB, 'Color', True, True, None),
35 ('My ColourAndAlpha', FBPropertyType.kFBPT_ColorRGBA, 'ColorAndAlpha', True, True, None),
36 ('My Action', FBPropertyType.kFBPT_Action, 'Action', True, True, None),
37 ('My TimeSpan', FBPropertyType.kFBPT_TimeSpan, 'Time', False, True, None), # Not animatable
38 )
39
40# Explanation of property syntax
41
42# Parameters:
43# pName - The name of the property.
44# pType - Type of the property see enum FBPropertyType.
45# pDataType - DataType of the property is a text define in ANIMATIONNODE_TYPE_??? in fbdata.h.
46# pAnimatable - To specify if the property can be animated.
47# pIsUser - To specify if the property is available as a custom property or dynamic and attached to the object.
48# pReferenceSource - Use that param to specify the property that a reference refer to.
49
50# check if there is a selection
51if len( lModels ) == 0:
52 FBMessageBox( "Message", "Nothing selected", "OK", None, None )
53
54else:
55
56 # Create a FBProgress object and set default values for the caption and text.
57 lFbp = FBProgress()
58 lFbp.Caption = "CREATING CUSTOM PROPERTIES"
59 lFbp.Text = "yay !"
60 lCount = 0.0
61
62 # Create custom properties
63 for x in lModels:
64
65 for ( pName, pType, pDataType,pAnimatable, pIsUser, pReferenceSource ) in lProperty:
66 prop = x.PropertyCreate( pName, pType, pDataType, pAnimatable, pIsUser, pReferenceSource )
67 if prop == None:
68 print("NoneObj:"+pName+","+str(pType))
69 else:
70 print(prop.GetName()+prop.GetPropertyTypeName())
71 # set values for 'My Integer'
72 lProp = x.PropertyList.Find('My Integer')
73 lProp.SetMin(-100)
74 lProp.SetMax(100)
75 lProp.Data = 10
76 lProp.SetAnimated(True)
77
78 # set values for 'My Bool'
79 lProp = x.PropertyList.Find('My Bool')
80 lProp.Data = False
81 lProp.SetAnimated(True)
82
83 # set values for 'My Double'
84 lProp = x.PropertyList.Find('My Double')
85 lProp.SetMin(-100)
86 lProp.SetMax(100)
87 lProp.Data = 2.2
88 # SetAnimated exposes the property to the relations constraint
89 lProp.SetAnimated(True)
90
91 # set value for 'My Chrptr'
92 lProp= x.PropertyList.Find('My ChrPtr')
93 lProp.Data = "TestThis!"
94
95 # set value for 'My Enum'
96 lProp= x.PropertyList.Find('My Enum')
97 lEnumList = lProp.GetEnumStringList(True) #Get Enum StringList and add new item.
98 lEnumList.Add("Test1")
99 lEnumList.Add("Test2")
100 lEnumList.Add("Test3")
101 lProp.NotifyEnumStringListChanged() #Notify change, to let it take effect.
102
103 # set value for 'My Time '
104 lProp= x.PropertyList.Find('My Time')
105 lProp.Data = FBTime(0,0,1,1)
106 lProp.SetAnimated =True
107
108 # set values for 'My Vector3D'
109 lProp = x.PropertyList.Find('My Vector3D')
110 lVector = FBVector3d(90,20,-70)
111 lProp.Data = lVector
112 lProp.SetAnimated(True)
113
114 # set values for 'My Vector4D'
115 lProp = x.PropertyList.Find('My Vector4D')
116 lVector = FBVector4d(90,20,-70,60)
117 lProp.Data = lVector
118 lProp.SetAnimated(True)
119
120 # set values for 'My Colour '
121 lProp = x.PropertyList.Find('My Colour')
122 lColour = FBColor(0,0,1)
123 lProp.Data = lColour
124 lProp.SetAnimated(True)
125
126 # set values for 'My ColourAndAlpha '
127 lProp = x.PropertyList.Find('My ColourAndAlpha')
128 lColour = FBColorAndAlpha(0,1,0,0.5)
129
130 lProp.SetAnimated(True)
131
132 # set values for 'My Action '
133 lProp = x.PropertyList.Find('My Action')
134 lProp.SetAnimated(True)
135
136 # set values for 'My Bool '
137 lProp = x.PropertyList.Find('My Bool')
138 lProp.Data = True
139 lProp.SetAnimated(True)
140
141 # set values for 'My Integer '
142 lProp = x.PropertyList.Find('My Integer')
143 lProp.SetMin(0)
144 lProp.SetMax(100)
145 lProp.Data = 0
146 lProp.SetAnimated(True)
147
148 lCount += 1
149 lVal = lCount / len(lModels) * 100
150 lFbp.Percent = int(lVal)
151
152 # We must call FBDelete when the FBProgress object is no longer needed.
153 lFbp.FBDelete()
154
155
156
157
158
159
160
161
162
Color and alpha vector.
Definition: pyfbsdk_generated.h:4497
Color vector.
Definition: pyfbsdk_generated.h:4470
Progress bar.b>Property: Base property class.
Definition: pyfbsdk_generated.h:14666
Time data structure.
Definition: pyfbsdk_generated.h:19596
Python built-in int class.
Definition: pyfbsdk.h:59
Python built-in string class.
Definition: pyfbsdk.h:77
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.