I am updating the active object's location.x with a FloatProperty with the following code.
How can I change the value of the FloatProperty slider to the active_object's current location.x when the active_object changes?
Thank you!
import bpy
class SomePanel( bpy.types.Panel ):
bl_label = "Property panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
layout = self.layout
scn = context.scene
layout.prop( scn, 'someValue' )
def whenUpdate( self, context ):
if context.active_object:
context.active_object.location.x = self.someValue
print( 'update', self.someValue )
def register():
bpy.types.Scene.someValue = bpy.props.FloatProperty(
name = "Float",
description = "Enter a float", min = -100, max = 100,
update = whenUpdate ) #Assign the update function here
bpy.utils.register_class(SomePanel)
def unregister():
bpy.utils.unregister_class(SomePanel)
del bpy.types.Scene.someValue
if __name__ == "__main__":
register()
someValue
variable and theactive_object
from there? $\endgroup$