Created
October 24, 2015 12:59
-
-
Save zeffii/8fee3bb17ec109f8c5e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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