-
Notifications
You must be signed in to change notification settings - Fork 40
/
quick_pipe.py
133 lines (100 loc) · 3.86 KB
/
quick_pipe.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
import bpy
import bmesh
import math
import mathutils as mathu
from bpy.props import (
IntProperty,
FloatProperty
)
bl_info = {
"name": "Quick Pipe",
"author": "floatvoid (Jeremy Mitchell), Pavel Geraskin",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D > Edit Mode",
"description": "Quickly converts an edge selection to an extruded curve.",
"warning": "",
"wiki_url": "",
"category": "View3D"}
class jmPipeTool(bpy.types.Operator):
bl_idname = "object.quickpipe"
bl_label = "Quick Pipe"
bl_options = {'REGISTER', 'UNDO'}
first_mouse_x : IntProperty()
first_value : FloatProperty()
def modal(self, context, event):
if event.type in {'RIGHTMOUSE', 'ESC', 'LEFTMOUSE'}:
return {'FINISHED'}
if event.type == 'MOUSEMOVE':
delta = (self.first_mouse_x - event.mouse_x)
if event.ctrl:
delta *= 0.1
if event.shift:
delta *= 0.1
context.object.data.bevel_depth = abs( (self.first_value + delta) * 0.01 )
elif event.type == 'WHEELUPMOUSE':
bpy.context.object.data.bevel_resolution += 1
elif event.type == 'WHEELDOWNMOUSE':
if bpy.context.object.data.bevel_resolution > 0:
bpy.context.object.data.bevel_resolution -= 1
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.object:
if( context.object.type == 'MESH' ):
self.first_mouse_x = event.mouse_x
bpy.ops.mesh.duplicate_move()
bpy.ops.mesh.separate(type='SELECTED')
bpy.ops.object.editmode_toggle()
#pipe = context.view_layer.objects[-1]
pipe = context.selected_objects[-1]
bpy.ops.object.select_all(action='DESELECT')
pipe.select_set(state=True)
context.view_layer.objects.active = pipe
bpy.ops.object.convert(target='CURVE')
pipe.data.fill_mode = 'FULL'
pipe.data.splines[0].use_smooth = True
pipe.data.bevel_resolution = 1
pipe.data.bevel_depth = 0.1
elif( context.object.type == 'CURVE' ):
self.report({'WARNING'}, "Need Edit Mode!")
return {'CANCELLED'}
self.first_value = pipe.data.bevel_depth
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "No active object, could not finish")
return {'CANCELLED'}
#class VIEW3D_PT_tools_jmPipeTool(bpy.types.Panel):
#bl_label = "Quick Pipe"
#bl_space_type = 'VIEW_3D'
#bl_region_type = 'TOOLS'
#bl_category = 'Tools'
#bl_context = "mesh_edit"
#bl_options = {'DEFAULT_CLOSED'}
#def draw(self, context):
#layout = self.layout
#row = layout.row()
#row.operator("object.quickpipe")
def menu_func(self, context):
layout = self.layout
layout.operator_context = "INVOKE_DEFAULT"
self.layout.operator(jmPipeTool.bl_idname, text="Quick Pipe")
classes = (
jmPipeTool,
)
# Register
def register():
for cls in classes:
bpy.utils.register_class(cls)
# update_panel(None, bpy.context)
bpy.types.VIEW3D_MT_edit_mesh_context_menu.append(menu_func) # Mesh Context Menu
#bpy.types.VIEW3D_MT_edit_mesh_vertices.append(menu_func) # Vertices Menu(CTRL+V)
bpy.types.VIEW3D_MT_edit_mesh_edges.append(menu_func) # Edge Menu(CTRL+E)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
bpy.types.VIEW3D_MT_edit_mesh_context_menu.remove(menu_func)
#bpy.types.VIEW3D_MT_edit_mesh_vertices.remove(menu_func)
bpy.types.VIEW3D_MT_edit_mesh_edges.remove(menu_func)
if __name__ == "__main__":
register()