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 #####
21 "author": "Brian Hinton (Nichod)",
23 "blender": (2, 59, 0),
24 "location": "View3D > Add > Mesh",
25 "description": "Adds Chain with curve guide for easy creation",
27 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"\
28 "Scripts/Object/Add_Chain",
29 "tracker_url": "https://projects.blender.org/tracker/index.php?"\
30 "func=detail&aid=22203",
39 bpy
.ops
.object.add(type='EMPTY',
46 ##Changes name of Empty to rot_link adds variable emp
47 emp
= bpy
.context
.object
50 ##Rotate emp ~ 90 degrees
51 emp
.rotation_euler
= [1.570796, 0, 0]
53 ##Adds Curve Path to scene
54 bpy
.ops
.curve
.primitive_nurbs_path_add(view_align
=False,
60 ##Change Curve name to deform adds variable curv
61 curv
= bpy
.context
.object
64 ##Inserts Torus primitive
65 bpy
.ops
.mesh
.primitive_torus_add(major_radius
=1,
74 ##Positions Torus primitive to center of scene
75 bpy
.context
.active_object
.location
= 0.0, 0.0, 0.0
77 ##Reseting Torus rotation in case of 'Align to view' option enabled
78 bpy
.context
.active_object
.rotation_euler
= 0.0, 0.0, 0.0
81 ##Changes Torus name to chain adds variable tor
82 tor
= bpy
.context
.object
85 ##Adds Array Modifier to tor
86 bpy
.ops
.object.modifier_add(type='ARRAY')
88 ##Adds subsurf modifier tor
89 bpy
.ops
.object.modifier_add(type='SUBSURF')
92 bpy
.ops
.object.shade_smooth()
95 sce
= bpy
.context
.scene
96 sce
.objects
.active
= curv
98 ##Toggle into editmode
99 bpy
.ops
.object.editmode_toggle()
101 ## TODO, may be better to move objects directly.
102 ##Translate curve object
103 bpy
.ops
.transform
.translate(value
=(2, 0, 0),
104 constraint_axis
=(True, False, False),
105 constraint_orientation
='GLOBAL',
107 proportional
='DISABLED',
108 proportional_edit_falloff
='SMOOTH',
111 snap_target
='CLOSEST',
112 snap_point
=(0, 0, 0),
114 snap_normal
=(0, 0, 0),
115 release_confirm
=False,
118 ##Toggle into objectmode
119 bpy
.ops
.object.editmode_toggle()
121 ##Select tor or chain
122 sce
.objects
.active
= tor
124 ##Selects Array Modifier for editing
125 array
= tor
.modifiers
['Array']
127 ##Change Array Modifier Parameters
128 array
.fit_type
= 'FIT_CURVE'
130 array
.offset_object
= emp
131 array
.use_object_offset
= True
132 array
.relative_offset_displace
= 0.549, 0.0, 0.0
135 bpy
.ops
.object.modifier_add(type='CURVE')
137 ##Selects Curve Modifier for editing
138 cur
= tor
.modifiers
['Curve']
140 ##Change Curve Modifier Parameters
143 #makes AddChain an operator
144 class AddChain(bpy
.types
.Operator
):
146 bl_idname
= "mesh.primitive_chain_add"
147 bl_label
= "Add Chain"
148 bl_options
= {'REGISTER', 'UNDO'}
151 def execute(self
, context
):
156 # Register the operator
157 def menu_func(self
, context
):
158 self
.layout
.operator(AddChain
.bl_idname
, text
="Chain", icon
='PLUGIN')
162 bpy
.utils
.register_module(__name__
)
164 # Add "Chain" menu to the "Add Mesh" menu.
165 bpy
.types
.INFO_MT_mesh_add
.append(menu_func
)
169 bpy
.utils
.unregister_module(__name__
)
171 # Remove "Chain" menu from the "Add Mesh" menu.
172 bpy
.types
.INFO_MT_mesh_add
.remove(menu_func
)
174 if __name__
== "__main__":