-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext_generator.py
138 lines (105 loc) · 3.89 KB
/
text_generator.py
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
import bpy
import os
import string
bl_info = {
"name": "3D Text Generator",
"author": "Matthew Hillier",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D > Add > Mesh > New Object",
"description": "Generates 3D models from text",
"warning": "",
"doc_url": "",
"category": "Add Mesh",
}
def generate_buttton(context):
custom_chars = ['10', '11', '12', '13', '14', '15', '16',
'17', '18', '19', 'Catan', 'TotallyNotCatan', 'Matthew', 'SaxOps1']
all_chars = list(string.ascii_uppercase) + \
list(string.digits) + custom_chars
chars_collection = bpy.data.collections.new("All Chars")
bpy.context.scene.collection.children.link(chars_collection)
for i in all_chars:
char_name = "char-" + i
font_curve = bpy.data.curves.new(type="FONT", name="font_curve: " + i)
font_curve.body = i
font_curve.extrude = 0.05
font_curve.font = bpy.data.fonts.load('C:\\Windows\\Fonts\\GARA.ttf')
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
font_curve.align_x = 'CENTER'
font_curve.align_y = 'CENTER'
font_obj = bpy.data.objects.new(char_name, font_curve)
bpy.data.collections['All Chars'].objects.link(font_obj)
objectToSelect = bpy.data.objects[char_name]
objectToSelect.select_set(True)
bpy.context.view_layer.objects.active = objectToSelect
bpy.ops.object.convert(target='MESH')
class TextGenerator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "3dtextgen.generate_text"
bl_label = "Generate Text"
def execute(self, context):
generate_buttton(context)
return {'FINISHED'}
def clear_buttton(context):
bpy.ops.object.select_all()
bpy.ops.object.select_all()
bpy.ops.object.delete(use_global=False)
for c in bpy.data.collections:
bpy.data.collections.remove(c)
class RemoveAll(bpy.types.Operator):
"""Tooltip"""
bl_idname = "3dtextgen.remove_all"
bl_label = "DELETE EVERYTHING!"
def execute(self, context):
clear_buttton(context)
return {'FINISHED'}
def export_all_obj(exportFolder):
objects = bpy.data.objects
for object in objects:
bpy.ops.object.select_all(action='DESELECT')
object.select_set(state=True)
exportName = exportFolder + object.name + '.obj'
bpy.ops.export_scene.obj(filepath=exportName, use_selection=True)
class ExportAll(bpy.types.Operator):
"""Tooltip"""
bl_idname = "3dtextgen.export_all"
bl_label = "Export all chars to .obj"
def execute(self, context):
output_path = 'C:\\Users\\Matthew\\Desktop\\Blender\\3DText\\'
export_all_obj(output_path)
return {'FINISHED'}
class LayoutDemoPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "3D Text Generator"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
layout.label(text="Empty Scene")
row = layout.row()
row.scale_y = 1.5
row.operator("3dtextgen.remove_all")
layout.label(text="Text Generator")
row = layout.row()
row.scale_y = 1.5
row.operator("3dtextgen.generate_text")
layout.label(text="Export chars")
row = layout.row()
row.scale_y = 1.5
row.operator("3dtextgen.export_all")
def register():
bpy.utils.register_class(TextGenerator)
bpy.utils.register_class(LayoutDemoPanel)
bpy.utils.register_class(RemoveAll)
bpy.utils.register_class(ExportAll)
def unregister():
bpy.utils.unregister_class(LayoutDemoPanel)
bpy.utils.unregister_class(TextGenerator)
bpy.utils.unregister_class(RemoveAll)
bpy.utils.unregister_class(ExportAll)
if __name__ == "__main__":
register()