Skip to content

Instantly share code, notes, and snippets.

@coxevan
Last active September 19, 2017 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coxevan/46d8e95bab3dc73ddf2387f373355925 to your computer and use it in GitHub Desktop.
Save coxevan/46d8e95bab3dc73ddf2387f373355925 to your computer and use it in GitHub Desktop.
'''
Utility methods for getting and setting reference properties ( aka - the blue properties ) in MotionBuilder.
'''
import pyfbsdk
def get_reference_property( obj, prop_name ):
'''
Gets a reference property from an object by name
:param obj: pyfbsdk.FBComponent
:param prop_name: name of the property
:return: prop
'''
prop = obj.PropertyList.Find( str( prop_name ) )
if not prop:
print( "Property '{0}' does not exist on {1]".format( prop_name, obj.LongName ) )
return False
if not prop.IsReferenceProperty( ):
print( "Property '{0}' exists on {1} but is not a reference property".format( prop_name, obj.LongName ) )
return False
return prop
def get_all_reference_properties( obj ):
'''
get all reference properties on an object
:param obj: pyfbsdk.FBComponent
:return: list of properties
'''
reference_properties = [ ]
for prop in obj.PropertyList:
if not prop.IsReferenceProperty():
continue
reference_properties.append( prop )
if not reference_properties:
print( "No reference properties found on {0}".format( obj.LongName ) )
return False
return reference_properties
def get_property_from_reference( prop ):
'''
Get the property that the reference property is connected to.
:param prop: reference property we're querying
:return: pyfbsdk.FBProperty
'''
if not prop.IsReferenceProperty():
print( "{0} is not a reference property".format( prop.Name ) )
return False
return prop.GetSrc( 0 )
def get_reference_property_owner( prop ):
'''
Gets the object that the reference property's property is on.
FBCharacter has a reference property for Collar Stiffness that is technically on the HIK Solver. etc.
:param prop: reference property
:return: pyfbsdk.FBComponent
'''
if not isinstance( prop, pyfbsdk.FBProperty ):
print( "{0} is not a pyfbsdk.FBProperty".format( prop ) )
return False
if not prop.GetSrcCount( ) > 0:
print( "{0} does not have any connections. Is not a valid reference property".format( prop.Name ) )
return prop.GetSrc( 0 ).GetOwner( )
def set_reference_property_on_obj( obj, property_name, value ):
'''
Utility function to set reference properties by name given an object.
:param obj:
:param property_name:
:param value:
:return:
'''
ref_prop = get_reference_property( obj, property_name )
if not isinstance( ref_prop, pyfbsdk.FBProperty ):
return False
return set_reference_property( ref_prop, value )
def set_reference_property( prop, value ):
'''
Utility function to set reference properties given a property
:param property:
:param value:
:return:
'''
obj_prop = get_property_from_reference( prop )
if not obj_prop:
return False
obj_prop.Data = value
return True
if __name__ == '__builtin__':
# Name of our reference property and value we want to set it to
reference_property_name = 'HIK 2016 Solver.Collar Stiffness X'
reference_property_target_value = 100.0
character = pyfbsdk.FBApplication().CurrentCharacter
set_reference_property_on_obj( character,
reference_property_name,
reference_property_target_value )
@coxevan
Copy link
Author

coxevan commented Sep 19, 2017

Edited this after I realized i was using 'property' instead of 'prop' as a variable name. Removed it to not mess with python internals n stuff, but let me know if i didn't catch them all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment