set property to native line ending
[blender-addons.git] / object_add_chain.py
blob9c067956b6885adc69a40f08e174c48ed89d91da
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),
23 "blender": (2, 59, 0),
24 "location": "View3D > Add > Mesh",
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 "tracker_url": "https://projects.blender.org/tracker/index.php?"\
30 "func=detail&aid=22203",
31 "category": "Object"}
33 import bpy
35 def Add_Chain():
38 ##Adds Empty to scene
39 bpy.ops.object.add(type='EMPTY',
40 view_align=False,
41 enter_editmode=False,
42 location=(0, 0, 0),
43 rotation=(0, 0, 0),
46 ##Changes name of Empty to rot_link adds variable emp
47 emp = bpy.context.object
48 emp.name = "rot_link"
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,
55 enter_editmode=False,
56 location=(0, 0, 0),
57 rotation=(0, 0, 0),
60 ##Change Curve name to deform adds variable curv
61 curv = bpy.context.object
62 curv.name = "deform"
64 ##Inserts Torus primitive
65 bpy.ops.mesh.primitive_torus_add(major_radius=1,
66 minor_radius=0.25,
67 major_segments=12,
68 minor_segments=4,
69 use_abso=False,
70 abso_major_rad=1,
71 abso_minor_rad=0.5,
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
83 tor.name = "chain"
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')
91 ##Smooths tor
92 bpy.ops.object.shade_smooth()
94 ##Select curv
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',
106 mirror=False,
107 proportional='DISABLED',
108 proportional_edit_falloff='SMOOTH',
109 proportional_size=1,
110 snap=False,
111 snap_target='CLOSEST',
112 snap_point=(0, 0, 0),
113 snap_align=False,
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'
129 array.curve = curv
130 array.offset_object = emp
131 array.use_object_offset = True
132 array.relative_offset_displace = 0.549, 0.0, 0.0
134 ##Add curve modifier
135 bpy.ops.object.modifier_add(type='CURVE')
137 ##Selects Curve Modifier for editing
138 cur = tor.modifiers['Curve']
140 ##Change Curve Modifier Parameters
141 cur.object = curv
143 #makes AddChain an operator
144 class AddChain(bpy.types.Operator):
145 """Add a Chain"""
146 bl_idname = "mesh.primitive_chain_add"
147 bl_label = "Add Chain"
148 bl_options = {'REGISTER', 'UNDO'}
151 def execute(self, context):
152 Add_Chain()
154 return {'FINISHED'}
156 # Register the operator
157 def menu_func(self, context):
158 self.layout.operator(AddChain.bl_idname, text="Chain", icon='PLUGIN')
161 def register():
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)
168 def unregister():
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__":
175 register()