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, 71, 0),
24 "location": "Toolshelf > Create Tab",
25 "description": "Adds Chain with curve guide for easy creation",
27 "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
28 "Scripts/Object/Add_Chain",
33 from bpy
.types
import Operator
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(
61 # Change Curve name to deform adds variable curv
62 curv
= bpy
.context
.object
65 # Inserts Torus primitive
66 bpy
.ops
.mesh
.primitive_torus_add(
75 # Positions Torus primitive to center of scene
76 bpy
.context
.active_object
.location
= 0.0, 0.0, 0.0
78 # Reseting Torus rotation in case of 'Align to view' option enabled
79 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(
105 constraint_axis
=(True, False, False),
106 constraint_orientation
='GLOBAL',
108 proportional
='DISABLED',
109 proportional_edit_falloff
='SMOOTH',
112 snap_target
='CLOSEST',
113 snap_point
=(0, 0, 0),
115 snap_normal
=(0, 0, 0),
116 release_confirm
=False,
119 # Toggle into objectmode
120 bpy
.ops
.object.editmode_toggle()
122 # Select tor or chain
123 sce
.objects
.active
= tor
125 # Selects Array Modifier for editing
126 array
= tor
.modifiers
['Array']
128 # Change Array Modifier Parameters
129 array
.fit_type
= 'FIT_CURVE'
131 array
.offset_object
= emp
132 array
.use_object_offset
= True
133 array
.relative_offset_displace
= 0.549, 0.0, 0.0
136 bpy
.ops
.object.modifier_add(type='CURVE')
138 # Selects Curve Modifier for editing
139 cur
= tor
.modifiers
['Curve']
141 # Change Curve Modifier Parameters
145 class AddChain(Operator
):
146 bl_idname
= "mesh.primitive_chain_add"
147 bl_label
= "Add Chain"
148 bl_description
= ("Create a Chain segment with helper objects controlling modifiers:\n"
149 "1) A Curve Modifier Object (deform) for the length and shape,\n"
150 "Edit the Path to extend Chain Length\n"
151 "2) An Empty (rot_link) as an Array Offset for rotation")
152 bl_options
= {'REGISTER', 'UNDO'}
154 def execute(self
, context
):
158 except Exception as e
:
159 self
.report({'WARNING'},
160 "Some operations could not be performed (See Console for more info)")
162 print("\n[Add Advanced Objects]\nOperator: "
163 "mesh.primitive_chain_add\nError: {}".format(e
))
171 bpy
.utils
.register_class(AddChain
)
175 bpy
.utils
.unregister_class(AddChain
)
178 if __name__
== "__main__":