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, 68, 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://developer.blender.org/T22203",
37 bpy
.ops
.object.add(type='EMPTY',
44 ##Changes name of Empty to rot_link adds variable emp
45 emp
= bpy
.context
.object
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,
58 ##Change Curve name to deform adds variable curv
59 curv
= bpy
.context
.object
62 ##Inserts Torus primitive
63 bpy
.ops
.mesh
.primitive_torus_add(major_radius
=1,
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
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')
89 bpy
.ops
.object.shade_smooth()
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',
104 proportional
='DISABLED',
105 proportional_edit_falloff
='SMOOTH',
108 snap_target
='CLOSEST',
109 snap_point
=(0, 0, 0),
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'
127 array
.offset_object
= emp
128 array
.use_object_offset
= True
129 array
.relative_offset_displace
= 0.549, 0.0, 0.0
132 bpy
.ops
.object.modifier_add(type='CURVE')
134 ##Selects Curve Modifier for editing
135 cur
= tor
.modifiers
['Curve']
137 ##Change Curve Modifier Parameters
140 #makes AddChain an operator
141 class AddChain(bpy
.types
.Operator
):
143 bl_idname
= "mesh.primitive_chain_add"
144 bl_label
= "Add Chain"
145 bl_options
= {'REGISTER', 'UNDO'}
148 def execute(self
, context
):
153 # Register the operator
154 def menu_func(self
, context
):
155 self
.layout
.operator(AddChain
.bl_idname
, text
="Chain", icon
='PLUGIN')
159 bpy
.utils
.register_module(__name__
)
161 # Add "Chain" menu to the "Add Mesh" menu.
162 bpy
.types
.INFO_MT_mesh_add
.append(menu_func
)
166 bpy
.utils
.unregister_module(__name__
)
168 # Remove "Chain" menu from the "Add Mesh" menu.
169 bpy
.types
.INFO_MT_mesh_add
.remove(menu_func
)
171 if __name__
== "__main__":