Add Chain Mail

Hey guys,

Whilst thinking about how i was going to add some more functionality to my PolySphere script, i thought it might be an idea to create another add on so i could familiarise my self with this whole scripting business.

So i made a Chain Mail script that enables the creation of a Chain Mail mesh with two paths that directly control the overall size of the mail across two axis.

Hopefully it will be of use :slight_smile:

Add Chainmail (current version 0.2.5) Updated on 22nd June 2011

http://img.photobucket.com/albums/v299/metalliandy/Chain_Mail_Th-1.jpg

http://www.metalliandy.com/downloads…in_mail_025.py

Enjoy!

http://img.photobucket.com/albums/v299/metalliandy/Chain_Mail_Th.jpg

And a video of the script in action

http://vimeo.com/18269605

Enjoy!

can you post a screenshot? I do not have access to Blender right now.
this sounds interesting.

interesting effect here !

is it possible to change the link shape ?
like having a hexagonale shape or other shape may be !

you still have to learn how to add a panel to change some of the variables!
would be very nice to adjust some if the parameters

it’s not that difficult

i have a very busy week but if i have time this weekend i 'll try to make one for this one LOL

nice work
happy 2.5

A few observations about the code, nothing too serious… but you might get some insight. (if this seems too simplistic, then this post is directed at the potential total newcomer reading it). OK, Let’s suppose you have a bunch of these in your code.

bpy.ops.curve.primitive_nurbs_path_add( view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

Whenever you see a lot of repetition (like False, False, False…), it means you can probably write it differently. Consider something like this at the top of your code:


def selectLayer(layernum):
    bools = []
    for i in range(20):
        if layernum == i:
            bools.append(True)
        else:
            bools.append(False)
    return tuple(bools)

you can test selectLayer by doing
print(selectLayer(0)) …or print(selectLayer(7))
so…layer 19 is the last one, because we start counting at 0, like lifts.

that allows you to write

bpy.ops.curve.primitive_nurbs_path_add( view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0), layers=selectLayer(0))

one step further


view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0)

are all default values, leaving them out produces the same effect. Their purpose is to let you modify the behavior of the function if you need to. Read this short explanation: default-argument-values and read PythonDoc/bpy.ops.curve.html, you’ll see they are optional.

in essence you can do

bpy.ops.curve.primitive_nurbs_path_add(layers=selectLayer(0))

and layers=selectLayer(0) is only required if you have some preference of what layer to use. Defining a function like selectLayer at the top of your code allows you to call it many times during your script and it will work for any valid layer. It helps to stick a line inside selectLayer that checks the input, and prints an error message if you accidentally pass a layer that is higher than 19 (or lower than 0…or a character/string). Error checking is good practice as you get more complex.

If the only layer you want to work on is 0, there is an even faster way…

layers=((True,)+(False,)*19)

where is the array size defined?
i can see a var here

#Defines Fixed Count
array.fit_type = (‘FIXED_COUNT’)

but cannot see the size is defined ?

Thanks

@rickyblender, select and scale: Deformation Path Up or /and Deformation Path Acro.
@metalliandy, are you going to introduce some Noise or tamed randomness? :slight_smile:

ok but can you set this as a propertie to be put inside a panel as a parameter?

i got a new sript version with a tool prop panel
but not certain how this array can be set with a propretie!

any idea?

i’ll try to uplaod in net hour
got to clean up a few things first

by the way i need a little function or some lines to erase exsiting 3 objects
the chain mail and 2 curves before adding a new one !
how can this be written ?

need to check first if the object exist or not
got that right now

ob1 = bpy.data.objects[‘Chain Mail’]
bpy.context.scene.objects.unlink(ob1)
bpy.data.objects.remove(ob1)

Thanks

Hey guys,
I really appreciate all the comments and suggestions :slight_smile:

The script was created over the period of a few hours and i only wanted to get basic functionality working in the initial release but im open to new ideas :slight_smile:
Its always cool to see what other people would do and its a great learning exercise to add stuff that people suggest :slight_smile:

Thanks for the reply

Here is a screenshot :slight_smile:

http://img.photobucket.com/albums/v299/metalliandy/Chain_Mail_Th.jpg

And a video of the script in action

I didnt really see the point in changing the link shape as all mail are essentially based on a torus shape, but i see how this could be usefull

I will have a look at adding a menu too, it would be a good thing for me to learn :slight_smile:

As always, your help and advice is greatly appreciated :slight_smile:
Thanks for taking the time again to kick my scripts into shape :slight_smile:

The first few Array modifiers are set to the default (iirc) so i could generate the basic link shape before setting it up to become tillable and deformable with the Paths.
The chainmail is set to grow as you move the paths around so a fixed count wasnt optimal for that.

I think that might be an idea :slight_smile:
As i said above, I literally threw this script together over the period of a few hours just to get the basic functionality working but i really want to add some panels so that everything can be modified but currently i have no idea how to do this! lol

I also want to get a chain link fence working to if possible :slight_smile:

Do you have any tuts or link how i could add things like noise and panels and maybe submenus under the Add menu?

Thanks again for the help :slight_smile:

Im not sure what you mean.
You want to delete the existing objects and add some of your own?

i got a basic new script with panel
but only thing missing is to remove existing objects

so there must a way to test if an object with a name exist or not
if yes then you delete it before adding a new object with same name !

for array size will see after how this can be done function of a parameter in panel

problem here is that you need to do this with an operator to execute it
cause if adding large array it would slow down blender quit a lot
so best way i think is with an execute button instead of adding it inside the Draw function of the panel which would execute it several times a second and slow down blender!

if i can get how to test if name object exist i will add this and load up the new version here!

Thanks guys

the code snippets pdf describes some approaches to adding UI elements, and http://blenderartists.org/forum/showthread.php?t=164765&page=1 deserves some eye-time. Experiment with getting a slider to print values to the commandline. Part of the process of coding is to first define globally what you want to achieve, then progressively break the idea up into smaller parts…and those parts into smaller parts again.

  • I advise strongly against having one giant function of 270 lines. Break it up into several helper-functions to keep the code cleaner. (and shorter)
  • It’s OK to get less comprehensive with your #commenting, you notice that often the code says already what you need to know. the plain english equivalent becomes a waste of space (see it as a positive lazyness). Start to comment larger blocks, larger ideas…and separate blocks with a space

like:


#describing the next few lines briefly
line0
line1
do something here
calculate this 
response = use the previous calculation and feed it to a function
use response to do something.

#describing the next few lines briefly 2
line8
line9
do something here blablabla
calculate this etcetc
response = use the previous calculation and feed it to a function
use response to do something.

With console reporting it became easy to knock out a quick script without really needing to understand much about python. Nonetheless the script is remarkably usable. The downside is that you only vaguely understand the code or how to manipulate it. Read the python.org documentation for python 3.1, especially the code snippets. Doing some mundane non-blender python programming might seem a waste of time but it will prepare you for living higher up on the food chain.

I cant wait to see what you come up with :slight_smile:

Thanks for the link :slight_smile:
I see what you mean with the commenting…i think its a little over the top too.
I went full steam ahead with the script and just added everything as i went along and as you said much of it is unneeded really.
I will reformat the script and try to make it a little neater :slight_smile:

here the code
but not completed yet

tell me what you think

cannnot pass the code too long

get it from here

http://cid-348ad7d85dee0c79.photos.live.com/self.aspx/Brdigefoler1/CHAINMAILrj2.blend

will continue later on this afternoon or tomorrow
got to go get a new USB drive this afternoon!

just run it in text editor and see parameters in Tool pro panel

have fun

Thanks happy 2.5

If you like you can email me the code.
I will send you a PM in a min :slight_smile:

heh i had updated that post again : http://blenderartists.org/forum/showthread.php?t=205582&p=1763043&viewfull=1#post1763043

to see the new chain mail
just click on the last button Execute and it will add it in viewport!

but cannot do more then ounce for now cause need to erase old objects first !

be back later

thanks

lol
Thanks for the update :slight_smile:

Did you attach anything? i dont see the code

http://www.pasteall.org/blend/ is a great place for upping small blends.
and http://www.pasteall.org/ if the py is too long for the forum

only problem is that it is uploaded for ever!
you cannot delete anything - this is a special request on demand only!

did you try my new version?

anyway what is wrong with MSN you get 25 GB free not bad at all!

youneed to download the file and load it up
in file look in the text editor it is already loaded there just run it !

salutations

Oh right!
I didnt see that you edited your post.

The panel looks great :slight_smile:

It will be fun to play around with :slight_smile:

One thing that you should be aware of is that the size of the rings determine how well the whole thing tiles together so changing the diameter of the initial rings will break the tilling.

The segments could go as high as needed but to go lower would also break the tilling as it stands now.

Nice job with the panel though…It will be fun to play around with one the functions are set up!
Thanks for the help :slight_smile:

i’m still refactoring the code, it’s looking better. the whisky slows me down :slight_smile: