-
-
Save zeffii/3a82a35d1ca20717e35e to your computer and use it in GitHub Desktop.
test
This file contains hidden or 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 HelloVariablePanel(bpy.types.Panel): | |
"""Creates a Panel in the Object properties window""" | |
bl_label = "Hello World Panel" | |
bl_idname = "OBJECT_PT_hello" | |
bl_space_type = 'PROPERTIES' | |
bl_region_type = 'WINDOW' | |
bl_context = "object" | |
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 register(): | |
bpy.utils.register_class(SimpleCallback) | |
bpy.utils.register_class(HelloVariablePanel) | |
bpy.types.Scene.some_value = bpy.props.IntProperty(default=30) | |
def unregister(): | |
del bpy.types.Scene.some_value | |
bpy.utils.unregister_class(HelloVariablePanel) | |
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