17
17
# ##### END GPL LICENSE BLOCK #####
20
20
"name": "Pipe Joints",
21
21
"author": "Buerbaum Martin (Pontiac)",
22
"version": (0, 10, 6),
25
"location": "View3D > Add > Mesh > Pipe Joint",
26
"description": "Adds 5 pipe Joint types to the Add Mesh menu",
22
"version": (0, 10, 7),
24
"location": "View3D > Add > Mesh > Pipe Joints",
25
"description": "Add different types of pipe joints",
28
27
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
29
28
"Scripts/Add_Mesh/Add_Pipe_Joints",
30
29
"tracker_url": "https://projects.blender.org/tracker/index.php?"\
31
"func=detail&aid=21443&group_id=153&atid=469",
30
"func=detail&aid=21443",
32
31
"category": "Add Mesh"}
36
This script lets the user create various types of pipe joints.
39
You have to activated the script in the "Add-Ons" tab (user preferences).
40
The functionality can then be accessed via the
41
"Add Mesh" -> "Pipe Joints" menu.
42
Note: Currently only the "Elbow" type supports odd number of vertices.
45
v0.10.6 - Removed "recall properties" from all functions.
46
Updated various code for new API.
47
API: mathutils.RotationMatrix -> mathutils.Matrix.Rotation
48
API: xxx.selected -> xxx.select
49
API: "invoke" function for each operator.
50
Updated for new bl_addon_info structure.
51
New code for the "align_matrix".
52
made script PEP8 compatible.
53
v0.10.5 - createFaces can now create fan/star like faces.
54
v0.10.4 - Updated the function "createFaces" a bit. No functional changes.
55
v0.10.3 - Updated store_recall_properties, apply_object_align
56
and create_mesh_object.
57
Changed how recall data is stored.
59
v0.10.2 - API change Mathutils -> mathutils (r557)
61
v0.10.1 - Use hidden "edit" property for "recall" operator.
62
v0.10 - Store "recall" properties in the created objects.
63
Align the geometry to the view if the user preference says so.
64
v0.9.10 - Use bl_addon_info for Add-On information.
65
v0.9.9 - Changed the script so it can be managed from the "Add-Ons" tab in
67
Added dummy "PLUGIN" icon.
68
v0.9.8 - Fixed some new API stuff.
69
Mainly we now have the register/unregister functions.
70
Also the new() function for objects now accepts a mesh object.
71
Corrected FSF address.
73
v0.9.7 - Use "unit" settings for angles as well.
74
This also lets me use radiant for all internal values..
75
v0.9.6 - Use "unit" settings (i.e. none/metric/imperial).
76
v0.9.5 - Use mesh.from_pydata() for geometry creation.
77
So we can remove unpack_list and unpack_face_list again.
78
v0.9.4 - Creating of the pipe now works in mesh edit mode too.
79
Thanks to ideasman42 (Campbell Barton) for his nice work
80
on the torus script code :-).
81
v0.9.3 - Changed to a saner vertex/polygon creation process (previously
82
my usage of mesh.faces.add could only do quads)
83
For this I've copied the functions unpack_list and unpack_face_list
84
from import_scene_obj.py.
85
Elbow joint actually supports 3 vertices per circle.
87
Script _should_ now be PEP8 compatible.
88
v0.9.2 - Converted from tabs to spaces (4 spaces per tab).
89
v0.9.1 - Converted add_mesh and add_object to their new counterparts
90
"bpy.data.meshes.new() and "bpy.data.objects.new()"
91
v0.9 - Converted to 2.5. Made mostly pep8 compatible (exept for tabs and
92
stuff the check-script didn't catch).
93
v0.8.5 - Fixed bug in Elbow joint. Same problem as in 0.8.1
94
v0.8.4 - Fixed bug in Y joint. Same problem as in 0.8.1
95
v0.8.3 - Fixed bug in N joint. Same problem as in 0.8.1
96
v0.8.2 - Fixed bug in X (cross) joint. Same problem as in 0.8.1
97
v0.8.1 - Fixed bug in T joint. Angles greater than 90 deg combined with a
98
radius != 1 resulted in bad geometry (the radius was not taken into
99
account when calculating the joint vertices).
100
v0.8 - Added N-Joint.
101
Removed all uses of baseJointLocZ. It just clutters the code.
102
v0.7 - Added cross joint
103
v0.6 - No visible changes. Lots of internal ones though
104
(complete redesign of face creation process).
105
As a bonus the code is a bit easier to read now.
106
Added a nice&simple little "bridge" function
107
(createFaces) for these changes.
108
v0.5.1 - Made it possible to create asymmetric Y joints.
109
Renamed the 2 Wye Joints to something more fitting and unique.
110
One is now the Tee joint, the second one remains the Wye joint.
111
v0.5 - Added real Y joint.
112
v0.4.3 - Added check for odd vertex numbers. They are not (yet) supported.
113
v0.4.2 - Added pipe length to the GUI.
114
v0.4.1 - Removed the unfinished menu entries for now.
115
v0.4 - Tried to clean up the face creation in addTeeJoint
116
v0.3 - Code for wye (Y) shape (straight pipe with "branch" for now)
117
v0.2 - Restructured to allow different types of pipe (joints).
118
v0.1 - Initial revision.
121
http://gitorious.org/blender-scripts/blender-pipe-joint-script
122
http://blenderartists.org/forum/showthread.php?t=154394
126
Use a rotation matrix for rotating the circle vertices:
127
rotation_matrix = mathutils.Matrix.Rotation(-math.pi/2, 4, 'x')
128
mesh.transform(rotation_matrix)
133
34
from math import *
134
35
from bpy.props import *
137
# Apply view rotation to objects if "Align To" for
138
# new objects was set to "VIEW" in the User Preference.
139
# Is now handled in the invoke functions
140
# calculates the matrix for the new object
141
# depending on user pref
142
def align_matrix(context):
143
loc = mathutils.Matrix.Translation(context.scene.cursor_location)
144
obj_align = context.user_preferences.edit.object_align
145
if (context.space_data.type == 'VIEW_3D'
146
and obj_align == 'VIEW'):
147
view_mat = context.space_data.region_3d.view_matrix
148
rot = view_mat.rotation_part().invert().resize4x4()
150
rot = mathutils.Matrix()
151
align_matrix = loc * rot
155
38
# Create a new mesh (object) from verts/edges/faces.
156
39
# verts/edges/faces ... List of vertices/edges/faces for the
157
40
# new mesh (as used in from_pydata).
158
41
# name ... Name of the new mesh (& object).
159
# edit ... Replace existing mesh data.
160
# Note: Using "edit" will destroy/delete existing mesh data.
161
def create_mesh_object(context, verts, edges, faces, name, edit, align_matrix):
162
scene = context.scene
163
obj_act = scene.objects.active
165
# Can't edit anything, unless we have an active obj.
166
if edit and not obj_act:
42
def create_mesh_object(context, verts, edges, faces, name):
170
44
mesh = bpy.data.meshes.new(name)
175
49
# Update mesh geometry after adding stuff.
178
# Deselect all objects.
179
bpy.ops.object.select_all(action='DESELECT')
182
# Replace geometry of existing object
184
# Use the active obj and select it.
188
if obj_act.mode == 'OBJECT':
189
# Get existing mesh datablock.
190
old_mesh = ob_new.data
192
# Set object data to nothing
195
# Clear users of existing mesh datablock.
196
old_mesh.user_clear()
198
# Remove old mesh datablock if no users are left.
199
if (old_mesh.users == 0):
200
bpy.data.meshes.remove(old_mesh)
202
# Assign new mesh datablock.
207
ob_new = bpy.data.objects.new(name, mesh)
209
# Link new object to the given scene and select it.
210
scene.objects.link(ob_new)
213
# Place the object at the 3D cursor location.
214
ob_new.matrix_world = align_matrix
216
if obj_act and obj_act.mode == 'EDIT':
218
# We are in EditMode, switch to ObjectMode.
219
bpy.ops.object.mode_set(mode='OBJECT')
221
# Select the active object as well.
222
obj_act.select = True
224
# Apply location of new object.
227
# Join new object into the active.
228
bpy.ops.object.join()
230
# Switching back to EditMode.
231
bpy.ops.object.mode_set(mode='EDIT')
236
# We are in ObjectMode.
237
# Make the new object the active one.
238
scene.objects.active = ob_new
52
from bpy_extras import object_utils
53
return object_utils.object_data_add(context, mesh, operator=None)
243
55
# A very simple "bridge" tool.
244
56
# Connects two equally long vertex rows with faces.
314
126
'''Add an Elbow pipe mesh'''
315
127
bl_idname = "mesh.primitive_elbow_joint_add"
316
128
bl_label = "Add Pipe Elbow"
317
bl_options = {'REGISTER', 'UNDO'}
319
# edit - Whether to add or update.
320
edit = BoolProperty(name="",
129
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
325
131
radius = FloatProperty(name="Radius",
326
description="The radius of the pipe.",
132
description="The radius of the pipe",
331
137
div = IntProperty(name="Divisions",
332
description="Number of vertices (divisions).",
138
description="Number of vertices (divisions)",
333
139
default=32, min=3, max=256)
335
141
angle = FloatProperty(name="Angle",
336
description="The angle of the branching pipe (i.e. the 'arm')." \
337
" Measured from the center line of the main pipe.",
142
description="The angle of the branching pipe (i.e. the 'arm' - " \
143
"Measured from the center line of the main pipe",
338
144
default=radians(45.0),
339
145
min=radians(-179.9),
340
146
max=radians(179.9),
343
149
startLength = FloatProperty(name="Length Start",
344
description="Length of the beginning of the pipe.",
150
description="Length of the beginning of the pipe",
349
155
endLength = FloatProperty(name="End Length",
350
description="Length of the end of the pipe.",
156
description="Length of the end of the pipe",
355
align_matrix = mathutils.Matrix()
357
162
def execute(self, context):
360
164
radius = self.radius
429
227
'''Add a Tee-Joint mesh'''
430
228
bl_idname = "mesh.primitive_tee_joint_add"
431
229
bl_label = "Add Pipe Tee-Joint"
432
bl_options = {'REGISTER', 'UNDO'}
434
# edit - Whether to add or update.
435
edit = BoolProperty(name="",
230
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
440
232
radius = FloatProperty(name="Radius",
441
description="The radius of the pipe.",
233
description="The radius of the pipe",
446
238
div = IntProperty(name="Divisions",
447
description="Number of vertices (divisions).",
239
description="Number of vertices (divisions)",
452
244
angle = FloatProperty(name="Angle",
453
description="The angle of the branching pipe (i.e. the 'arm')." \
454
" Measured from the center line of the main pipe.",
245
description="The angle of the branching pipe (i.e. the 'arm' - " \
246
"Measured from the center line of the main pipe",
455
247
default=radians(90.0),
456
248
min=radians(0.1),
457
249
max=radians(179.9),
620
404
'''Add a Wye-Joint mesh'''
621
405
bl_idname = "mesh.primitive_wye_joint_add"
622
406
bl_label = "Add Pipe Wye-Joint"
623
bl_options = {'REGISTER', 'UNDO'}
625
# edit - Whether to add or update.
626
edit = BoolProperty(name="",
407
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
631
409
radius = FloatProperty(name="Radius",
632
description="The radius of the pipe.",
410
description="The radius of the pipe",
637
415
div = IntProperty(name="Divisions",
638
description="Number of vertices (divisions).",
416
description="Number of vertices (divisions)",
643
421
angle1 = FloatProperty(name="Angle 1",
644
description="The angle of the 1. branching pipe." \
645
" Measured from the center line of the main pipe.",
422
description="The angle of the 1. branching pipe " \
423
"(measured from the center line of the main pipe)",
646
424
default=radians(45.0),
647
425
min=radians(-179.9),
648
426
max=radians(179.9),
650
428
angle2 = FloatProperty(name="Angle 2",
651
description="The angle of the 2. branching pipe." \
652
" Measured from the center line of the main pipe.",
429
description="The angle of the 2. branching pipe " \
430
"(measured from the center line of the main pipe) ",
653
431
default=radians(45.0),
654
432
min=radians(-179.9),
655
433
max=radians(179.9),
829
599
# Create the vertices and polygons for a coss (+ or X) pipe joint.
830
600
bl_idname = "mesh.primitive_cross_joint_add"
831
601
bl_label = "Add Pipe Cross-Joint"
832
bl_options = {'REGISTER', 'UNDO'}
834
# edit - Whether to add or update.
835
edit = BoolProperty(name="",
602
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
840
604
radius = FloatProperty(name="Radius",
841
description="The radius of the pipe.",
605
description="The radius of the pipe",
846
610
div = IntProperty(name="Divisions",
847
description="Number of vertices (divisions).",
611
description="Number of vertices (divisions)",
852
616
angle1 = FloatProperty(name="Angle 1",
853
description="The angle of the 1. arm (from the main axis).",
617
description="The angle of the 1. arm (from the main axis)",
854
618
default=radians(90.0),
855
619
min=radians(-179.9),
856
620
max=radians(179.9),
858
622
angle2 = FloatProperty(name="Angle 2",
859
description="The angle of the 2. arm (from the main axis).",
623
description="The angle of the 2. arm (from the main axis)",
860
624
default=radians(90.0),
861
625
min=radians(-179.9),
862
626
max=radians(179.9),
864
628
angle3 = FloatProperty(name="Angle 3 (center)",
865
description="The angle of the center arm (from the main axis).",
629
description="The angle of the center arm (from the main axis)",
866
630
default=radians(0.0),
867
631
min=radians(-179.9),
868
632
max=radians(179.9),