-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_x_preset.py
More file actions
65 lines (47 loc) · 1.91 KB
/
Copy pathmove_x_preset.py
File metadata and controls
65 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# SPDX-FileCopyrightText: © 2016 Michel Anders (varkenvarken) & contributors
#
# SPDX-License-Identifier: GPL-2.0-or-later
bl_info = {
"name": "Simple Move X Operator",
"author": "Your Name",
"version": (0, 0, 5),
"blender": (5, 0, 0),
"location": "Object > Move X",
"description": "Move the active object along the X axis (with preset)",
"category": "Object",
}
from bpy.types import Operator
from bpy.props import FloatProperty
# This is literally the same move x operator from the first module
# but with the "PRESET" option added. This will result in a preset
# menu to be shown atop of the amount property when this operator is
# executed, allowing the user to store a value for the amount with
# a given name. This isn´t very useful for a single property, but for
# operators with lots of properties and/or string properties it is.
class OBJECT_OT_move_x(Operator):
bl_idname = "object.move_x"
bl_label = "Move X"
bl_options = {"REGISTER", "UNDO", "PRESET"}
amount: FloatProperty(
name="Amount", description="Amount to move along X axis", default=1.0
) # type: ignore
def execute(self, context):
"""Move the active object by a configurable amount along the x-axis"""
context.active_object.location.x += self.amount
return {"FINISHED"}
@classmethod
def poll(cls, context):
"""Ensure we have an active object and that we are in object mode"""
return context.active_object is not None and context.mode == "OBJECT"
from bpy.utils import register_class, unregister_class
from bpy.types import VIEW3D_MT_object
def menu_func(self, context):
self.layout.operator(OBJECT_OT_move_x.bl_idname)
def register():
register_class(OBJECT_OT_move_x)
VIEW3D_MT_object.append(menu_func)
def unregister():
VIEW3D_MT_object.remove(menu_func)
unregister_class(OBJECT_OT_move_x)
if __name__ == "__main__":
register()