Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created October 24, 2015 12:59
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 zeffii/8fee3bb17ec109f8c5e1 to your computer and use it in GitHub Desktop.
Save zeffii/8fee3bb17ec109f8c5e1 to your computer and use it in GitHub Desktop.
import bpy
class SimpleCallback(bpy.types.Operator):
bl_idname = "object.variable_callback"
bl_label = "Simple Callback"
variable_name = bpy.props.StringProperty()
ops_kind = bpy.props.FloatProperty()
def execute(self, context):
if self.ops_kind in {2.0, 0.5}:
scn = context.scene
current_value = getattr(scn, self.variable_name)
setattr(scn, self.variable_name, int(current_value * self.ops_kind))
return {'FINISHED'}
class HelloVariableOperator(bpy.types.Operator):
"""Creates a Panel in the Object properties window"""
bl_idname = "object.variable_operator"
bl_label = "Simple Variable Operator"
bl_options = {'REGISTER', 'UNDO'}
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
# left
op = row.operator("object.variable_callback", icon="ZOOMOUT", text="")
op.ops_kind = 0.5
op.variable_name = 'some_value'
# middle
scn = bpy.context.scene
print(scn.some_value)
row.prop(scn, "some_value", text='some_value')
# right
op = row.operator("object.variable_callback", icon="ZOOMIN", text="")
op.ops_kind = 2.0
op.variable_name = 'some_value'
def execute(self, context):
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleCallback)
bpy.utils.register_class(HelloVariableOperator)
bpy.types.Scene.some_value = bpy.props.IntProperty(default=30)
def unregister():
del bpy.types.Scene.some_value
bpy.utils.unregister_class(HelloVariableOperator)
bpy.utils.unregister_class(SimpleCallback)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment