Add Chain for Blender 2.5 preview

Just a preview of the script. It’s my first truly complete Python script so be kind! I’ll post the actual script up in a bit. Thanks to MichaelW for his help! Definitely pointed me in the right direction a couple of times and wouldn’t have learned as much as I did without his assistance!

Preview: http://www.vimeo.com/11279857

I’m going to create a little tutorial on how I did it. And I plan on releasing additional tutorials soonish on learning all this stuff. Share as I learn approach! I own blenderscripts.org so expect something there in the near future.

# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
#
import bpy
#
bl_addon_info = {
    'name': 'Add: Chain',
    'author': 'Brian Hinton (Nichod)',
    'version': '0.1',
    'blender': (2, 5, 3),
    'location': 'View3D > Add > Mesh > Chain',
    'description': 'Adds Chain with curve guide for easy creation',
    'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/' \
        'Scripts/Chain',  # @todo Create page and fix this link.
    'category': 'Object'}
#
#
#
def Add_Chain():
  

    ##Adds Empty to scene
    bpy.ops.object.add(type='EMPTY', view_align=False, enter_editmode=False, location=(0, 0, 0), 
rotation=(0, 0, 0), layer=(True, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False, False, 
False, False, False, False, False, False, False, False, False, False, False, False, False))

    ##Changes name of Empty to rot_link adds variable emp
    emp = bpy.context.object
    emp.name = "rot_link"

    ##Rotate emp ~ 90 degrees
    emp.rotation_euler = [1.570796, 0, 0]

    ##Adds Curve Path to scene
    bpy.ops.object.curve_add(type='PATH', view_align=False, enter_editmode=False, location=(0, 0, 0), 
rotation=(0, 0, 0), layer=(True, False, False, False, False, False, 
False, False, False, False, False, False, False, False, False, False, False, False, False, 
False, False, False, False, False, False, False, False, False, False, False, False, False))

    ##Change Curve name to deform adds variable curv
    curv = bpy.context.object
    curv.name = "deform"

    ##Inserts Torus primitive
    bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, 
major_segments=12, minor_segments=4, use_abso=False, abso_major_rad=1, 
abso_minor_rad=0.5)

    ##Positions Torus primitive to center of scene
    bpy.context.active_object.location = [0, 0, 0]

    ##Changes Torus name to chain adds variable tor
    tor = bpy.context.object
    tor.name = "chain"

    ##Adds Array Modifier to tor
    bpy.ops.object.modifier_add(type='ARRAY')

    ##Adds subsurf modifier tor
    bpy.ops.object.modifier_add(type='SUBSURF')

    ##Smooths tor
    bpy.ops.object.shade_smooth()

    ##Select curv 
    sce = bpy.context.scene
    sce.objects.active = curv

    ##Toggle into editmode
    bpy.ops.object.editmode_toggle()

    ##Translate curve object
    bpy.ops.transform.translate(value=(2, 0, 0), constraint_axis=(True, False, False), 
constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', 
proportional_editing_falloff='SMOOTH', proportional_size=1, snap=False, 
snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), 
release_confirm=False)

    ##Toggle into objectmode
    bpy.ops.object.editmode_toggle()

    ##Select tor or chain
    sce.objects.active = tor

    ##Selects Array Modifier for editing
    array = tor.modifiers['Array']

    ##Change Array Modifier Parameters
    array.fit_type = ('FIT_CURVE')
    array.curve = curv
    array.offset_object = emp
    array.add_offset_object = True
    array.relative_offset_displacement = [ 0.549, 0, 0 ]

    ##Add curve modifier
    bpy.ops.object.modifier_add(type='CURVE')

    ##Selects Curve Modifier for editing
    cur = tor.modifiers['Curve']

    ##Change Curve Modifier Parameters
    cur.object = curv

#makes AddChain an operator
class AddChain(bpy.types.Operator):
    '''Add a Chain.'''
    bl_idname = "mesh.primitive_chain_add"
    bl_label = "Add Chain"
    bl_options = {'REGISTER', 'UNDO'}


    def execute(self, context):
        Add_Chain()

        return {'FINISHED'}

# Register the operator
menu_func = (lambda self, 
            context: self.layout.operator(AddChain.bl_idname,
            text="Chain", icon='PLUGIN'))


def register():
    bpy.types.register(AddChain)

    # Add "Chain" menu to the "Add Mesh" menu.
    bpy.types.INFO_MT_mesh_add.append(menu_func)


def unregister():
    bpy.types.unregister(AddChain)

    # Remove "Chain" menu from the "Add Mesh" menu.
    bpy.types.INFO_MT_mesh_add.remove(menu_func)

if __name__ == "__main__":
    register()

https://svn.blender.org/svnroot/bf-extensions/trunk/py/scripts/addons/object_add_chain.py

it looks nice Nichod! thank you for this script.

nice work!

that looks great and really slick!

ok, now i get it. :wink:
Great Job!
I’m properly testing the script now.
It is more awesome than it looks.

Thanks for the kind words guys! I’m fleshing it out a bit more and I’ll post it up possibly later this evening. Just want to make sure that it works and will install easily.

video is nice but where can we download the script for this auto chain

it makes it so esy to make a chain in the video it’s amazing how 2.5 is becoming powefull
and easy to use !

keep up the good work
appy 2.5

Very nice Nichod.

Looking forward to adding this script to my growing Blender 2.5x tool-set (Lets out a scream of delight).

–Double Post–

Great script! Thanks for sharing Nichod. :yes:

First post updated with version 0.1 of script! Enjoy and let me know how it works for you. Please use a recent build and if I recall there was a build that broke the torus preset (used by this script) so it things look a little strange when using the script…that could be why!

If you have any questions I’ll do my best to answer, but I’m going to bed now and I work tomorrow so I’ll be in and out of the forums. :yes:

F’ing Awesome!!

:smiley:

-SterlingY

Just FYI some people are getting errors. I’ll check on it. But try installing a copy from the link at the bottom of the first post.

Wow, this one made me smile - I think I just found a permanent tool for my toolbox - really speeds up the chain and other repeating objects making - I made a string of christmas lights in a few minutes as a test.

Thanks Nichod!

interesting but can you share this script too

it can add to the tool box

happy 2.5

If you haven’t seen my other videos: http://vimeo.com/user3689925

I just recorded the first video on building the chain script and it will be part of the daily videos. Keep an eye out and it will be up soon. I’ll post here when it’s available.

i got one suggestion thinking about chain shape

would it be possible to use different shape of chain link

i mean like you make a default predefined chain link for instance
but could be replaced by another object with the rigth name to be used to main make the chain
or used a field to enter the name of an object to use !

that way you can customise the chain as you wish and not be limited to a specific shape of chain link!

happy 2.5

This is somewhat possible right now. Just select the chain, toggle into edit mode, select all and delete. Then making sure that the 3D cursor is at 0, 0, 0 insert a different shape into the scene and model it accordingly.

In the future I will be adding to the script the ability to select any object in the scene as the chain link, but that’s probably a couple of weeks away.

very cool script showing the 2.5 power in action

hope to see an upate on this script soon

keep up the good work
happy 2.5

Stops to work for me… I think that the problem is:

>>> bpy.ops.object.curve_add(type='PATH', view_align=False, enter_editmode=False, location=(0, 0, 0), 
... rotation=(0, 0, 0), layer=(True, False, False, False, False, False, 
... False, False, False, False, False, False, False, False, False, False, False, False, False, 
... False, False, False, False, False, False, False, False, False, False, False, False, False))
Traceback (most recent call last):
  File "<console>", line 4, in <module>
  File "/home/mato/Escritorio/blender25/.blender/scripts/modules/bpy/ops.py", line 158, in __call__
    ret = op_call(self.idname_py(), C_dict, kw)
SystemError: Calling operator "bpy.ops.object.curve_add" error, could not be found

The file ops.py exist in the path that say there…