align columns (for multi-drag)
[blender-addons.git] / object_add_chain.py
blob264b550015e7790887ca64ae3a43b568fa30856a
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 bl_info = {
20 "name": "Add Chain",
21 "author": "Brian Hinton (Nichod)",
22 "version": (0, 1, 1),
23 "blender": (2, 71, 0),
24 "location": "Toolshelf > Create Tab",
25 "description": "Adds Chain with curve guide for easy creation",
26 "warning": "",
27 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
28 "Scripts/Object/Add_Chain",
29 "category": "Object",
32 import bpy
33 from bpy.types import Operator, Panel
35 def Add_Chain():
36 ##Adds Empty to scene
37 bpy.ops.object.add(type='EMPTY',
38 view_align=False,
39 enter_editmode=False,
40 location=(0, 0, 0),
41 rotation=(0, 0, 0),
44 ##Changes name of Empty to rot_link adds variable emp
45 emp = bpy.context.object
46 emp.name = "rot_link"
48 ##Rotate emp ~ 90 degrees
49 emp.rotation_euler = [1.570796, 0, 0]
51 ##Adds Curve Path to scene
52 bpy.ops.curve.primitive_nurbs_path_add(view_align=False,
53 enter_editmode=False,
54 location=(0, 0, 0),
55 rotation=(0, 0, 0),
58 ##Change Curve name to deform adds variable curv
59 curv = bpy.context.object
60 curv.name = "deform"
62 ##Inserts Torus primitive
63 bpy.ops.mesh.primitive_torus_add(major_radius=1,
64 minor_radius=0.25,
65 major_segments=12,
66 minor_segments=4,
67 abso_major_rad=1,
68 abso_minor_rad=0.5,
71 ##Positions Torus primitive to center of scene
72 bpy.context.active_object.location = 0.0, 0.0, 0.0
74 ##Reseting Torus rotation in case of 'Align to view' option enabled
75 bpy.context.active_object.rotation_euler = 0.0, 0.0, 0.0
78 ##Changes Torus name to chain adds variable tor
79 tor = bpy.context.object
80 tor.name = "chain"
82 ##Adds Array Modifier to tor
83 bpy.ops.object.modifier_add(type='ARRAY')
85 ##Adds subsurf modifier tor
86 bpy.ops.object.modifier_add(type='SUBSURF')
88 ##Smooths tor
89 bpy.ops.object.shade_smooth()
91 ##Select curv
92 sce = bpy.context.scene
93 sce.objects.active = curv
95 ##Toggle into editmode
96 bpy.ops.object.editmode_toggle()
98 ## TODO, may be better to move objects directly.
99 ##Translate curve object
100 bpy.ops.transform.translate(value=(2, 0, 0),
101 constraint_axis=(True, False, False),
102 constraint_orientation='GLOBAL',
103 mirror=False,
104 proportional='DISABLED',
105 proportional_edit_falloff='SMOOTH',
106 proportional_size=1,
107 snap=False,
108 snap_target='CLOSEST',
109 snap_point=(0, 0, 0),
110 snap_align=False,
111 snap_normal=(0, 0, 0),
112 release_confirm=False,
115 ##Toggle into objectmode
116 bpy.ops.object.editmode_toggle()
118 ##Select tor or chain
119 sce.objects.active = tor
121 ##Selects Array Modifier for editing
122 array = tor.modifiers['Array']
124 ##Change Array Modifier Parameters
125 array.fit_type = 'FIT_CURVE'
126 array.curve = curv
127 array.offset_object = emp
128 array.use_object_offset = True
129 array.relative_offset_displace = 0.549, 0.0, 0.0
131 ##Add curve modifier
132 bpy.ops.object.modifier_add(type='CURVE')
134 ##Selects Curve Modifier for editing
135 cur = tor.modifiers['Curve']
137 ##Change Curve Modifier Parameters
138 cur.object = curv
140 class AddChain(bpy.types.Operator):
141 """Add a Chain"""
142 bl_idname = "mesh.primitive_chain_add"
143 bl_label = "Add Chain"
144 bl_options = {'REGISTER', 'UNDO'}
146 def execute(self, context):
147 Add_Chain()
149 return {'FINISHED'}
151 class add_chain(Panel):
152 bl_space_type = 'VIEW_3D'
153 bl_region_type = 'TOOLS'
154 bl_category = 'Create'
155 bl_label = "Add Chain"
156 bl_context = "objectmode"
157 bl_options = {'DEFAULT_CLOSED'}
159 def draw(self, context):
160 layout = self.layout
161 layout.operator(AddChain.bl_idname, text="Chain")
163 def register():
164 bpy.utils.register_module(__name__)
165 pass
167 def unregister():
168 bpy.utils.unregister_module(__name__)
169 pass
171 if __name__ == "__main__":
172 register()