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://projects.blender.org/tracker/index.php?"\
30 "func=detail&aid=22203",
38 bpy
.ops
.object.add(type='EMPTY',
45 ##Changes name of Empty to rot_link adds variable emp
46 emp
= bpy
.context
.object
49 ##Rotate emp ~ 90 degrees
50 emp
.rotation_euler
= [1.570796, 0, 0]
52 ##Adds Curve Path to scene
53 bpy
.ops
.curve
.primitive_nurbs_path_add(view_align
=False,
59 ##Change Curve name to deform adds variable curv
60 curv
= bpy
.context
.object
63 ##Inserts Torus primitive
64 bpy
.ops
.mesh
.primitive_torus_add(major_radius
=1,
72 ##Positions Torus primitive to center of scene
73 bpy
.context
.active_object
.location
= 0.0, 0.0, 0.0
75 ##Reseting Torus rotation in case of 'Align to view' option enabled
76 bpy
.context
.active_object
.rotation_euler
= 0.0, 0.0, 0.0
79 ##Changes Torus name to chain adds variable tor
80 tor
= bpy
.context
.object
83 ##Adds Array Modifier to tor
84 bpy
.ops
.object.modifier_add(type='ARRAY')
86 ##Adds subsurf modifier tor
87 bpy
.ops
.object.modifier_add(type='SUBSURF')
90 bpy
.ops
.object.shade_smooth()
93 sce
= bpy
.context
.scene
94 sce
.objects
.active
= curv
96 ##Toggle into editmode
97 bpy
.ops
.object.editmode_toggle()
99 ## TODO, may be better to move objects directly.
100 ##Translate curve object
101 bpy
.ops
.transform
.translate(value
=(2, 0, 0),
102 constraint_axis
=(True, False, False),
103 constraint_orientation
='GLOBAL',
105 proportional
='DISABLED',
106 proportional_edit_falloff
='SMOOTH',
109 snap_target
='CLOSEST',
110 snap_point
=(0, 0, 0),
112 snap_normal
=(0, 0, 0),
113 release_confirm
=False,
116 ##Toggle into objectmode
117 bpy
.ops
.object.editmode_toggle()
119 ##Select tor or chain
120 sce
.objects
.active
= tor
122 ##Selects Array Modifier for editing
123 array
= tor
.modifiers
['Array']
125 ##Change Array Modifier Parameters
126 array
.fit_type
= 'FIT_CURVE'
128 array
.offset_object
= emp
129 array
.use_object_offset
= True
130 array
.relative_offset_displace
= 0.549, 0.0, 0.0
133 bpy
.ops
.object.modifier_add(type='CURVE')
135 ##Selects Curve Modifier for editing
136 cur
= tor
.modifiers
['Curve']
138 ##Change Curve Modifier Parameters
141 #makes AddChain an operator
142 class AddChain(bpy
.types
.Operator
):
144 bl_idname
= "mesh.primitive_chain_add"
145 bl_label
= "Add Chain"
146 bl_options
= {'REGISTER', 'UNDO'}
149 def execute(self
, context
):
154 # Register the operator
155 def menu_func(self
, context
):
156 self
.layout
.operator(AddChain
.bl_idname
, text
="Chain", icon
='PLUGIN')
160 bpy
.utils
.register_module(__name__
)
162 # Add "Chain" menu to the "Add Mesh" menu.
163 bpy
.types
.INFO_MT_mesh_add
.append(menu_func
)
167 bpy
.utils
.unregister_module(__name__
)
169 # Remove "Chain" menu from the "Add Mesh" menu.
170 bpy
.types
.INFO_MT_mesh_add
.remove(menu_func
)
172 if __name__
== "__main__":