-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_star_basic.py
More file actions
101 lines (77 loc) · 2.6 KB
/
Copy pathadd_star_basic.py
File metadata and controls
101 lines (77 loc) · 2.6 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# SPDX-FileCopyrightText: © 2016 Michel Anders (varkenvarken) & contributors
#
# SPDX-License-Identifier: GPL-2.0-or-later
bl_info = {
"name": "Star",
"author": "Your Name",
"version": (0, 0, 1),
"blender": (5, 0, 0),
"location": "Object > Add",
"description": "Add a star shaped mesh to the scene",
"category": "Object",
}
import bpy
from bpy.types import Operator
from bpy.props import IntProperty, FloatProperty
# help function to check that that the outer radius is
# always larger than the inner radius.
# Note that the comparisons are strict, i.e. do NOT
# check for equality to prevent infinite recursion!
def update_outer_radius(self, context):
"""make sure outer radius > inner radius"""
if self.inner_radius > self.outer_radius:
self.outer_radius = self.inner_radius
def update_inner_radius(self, context):
"""make sure inner radius <= outer radius"""
if self.outer_radius < self.inner_radius:
self.inner_radius = self.outer_radius
class OBJECT_OT_add_star(Operator):
bl_idname = "object.add_star"
bl_label = "Add star"
bl_description = "Add a star shaped mesh to the scene"
bl_options = {"REGISTER", "UNDO"}
points: IntProperty(
name="Points",
description="Number of points on the star",
default=5,
min=3,
soft_max=20,
)
inner_radius: FloatProperty(
name="Inner radius",
description="Distance from center to indented vertices",
default=1.0,
min=0.0,
update=update_outer_radius,
)
outer_radius: FloatProperty(
name="Outer radius",
description="Distance from center to point tips",
default=1.5,
min=0.0,
update=update_inner_radius,
)
def execute(self, context):
"""A dummy method"""
return {"FINISHED"}
@classmethod
def poll(cls, context):
return context.mode == "OBJECT"
# Note: best practice is to put all imports at the beginning
# but we want make a clear distinction between operator
# implementation and registration.
from bpy.utils import register_class, unregister_class
from bpy.types import VIEW3D_MT_add
def menu_func(self, context):
"""Add the star operator to the Add menu."""
self.layout.operator(OBJECT_OT_add_star.bl_idname)
def register():
"""Register the add-on classes and menu."""
register_class(OBJECT_OT_add_star)
VIEW3D_MT_add.append(menu_func)
def unregister():
"""Unregister the add-on classes and menu."""
VIEW3D_MT_add.remove(menu_func)
unregister_class(OBJECT_OT_add_star)
if __name__ == "__main__":
register()