-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_icons_blender.template
188 lines (146 loc) · 5.38 KB
/
simple_icons_blender.template
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import math
import os
import string
import tempfile
import bpy
from io_curve_svg.import_svg import load as import_svg_file
bl_info = {
"name": "Simple Icons",
"description": "Blender Simple Icons add-on",
"author": "mondeja",
"license": "BSD-3-Clause",
"category": "Add Curve",
"version": (13, 16, 0),
"blender": (2, 93, 0),
"support": "COMMUNITY",
}
class BlenderVersionError(Exception):
pass
if bl_info["blender"] > bpy.app.version:
raise BlenderVersionError(f"This addon requires Blender >= {bl_info['blender']}")
# -----------------------------------------------
class AddSi:
def execute(self, context):
simple_icons_blender_tempdir = os.path.join(
tempfile.gettempdir(), "simple-icons-blender",
)
if not os.path.isdir(simple_icons_blender_tempdir):
os.mkdir(simple_icons_blender_tempdir)
temp_filepath = os.path.join(
simple_icons_blender_tempdir, self.bl_label.replace(os.sep, "-"),
)
if not os.path.isfile(temp_filepath):
with open(temp_filepath, "w") as f:
f.write(self.si_svg)
import_svg_file(self, context, temp_filepath)
context.view_layer.objects.active = context.scene.objects[-1]
context.scene.objects[-1].select_set(True)
return {"FINISHED"}
A = AddSi
O = bpy.types.Operator
%(simple_icons_classes)s
G = globals()
SI_CLASSES = [G[object_name] for object_name in G if object_name.startswith("AddSi_")]
PAGINATION_SUBMENUS = %(letter_submenus_array)s
# ------------------------------------------------
# Menu and operators
class VIEW3D_MT_simple_icons_add(bpy.types.Menu):
# Define the "Simple Icons" menu
bl_idname = "VIEW3D_MT_simple_icons_add"
bl_label = "Simple Icons"
def draw(self, context):
for submenu in PAGINATION_SUBMENUS:
self.layout.menu("VIEW3D_MT_simple_icons_add_" + submenu + "_submenu")
class VIEW3D_MT_simple_icons_add_letter_submenu(bpy.types.Menu):
def draw(self, context):
for cls in SI_CLASSES:
if cls.bl_label[0].upper() == self.bl_label:
self.layout.operator(cls.bl_idname, text=cls.bl_label)
LS = VIEW3D_MT_simple_icons_add_letter_submenu
class VIEW3D_MT_simple_icons_add_symbol_submenu(bpy.types.Menu):
bl_idname = "VIEW3D_MT_simple_icons_add_symbol_submenu"
bl_label = "#"
def draw(self, context):
for cls in SI_CLASSES:
if cls.bl_label[0].upper() not in string.ascii_uppercase:
self.layout.operator(cls.bl_idname, text=cls.bl_label)
%(letter_submenu_classes)s
def menu_func(self, context):
self.layout.separator()
self.layout.menu("VIEW3D_MT_simple_icons_add",
text="Simple Icons", icon="CURVE_DATA")
def register():
for cls in SI_CLASSES:
bpy.utils.register_class(cls)
bpy.utils.register_class(VIEW3D_MT_simple_icons_add)
for submenu in PAGINATION_SUBMENUS:
bpy.utils.register_class(G["VIEW3D_MT_simple_icons_add_" + submenu + "_submenu"])
bpy.types.VIEW3D_MT_curve_add.append(menu_func)
register_panel()
def unregister():
bpy.types.VIEW3D_MT_curve_add.remove(menu_func)
for submenu in PAGINATION_SUBMENUS:
bpy.utils.unregister_class(G["VIEW3D_MT_simple_icons_add_" + submenu + "_submenu"])
for cls in SI_CLASSES:
bpy.utils.unregister_class(cls);
bpy.utils.unregister_class(VIEW3D_MT_simple_icons_add)
unregister_panel()
# ------------------------------------------------
# Add icon panel
def transform_simple_icon(self, context):
obj = context.active_object
scale = context.scene.simple_icon_scale * 10
rot_x, rot_y, rot_z = context.scene.simple_icon_rotation
obj.scale = [scale, scale, 1]
obj.location = context.scene.simple_icon_location
obj.rotation_euler = [
math.radians(rot_x),
math.radians(rot_y),
math.radians(rot_z),
]
class AddSimpleTransformPanel(bpy.types.Panel):
"""Creates a Panel in the 3D Viewport N Panel"""
bl_label = "Simple transform"
bl_idname = "OBJECT_PT_add_simple_transform_panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_options = set()
bl_category = "Item"
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(context.scene, "simple_icon_scale")
row = layout.row()
row.prop(context.scene, "simple_icon_location")
row = layout.row()
row.prop(context.scene, "simple_icon_rotation")
@classmethod
def poll(cls, context):
return context.active_object.type == "CURVE"
def register_panel():
bpy.types.Scene.simple_icon_scale = bpy.props.IntProperty(
name="Scale",
min=0,
default=1,
update=transform_simple_icon,
)
bpy.types.Scene.simple_icon_location = bpy.props.FloatVectorProperty(
name="Location",
default=(0, 0, 0),
update=transform_simple_icon,
)
bpy.types.Scene.simple_icon_rotation = bpy.props.FloatVectorProperty(
name="Rotation",
min=-360,
max=360,
default=(0, 0, 0),
update=transform_simple_icon,
)
bpy.utils.register_class(AddSimpleTransformPanel)
def unregister_panel():
del bpy.types.Scene.simple_icon_scale
del bpy.types.Scene.simple_icon_location
del bpy.types.Scene.simple_icon_rotation
bpy.utils.unregister_class(AddSimpleTransformPanel)
if __name__ == "__main__":
register()