fix for error reading gzip'd x3d/vrml files
[blender-addons.git] / object_add_chain.py
blobfc5f3bd24f613a30ff148aa5061a6b3c94e834d0
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, 1),
23 "blender": (2, 68, 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
36 def Add_Chain():
37 ##Adds Empty to scene
38 bpy.ops.object.add(type='EMPTY',
39 view_align=False,
40 enter_editmode=False,
41 location=(0, 0, 0),
42 rotation=(0, 0, 0),
45 ##Changes name of Empty to rot_link adds variable emp
46 emp = bpy.context.object
47 emp.name = "rot_link"
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,
54 enter_editmode=False,
55 location=(0, 0, 0),
56 rotation=(0, 0, 0),
59 ##Change Curve name to deform adds variable curv
60 curv = bpy.context.object
61 curv.name = "deform"
63 ##Inserts Torus primitive
64 bpy.ops.mesh.primitive_torus_add(major_radius=1,
65 minor_radius=0.25,
66 major_segments=12,
67 minor_segments=4,
68 abso_major_rad=1,
69 abso_minor_rad=0.5,
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
81 tor.name = "chain"
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')
89 ##Smooths tor
90 bpy.ops.object.shade_smooth()
92 ##Select curv
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',
104 mirror=False,
105 proportional='DISABLED',
106 proportional_edit_falloff='SMOOTH',
107 proportional_size=1,
108 snap=False,
109 snap_target='CLOSEST',
110 snap_point=(0, 0, 0),
111 snap_align=False,
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'
127 array.curve = curv
128 array.offset_object = emp
129 array.use_object_offset = True
130 array.relative_offset_displace = 0.549, 0.0, 0.0
132 ##Add curve modifier
133 bpy.ops.object.modifier_add(type='CURVE')
135 ##Selects Curve Modifier for editing
136 cur = tor.modifiers['Curve']
138 ##Change Curve Modifier Parameters
139 cur.object = curv
141 #makes AddChain an operator
142 class AddChain(bpy.types.Operator):
143 """Add a Chain"""
144 bl_idname = "mesh.primitive_chain_add"
145 bl_label = "Add Chain"
146 bl_options = {'REGISTER', 'UNDO'}
149 def execute(self, context):
150 Add_Chain()
152 return {'FINISHED'}
154 # Register the operator
155 def menu_func(self, context):
156 self.layout.operator(AddChain.bl_idname, text="Chain", icon='PLUGIN')
159 def register():
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)
166 def unregister():
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__":
173 register()