# Copyright 2009 Autodesk, Inc. All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Create custom properties and attached them to all selected models.
#
# Topic: FBPropertyType, FBProperty
#
from pyfbsdk import *
# Create an empty FBModelList object.
lModels = FBModelList()
# Obtain the list of selected models.
FBGetSelectedModels(lModels)
# List of Properties to create
lProperty = (('My Integer', FBPropertyType.kFBPT_int, 'Integer', True, True, None),
('My Bool', FBPropertyType.kFBPT_bool, 'Bool', True, True, None),
('My Float', FBPropertyType.kFBPT_float, 'Float', False, True, None), # Not animatable
('My Double', FBPropertyType.kFBPT_double, 'Number',True, True, None),
('My Chrptr', FBPropertyType.kFBPT_charptr, 'String', False, True, None), # Not animatable
('My Enum', FBPropertyType.kFBPT_enum, 'Enum', True, True, None),
('My Time', FBPropertyType.kFBPT_Time, 'Time', True, True, None),
('My Obj', FBPropertyType.kFBPT_object, 'Object', False, True, None ), # Not animatable
('My Stringlist', FBPropertyType.kFBPT_stringlist, 'StringList', False, True, None), # Not animatable
('My Vector4D', FBPropertyType.kFBPT_Vector4D, 'Vector4', True, True, None),
('My Vector3D', FBPropertyType.kFBPT_Vector3D, 'Vector', True, True, None),
('My Vector2D', FBPropertyType.kFBPT_Vector2D, 'Vector2', True, True, None),
('My Colour', FBPropertyType.kFBPT_ColorRGB, 'Color', True, True, None),
('My ColourAndAlpha', FBPropertyType.kFBPT_ColorRGBA, 'ColorAndAlpha', True, True, None),
('My Action', FBPropertyType.kFBPT_Action, 'Action', True, True, None),
('My TimeSpan', FBPropertyType.kFBPT_TimeSpan, 'Time', False, True, None), # Not animatable
)
# Explanation of property syntax
# Parameters:
# pName - The name of the property.
# pType - Type of the property see enum FBPropertyType.
# pDataType - DataType of the property is a text define in ANIMATIONNODE_TYPE_??? in fbdata.h.
# pAnimatable - To specify if the property can be animated.
# pIsUser - To specify if the property is available as a custom property or dynamic and attached to the object.
# pReferenceSource - Use that param to specify the property that a reference refer to.
# check if there is a selection
if len( lModels ) == 0:
FBMessageBox( "Message", "Nothing selected", "OK", None, None )
else:
# Create a FBProgress object and set default values for the caption and text.
lFbp = FBProgress()
lFbp.Caption = "CREATING CUSTOM PROPERTIES"
lFbp.Text = "yay !"
lCount = 0.0
# Create custom properties
for x in lModels:
for ( pName, pType, pDataType,pAnimatable, pIsUser, pReferenceSource ) in lProperty:
prop = x.PropertyCreate( pName, pType, pDataType, pAnimatable, pIsUser, pReferenceSource )
if prop == None:
print("NoneObj:"+pName+","+str(pType))
else:
print(prop.GetName()+prop.GetPropertyTypeName())
# set values for 'My Integer'
lProp = x.PropertyList.Find('My Integer')### marche po
lProp.SetMin(-100)
lProp.SetMax(100)
lProp.Data = 10
lProp.SetAnimated(True)
# set values for 'My Bool'
lProp = x.PropertyList.Find('My Bool')
lProp.Data = False
lProp.SetAnimated(True)
# set values for 'My Double'
lProp = x.PropertyList.Find('My Double')
lProp.SetMin(-100)
lProp.SetMax(100)
lProp.Data = 2.2
# SetAnimated exposes the property to the relations constraint
lProp.SetAnimated(True)
# set value for 'My Chrptr'
lProp= x.PropertyList.Find('My ChrPtr')
lProp.Data = "TestThis!"
# set value for 'My Enum'
lProp= x.PropertyList.Find('My Enum')
lEnumList = lProp.GetEnumStringList(True) #Get Enum StringList and add new item.
lEnumList.Add("Test1")
lEnumList.Add("Test2")
lEnumList.Add("Test3")
lProp.NotifyEnumStringListChanged() #Notify change, to let it take effect.
# set value for 'My Time '
lProp= x.PropertyList.Find('My Time')
lProp.Data = FBTime(0,0,1,1)
lProp.SetAnimated =True
# set values for 'My Vector3D'
lProp = x.PropertyList.Find('My Vector3D')
lVector = FBVector3d(90,20,-70)
lProp.Data = lVector
lProp.SetAnimated(True)
# set values for 'My Vector4D'
lProp = x.PropertyList.Find('My Vector4D')
lVector = FBVector4d(90,20,-70,60)
lProp.Data = lVector
lProp.SetAnimated(True)
# set values for 'My Colour '
lProp = x.PropertyList.Find('My Colour')
lColour = FBColor(0,0,1)
lProp.Data = lColour
lProp.SetAnimated(True)
# set values for 'My ColourAndAlpha '
lProp = x.PropertyList.Find('My ColourAndAlpha')
lColour = FBColorAndAlpha(0,1,0,0.5)
##lProp.Data = lColour
lProp.SetAnimated(True)
# set values for 'My Action '
lProp = x.PropertyList.Find('My Action')
lProp.SetAnimated(True)
# set values for 'My Bool '
lProp = x.PropertyList.Find('My Bool')
lProp.Data = True
lProp.SetAnimated(True)
# set values for 'My Integer '
lProp = x.PropertyList.Find('My Integer')
lProp.SetMin(0)
lProp.SetMax(100)
lProp.Data = 0
lProp.SetAnimated(True)
lCount += 1
lVal = lCount / len(lModels) * 100
lFbp.Percent = int(lVal)
# We must call FBDelete when the FBProgress object is no longer needed.
lFbp.FBDelete()
发布日期:
2024-05-10
文章字数:
695
阅读时长:
4 分
评论