algo for zig zag line?

if you avhe 2 points P1 P2

and you need to draw sort of a zig zag line between the 2 points

anybody remember what the algo is for this ?

i;v seen that in probabilty math long time ago but don’t remember where !

Thanks

Why bother with an algorithm at all?

Just draw the two points in the IPO editor, set it to cyclic.

If you need a curve out of your script just use the IPO to Curve script.

in 2.5 never really used it before!

are you talking about the Graph editor here ?
any doc in wiki n how to for this ?

but iw ant 2 points in blender so how can you make a line very long for instance of in 3D?

Thanks

Here’s a simple script to making ZigZag(s) that I was able to produce in half an hour:

from Blender import *

threshold = 0.1

#######################################

def Make_ZigZag(L,d,steps):
    L = L*1.0  # make it a real number....
    if L < threshold:
        return None
    verts_list = []
    edges_list = []
#    faces_list = []
    
    p1 = (0,0,0)
    p2 = (0,L,0)
    verts_list.append(Mathutils.Vector(p1))
    
    dv = Mathutils.Vector((d,0,0))
    step_v = Mathutils.Vector((0,L/steps,0))
    for i in range(steps):
        v_last = verts_list[len(verts_list)-1]
        if ((int(i) % 2) == 0):
            v = v_last+step_v+dv
        else:
            v = v_last+step_v-dv
        verts_list.append(v)
        ed = (i,i+1)
        edges_list.append(ed)

    verts_list.append(Mathutils.Vector(p2))
    
    stMeshName = "New_object"
    try:
        me_new = Mesh.Get(stMeshName)
    except NameError:
        me_new = Mesh.New()
    me_new.verts.extend(verts_list)
    me_new.edges.extend(edges_list)
#    me_new.faces.extend(faces_list)
    
    ob_new = Object.New("Mesh")
    ob_new.link(me_new)
    sce = Scene.GetCurrent()
    sce.objects.link(ob_new)
    sce.objects.selected = []
    ob_new.sel = 1
    ob_new.name = "ZigZag"
    return ob_new

#######################################

L = 5
d = 1
steps = 10

ob = Make_ZigZag(L,d,steps)
Redraw()
if (ob<>None):
    print ob.name
else:
    print "Zig-zag planned is too dense..."
print

It’s 2.4x… and can be re-worked a little to produce symmetric zig-zags and such with un-even (randomized) deviations left-right.

Regards,

Abidos Thanks for the example

but sorry may be i did not explain the type of zig zag line enough

i was not talking about an exact zig zag perfect line!
that’s too easy to do!

let me try again here

2 points in space like P1 and P2 in 3D
but could be reduce to the case of 2D also but would preder in 3D

P1 is the a starting point and P2 the final or destination point
now when you begin you sort of walk at random advancing a llittle on the right for a short distance then changing direction at random may be more right or left

but the average of this walk is around the direct line between the 2 Points

i don’t remember the English name for this type of line apart of zig zag
but i remember seeing this in a book of probability long time ago

another example of this would be like a neutron moving in a dense material
it’s not taking a straight path but more like a random zig zag path but in a given direction

another example might be like a fly or a butterfly going between 2 points it’s never flying in straight line but more like a sort of zig zag line!

another example would like a salesman going from door to door on either side of the street
he’s going on an average path on the street but zig zaging

the lenght of each step is random and the direction is more or less random
in the general direction to P2 and average path is between P1 and P2
but the total distance accumulated is more then the minimum distance between the 2 Points

hope you understand better what i mean here

Thanks

Well, in the previous code, replace the Make_ZigZag(L,d,steps) with Make_ZigZag_center(L,d,steps) and you will get it centered along OY axis (LEFT image)… Should you replace it by Make_ZigZag_center_rand(L,d,steps) - you will get it a way randomized (RIGHT image).

http://s2.sigmirror.com/files/93942_bp4sf/ZigZag_1.jpg

The two new procs are:

def Make_ZigZag_center(L,d,steps):
    L = L*1.0  # make it a real number....
    if L < threshold:
        return None
    verts_list = []
    edges_list = []
#    faces_list = []
    
    d = d/2.0
    p1 = (0,0,0)
    p2 = (0,L,0)
    verts_list.append(Mathutils.Vector(p1))
    
    dv = Mathutils.Vector((d,0,0))
    step_v = Mathutils.Vector((0,L/steps,0))
    for i in range(steps):
        delta_dv = 2*dv
        if (i==0) or (i==steps-1):  # if the first/last one
            delta_dv = dv
        v_last = verts_list[len(verts_list)-1]
        if ((int(i) % 2) == 0):
            v = v_last+step_v+delta_dv
        else:
            v = v_last+step_v-delta_dv
        verts_list.append(v)
        ed = (i,i+1)
        edges_list.append(ed)

    verts_list.append(Mathutils.Vector(p2))
    
    stMeshName = "New_object"
    try:
        me_new = Mesh.Get(stMeshName)
    except NameError:
        me_new = Mesh.New()
    me_new.verts.extend(verts_list)
    me_new.edges.extend(edges_list)
#    me_new.faces.extend(faces_list)
    
    ob_new = Object.New("Mesh")
    ob_new.link(me_new)
    sce = Scene.GetCurrent()
    sce.objects.link(ob_new)
    sce.objects.selected = []
    ob_new.sel = 1
    ob_new.name = "ZigZag"
    return ob_new

def Make_ZigZag_center_rand(L,d,steps):
    L = L*1.0  # make it a real number....
    if L < threshold:
        return None
    verts_list = []
    edges_list = []
#    faces_list = []
    
    d = d/2.0
    p1 = (0,0,0)
    p2 = (0,L,0)
    verts_list.append(Mathutils.Vector(p1))
    
    last_dv = Mathutils.Vector((0,0,0))
    step_v = Mathutils.Vector((0,L/steps,0))
    for i in range(steps):
        dv = Mathutils.Vector((d*random.random(),0,0))
        delta_dv = 2*dv
        if (i==0) or (i==steps-1):  # if the first/last one
            delta_dv = dv
        v_last = verts_list[len(verts_list)-1]
        if ((int(i) % 2) == 0):
            v = v_last+step_v+delta_dv-last_dv
        else:
            v = v_last+step_v-delta_dv-last_dv
        last_dv = Mathutils.Vector((v[0],0,0))
        verts_list.append(v)
        ed = (i,i+1)
        edges_list.append(ed)

    verts_list.append(Mathutils.Vector(p2))
    
    stMeshName = "New_object"
    try:
        me_new = Mesh.Get(stMeshName)
    except NameError:
        me_new = Mesh.New()
    me_new.verts.extend(verts_list)
    me_new.edges.extend(edges_list)
#    me_new.faces.extend(faces_list)
    
    ob_new = Object.New("Mesh")
    ob_new.link(me_new)
    sce = Scene.GetCurrent()
    sce.objects.link(ob_new)
    sce.objects.selected = []
    ob_new.sel = 1
    ob_new.name = "ZigZag"
    return ob_new

Making the zig-zag between any two points in 3D is a matter of 1 translation and 2 rotations of this zig-zag line along OY. I hope you are able to modify the script to achieve that :wink:

Regards,

CORRECTION:

Pls replace


    verts_list.append(Mathutils.Vector(p2))

with:


    verts_list.pop()
    verts_list.append(Mathutils.Vector(p2))
 

in both NEW procs as there is a vertex NOT needed before the last one… :eek:

tested with the fist one ok

random is also working

i will have to port this to 2.5
right now i work almost only with scripting in 2.5
also i’l try to modif this to aprametrize the line for 3D
i think that would be easier then trying to figure out angle in 3D!

Thanks

here is the code for random one




from Blender import *
import  random


threshold = 0.1




def Make_ZigZag_center(L,d,steps):
    L = L*1.0  # make it a real number....
    if L < threshold:
        return None
    verts_list = []
    edges_list = []
#    faces_list = []
    
    d = d/2.0
    p1 = (0,0,0)
    p2 = (0,L,0)
    verts_list.append(Mathutils.Vector(p1))
    
    dv = Mathutils.Vector((d,0,0))
    step_v = Mathutils.Vector((0,L/steps,0))
    for i in range(steps):
        delta_dv = 2*dv
        if (i==0) or (i==steps-1):  # if the first/last one
            delta_dv = dv
        v_last = verts_list[len(verts_list)-1]
        if ((int(i) % 2) == 0):
            v = v_last+step_v+delta_dv
        else:
            v = v_last+step_v-delta_dv
        verts_list.append(v)
        ed = (i,i+1)
        edges_list.append(ed)

    verts_list.append(Mathutils.Vector(p2))
    
    stMeshName = "New_object"
    try:
        me_new = Mesh.Get(stMeshName)
    except NameError:
        me_new = Mesh.New()
    me_new.verts.extend(verts_list)
    me_new.edges.extend(edges_list)
#    me_new.faces.extend(faces_list)
    
    ob_new = Object.New("Mesh")
    ob_new.link(me_new)
    sce = Scene.GetCurrent()
    sce.objects.link(ob_new)
    sce.objects.selected = []
    ob_new.sel = 1
    ob_new.name = "ZigZag"
    return ob_new

def Make_ZigZag_center_rand(L,d,steps):
    L = L*1.0  # make it a real number....
    if L < threshold:
        return None
    verts_list = []
    edges_list = []
#    faces_list = []
    
    d = d/2.0
    p1 = (0,0,0)
    p2 = (0,L,0)
    verts_list.append(Mathutils.Vector(p1))
    
    last_dv = Mathutils.Vector((0,0,0))
    step_v = Mathutils.Vector((0,L/steps,0))
    for i in range(steps):
        dv = Mathutils.Vector((d*random.random(),0,0))
        delta_dv = 2*dv
        if (i==0) or (i==steps-1):  # if the first/last one
            delta_dv = dv
        v_last = verts_list[len(verts_list)-1]
        if ((int(i) % 2) == 0):
            v = v_last+step_v+delta_dv-last_dv
        else:
            v = v_last+step_v-delta_dv-last_dv
        last_dv = Mathutils.Vector((v[0],0,0))
        verts_list.append(v)
        ed = (i,i+1)
        edges_list.append(ed)

    verts_list.append(Mathutils.Vector(p2))
    
    stMeshName = "New_object"
    try:
        me_new = Mesh.Get(stMeshName)
    except NameError:
        me_new = Mesh.New()
    me_new.verts.extend(verts_list)
    me_new.edges.extend(edges_list)
#    me_new.faces.extend(faces_list)
    
    ob_new = Object.New("Mesh")
    ob_new.link(me_new)
    sce = Scene.GetCurrent()
    sce.objects.link(ob_new)
    sce.objects.selected = []
    ob_new.sel = 1
    ob_new.name = "ZigZag"
    return ob_new
    
    
    

L = 10
d = 1
steps = 10

ob =  Make_ZigZag_center_rand(L,d,steps)

Redraw()

if (ob<>None):
    print ob.name
else:
    print "Zig-zag planned is too dense..."
print 'It s 2.4x..... and can be re-worked a little'
    
    

i’ll try to port to 2.5 tonight

Thanks

CORRECTION:

Pls replace


    verts_list.append(Mathutils.Vector(p2))

with:


    verts_list.pop()
    verts_list.append(Mathutils.Vector(p2))

in both NEW procs as there is a vertex NOT needed before the last one… :eek:

Regards,

here is the 2.5

can you test this
let me know what you think

load in tet editor run it then look in add the mesh at top of screen in GUI
and bys electing the mesh at the end you should see the new zig zag script
selet this and selet first or second choice

then you should have your tool panel open and check at bottom you’ll see all the vars with which you can play to change the zig zag line in 3D viewport


	
# ##### 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ##### END GPL LICENSE BLOCK #####
	
	
	
import bpy
import mathutils
from math import *
from bpy.props import *
import  random
	
	
	
"""
Name: 'General zigzag line 3D'
Blender: 250
	
"""
__author__ = ["Rickyblender"]
__version__ = '0.0.1'
__url__ = ["                       "]
__bpydoc__ = """
	
Usage:
	
	
"""
	
	
	
	
#####################################################################################################
	
	
	
	
#########################################################
	
def float2_range(start, stop, step = 1.0):
	
	""" Returns a list of floats in a range."""
	
	stop =stop 
	
	#steps allowed between start and stop
	total_steps = int((float(stop - start) / step))+1
#	print ' total_steps  =',total_steps 
	
	#return the list of floats
	return [float(start + (step * i)) for i in range(total_steps)]
	
#########################################################
	
	

	
	
	
	
#####################################################################################################
	
####################################
	
	
	
	
########################################################################
	
class Addzigzag1(bpy.types.Operator):
	
	'''Add a 45 D X 45 D Triang   mesh.'''
	
	bl_idname = "mesh.primitive_zigzag1_add"
	bl_label = "zig zag line 2D"
	bl_options = {'REGISTER', 'UNDO'}
	
	
	
	nseg = IntProperty(name="Segments ",
		description="N Segments ",
		default=16, min=4, max=500)
	
	
	bool1 = BoolProperty(name="boolean",
		description="boolean prop",
		default=False)
	
	L1 = FloatProperty(name="Total Lenght",
		description="Total Lenght",
		default=10.0, min=1, max=100.0)
	
	d1 = FloatProperty(name="Segment lenght",
		description="Segment lenght",
		default=1.0, min=1, max=25.0)
	
	steps = IntProperty(name="steps",
		description="steps ",
		default=10, min=2, max=100)
	
	
	
	threshold = FloatProperty(name="threshold",
		description="threshold",
		default=0.1, min=0.01, max=25.0)
	
	
	def execute(self, context):
		nseg = self.properties.nseg
		L1 = self.properties.L1
		d1 = self.properties.d1
		bool1 = self.properties.bool1
		steps = self.properties.steps
		threshold = self.properties.threshold
	
	
		verts = []
		faces = []
		verts_new = []
		faces_new = []
		me_newverts=[]
		me_newedges=[]
	
	
		print ('booL1 =',bool1)
		if bool1==False:
			print ('bool is false')
			bool1=True
	
		name="zig zag line 2D "
		print (name)
	
	
	
		L1 = L1*1.0  # make it a real number....
		if L1 < threshold:
			return None
		verts_list = []
		edges_list = []
#		faces_list = []
	
		d1 = d1/2.0
		p1 = (0,0,0)
		p2 = (0,L1,0)
		verts_list.append(mathutils.Vector(p1))
	
		dv = mathutils.Vector((d1,0,0))
		step_v = mathutils.Vector((0,L1/steps,0))
	
		for i in range(steps):
			delta_dv = 2*dv
			if (i==0) or (i==steps-1):  # if the first/last one
				delta_dv = dv
			v_last = verts_list[len(verts_list)-1]
			if ((int(i) % 2) == 0):
				v = v_last+step_v+delta_dv
			else:
				v = v_last+step_v-delta_dv
	
			verts_list.append(v)
			ed = (i,i+1)
			edges_list.append(ed)
	
		verts_list.append(mathutils.Vector(p2))
	
		name = "ZigZag"

		me_newverts.extend(verts_list)
		me_newedges.extend(edges_list)
	
	
	
		mesh = bpy.data.meshes.new(name)
		mesh.from_pydata(me_newverts, me_newedges,[])
	
		mesh.update()
	
	# Create a new Object.
	
		ob_new = bpy.data.objects.new(name, mesh)
		ob_new.data = mesh
		bpy.context.scene.objects.link(ob_new)
	
	
	#  Add some material

	
		return {'FINISHED'}
	
	
	
	
	
########################################################################
	
########################################################################
	
class Addzigzag2(bpy.types.Operator):
	
	'''Add a 45 D X 45 D Triang   mesh.'''
	
	bl_idname = "mesh.primitive_zigzag2_add"
	bl_label = "zig zag line Random 2D"
	bl_options = {'REGISTER', 'UNDO'}
	
	
	
	nseg = IntProperty(name="Segments ",
		description="N Segments ",
		default=16, min=4, max=500)
	
	
	bool1 = BoolProperty(name="boolean",
		description="boolean prop",
		default=False)
	
	L1 = FloatProperty(name="Total Lenght",
		description="Total Lenght",
		default=10.0, min=1, max=100.0)
	
	d1 = FloatProperty(name="Segment lenght",
		description="Segment lenght",
		default=1.0, min=1, max=25.0)
	
	steps = IntProperty(name="steps",
		description="steps ",
		default=10, min=2, max=100)
	
	
	
	threshold = FloatProperty(name="threshold",
		description="threshold",
		default=0.1, min=0.01, max=25.0)
	
	
	def execute(self, context):
		nseg = self.properties.nseg
		L1 = self.properties.L1
		d1 = self.properties.d1
		bool1 = self.properties.bool1
		steps = self.properties.steps
		threshold = self.properties.threshold
	
	
		verts = []
		faces = []
		verts_new = []
		faces_new = []
		me_newverts=[]
		me_newedges=[]
	
	
		print ('booL1 =',bool1)
		if bool1==False:
			print ('bool is false')
			bool1=True
	
		name="zig zag Random line 2D "
		print (name)
	
	
	
		L1 = L1*1.0  										# make it a real number....
		if L1 < threshold:
			return None
		verts_list = []
		edges_list = []
#		faces_list = []
	
		d1 = d1/2.0
		p1 = (0,0,0)
		p2 = (0,L1,0)
		verts_list.append(mathutils.Vector(p1))
	
		last_dv = mathutils.Vector((0,0,0))
		step_v = mathutils.Vector((0,L1/steps,0))
	
		for i in range(steps):
			dv = mathutils.Vector((d1*random.random(),0,0))
			delta_dv = 2*dv
			if (i==0) or (i==steps-1): 						 # if the first/last one
				delta_dv = dv
			v_last = verts_list[len(verts_list)-1]
			if ((int(i) % 2) == 0):
				v = v_last+step_v+delta_dv-last_dv
			else:
				v = v_last+step_v-delta_dv-last_dv
	
			last_dv = mathutils.Vector((v[0],0,0))
			verts_list.append(v)
			ed = (i,i+1)
			edges_list.append(ed)
	
		verts_list.append(mathutils.Vector(p2))
	
		name = "ZigZagrnd"

		me_newverts.extend(verts_list)
		me_newedges.extend(edges_list)
	
	
	
		mesh = bpy.data.meshes.new(name)
		mesh.from_pydata(me_newverts, me_newedges,[])
	
		mesh.update()
	
	# Create a new Object.
	
		ob_new = bpy.data.objects.new(name, mesh)
		ob_new.data = mesh
		bpy.context.scene.objects.link(ob_new)
	
	
	#  Add some material

	
		return {'FINISHED'}
	
	
	
	
	
########################################################################
	
	
	
##########################################################################
	
	
	
	#######################  Menu addition #####################
	
class INFO_MT_mesh_zigzag1_add(bpy.types.Menu):
	
	
	bl_idname = "INFO_MT_mesh_zigzag1_add"
	bl_label = "ZIG ZAG 3D line"
	
	def draw(self, context):
		layout = self.layout
		layout.operator_context = 'INVOKE_REGION_WIN'
		
	
		layout.operator("mesh.primitive_zigzag1_add",
			text="zigzag Line")
	
		layout.operator("mesh.primitive_zigzag2_add",
			text="zigzag Line Random")
	
	
######################################################
	
	
import space_info
menu_func = (lambda self,
	context: self.layout.menu("INFO_MT_mesh_zigzag1_add"))
	
	
# Register the operators/menus
	
	# First define the different  functions
	
def register():
	
	
	
	
	bpy.types.register(Addzigzag1)
	bpy.types.register(Addzigzag2)
	
	
	
	
	
	
	
	
# Then defined the Menu add function
	
	bpy.types.register(INFO_MT_mesh_zigzag1_add)
	
	space_info.INFO_MT_mesh_add.append(menu_func)
	
################################################################
	
	
def unregister():
	# Unregister the operators/menus.
	
	
	
	bpy.types.unregister(Addzigzag1)
	bpy.types.unregister(Addzigzag2)
	
	bpy.types.unregister(INFO_MT_mesh_zigzag1_add)
	
	
	space_info.INFO_MT_mesh_add.remove(menu_func)
	
	
	
	
#####################################################################
	
	
	
	
if __name__ == "__main__":
	register()
	
	
	
	
	
	
	
	
	
	
	
	
	
	
"""
	

#################################################################################
	
	
#####################################################################
	
	
	
	
"""




can you make a new version in 2.5

Thanks

sorry cannot edit last post too long ?

can you tell me in words how the algo works

also possible to change angle of segment
all seems to be the same ?

Thanks & happy 2.5

can the vectors wth mathutil do it in 3D?

or if i have to parametrize with a bezier line in 3D?

Thanks

Hi there!

I’ve just produced a proc (2.4x) which with parameters as follows (just an example):

d = 1
steps = 10
p1 = (1,2,1)
p2 = (2,6,-4)

ob = Make_ZigZag_3D_center_rand(p1,p2,d,steps)
Redraw()

seems to does the job in 3D… Here are projections of one of resulting 3D zig-zags:

http://s2.sigmirror.com/files/93964_p9fc5/ZigZag_2.jpg

You may check the coordinates to verify the script work.

But this time I am not going to publish the code here as RickyBlender copies almost 100% of my tonight’s products in a script w/o even mentioning my efforts. I think that is NO good and the only way to preventing further stealing of code is NOT to publish it here in this thread although I was trying the whole evening to help Ricky reach his goal. :no:

Regards,

hey sorry i just took another script i work on and did not even look there was a GNU license at the beginning of it !

usually at that stage i don’t even add that license only at the end
when it’s complete enough to make sense and be usefull as a script
right now it’s about only 1/4 of a script

your name is added at the beginning
mind you i don’t know if you like this license or not!
but probably need more info also
let me know what else!

also it’s not finish there are lot’s more function to be added for the 3D
it s only 2D for now like to continue on this but may take some time to complete

here is the new code wth your name in it


	
# ##### 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ##### END GPL LICENSE BLOCK #####
	
	
	
import bpy
import mathutils
from math import *
from bpy.props import *
import  random
	
	
	
"""
Name: 'General zigzag line 3D'
Blender: 250

Designer

Rickyblender

and 

Abidos  


	
"""
__author__ = ["Rickyblender"]
__version__ = '0.0.1'
__url__ = ["                       "]
__bpydoc__ = """
	
Usage:
	
	
"""
	


def float2_range(start, stop, step = 1.0):
	
	""" Returns a list of floats in a range."""
	
	stop =stop 
	
	#steps allowed between start and stop
	total_steps = int((float(stop - start) / step))+1
#	print ' total_steps  =',total_steps 
	
	#return the list of floats
	return [float(start + (step * i)) for i in range(total_steps)]
	
#########################################################
	
	

	
	
	
	
########################################################################
	
class Addzigzag1(bpy.types.Operator):
	
	'''Add a 45 D X 45 D Triang   mesh.'''
	
	bl_idname = "mesh.primitive_zigzag1_add"
	bl_label = "zig zag line 2D"
	bl_options = {'REGISTER', 'UNDO'}
	
	
	
	nseg = IntProperty(name="Segments ",
		description="N Segments ",
		default=16, min=4, max=500)
	
	
	bool1 = BoolProperty(name="boolean",
		description="boolean prop",
		default=False)
	
	L1 = FloatProperty(name="Total Lenght",
		description="Total Lenght",
		default=10.0, min=1, max=100.0)
	
	d1 = FloatProperty(name="Segment lenght",
		description="Segment lenght",
		default=1.0, min=1, max=25.0)
	
	steps = IntProperty(name="steps",
		description="steps ",
		default=10, min=2, max=100)
	
	
	
	threshold = FloatProperty(name="threshold",
		description="threshold",
		default=0.1, min=0.01, max=25.0)
	
	
	def execute(self, context):
		nseg = self.properties.nseg
		L1 = self.properties.L1
		d1 = self.properties.d1
		bool1 = self.properties.bool1
		steps = self.properties.steps
		threshold = self.properties.threshold
	
	
		verts = []
		faces = []
		verts_new = []
		faces_new = []
		me_newverts=[]
		me_newedges=[]
	
	
		print ('booL1 =',bool1)
		if bool1==False:
			print ('bool is false')
			bool1=True
	
		name="zig zag line 2D "
		print (name)
	
	
	
		L1 = L1*1.0  # make it a real number....
		if L1 < threshold:
			return None
		verts_list = []
		edges_list = []
#		faces_list = []
	
		d1 = d1/2.0
		p1 = (0,0,0)
		p2 = (0,L1,0)
		verts_list.append(mathutils.Vector(p1))
	
		dv = mathutils.Vector((d1,0,0))
		step_v = mathutils.Vector((0,L1/steps,0))
	
		for i in range(steps):
			delta_dv = 2*dv
			if (i==0) or (i==steps-1):  # if the first/last one
				delta_dv = dv
			v_last = verts_list[len(verts_list)-1]
			if ((int(i) % 2) == 0):
				v = v_last+step_v+delta_dv
			else:
				v = v_last+step_v-delta_dv
	
			verts_list.append(v)
			ed = (i,i+1)
			edges_list.append(ed)
	
		verts_list.append(mathutils.Vector(p2))
	
		name = "ZigZag"

		me_newverts.extend(verts_list)
		me_newedges.extend(edges_list)
	
	
	
		mesh = bpy.data.meshes.new(name)
		mesh.from_pydata(me_newverts, me_newedges,[])
	
		mesh.update()
	
	# Create a new Object.
	
		ob_new = bpy.data.objects.new(name, mesh)
		ob_new.data = mesh
		bpy.context.scene.objects.link(ob_new)
	
	
	#  Add some material

	
		return {'FINISHED'}
	
	
	
	

########################################################################
	
class Addzigzag2(bpy.types.Operator):
	
	'''Add a 45 D X 45 D Triang   mesh.'''
	
	bl_idname = "mesh.primitive_zigzag2_add"
	bl_label = "zig zag line Random 2D"
	bl_options = {'REGISTER', 'UNDO'}
	
	
	
	nseg = IntProperty(name="Segments ",
		description="N Segments ",
		default=16, min=4, max=500)
	
	
	bool1 = BoolProperty(name="boolean",
		description="boolean prop",
		default=False)
	
	L1 = FloatProperty(name="Total Lenght",
		description="Total Lenght",
		default=10.0, min=1, max=100.0)
	
	d1 = FloatProperty(name="Segment lenght",
		description="Segment lenght",
		default=1.0, min=1, max=25.0)
	
	steps = IntProperty(name="steps",
		description="steps ",
		default=10, min=2, max=100)
	
	
	
	threshold = FloatProperty(name="threshold",
		description="threshold",
		default=0.1, min=0.01, max=25.0)
	
	
	def execute(self, context):
		nseg = self.properties.nseg
		L1 = self.properties.L1
		d1 = self.properties.d1
		bool1 = self.properties.bool1
		steps = self.properties.steps
		threshold = self.properties.threshold
	
	
		verts = []
		faces = []
		verts_new = []
		faces_new = []
		me_newverts=[]
		me_newedges=[]
	
	
		print ('booL1 =',bool1)
		if bool1==False:
			print ('bool is false')
			bool1=True
	
		name="zig zag Random line 2D "
		print (name)
	
	
	
		L1 = L1*1.0  										# make it a real number....
		if L1 < threshold:
			return None
		verts_list = []
		edges_list = []
#		faces_list = []
	
		d1 = d1/2.0
		p1 = (0,0,0)
		p2 = (0,L1,0)
		verts_list.append(mathutils.Vector(p1))
	
		last_dv = mathutils.Vector((0,0,0))
		step_v = mathutils.Vector((0,L1/steps,0))
	
		for i in range(steps):
			dv = mathutils.Vector((d1*random.random(),0,0))
			delta_dv = 2*dv
			if (i==0) or (i==steps-1): 						 # if the first/last one
				delta_dv = dv
			v_last = verts_list[len(verts_list)-1]
			if ((int(i) % 2) == 0):
				v = v_last+step_v+delta_dv-last_dv
			else:
				v = v_last+step_v-delta_dv-last_dv
	
			last_dv = mathutils.Vector((v[0],0,0))
			verts_list.append(v)
			ed = (i,i+1)
			edges_list.append(ed)
	
		verts_list.append(mathutils.Vector(p2))
	
		name = "ZigZagrnd"

		me_newverts.extend(verts_list)
		me_newedges.extend(edges_list)
	
	
	
		mesh = bpy.data.meshes.new(name)
		mesh.from_pydata(me_newverts, me_newedges,[])
	
		mesh.update()
	
	# Create a new Object.
	
		ob_new = bpy.data.objects.new(name, mesh)
		ob_new.data = mesh
		bpy.context.scene.objects.link(ob_new)
	
	
	#  Add some material

	
		return {'FINISHED'}
	
	
	

	
	#######################  Menu addition #####################
	
class INFO_MT_mesh_zigzag1_add(bpy.types.Menu):
	
	
	bl_idname = "INFO_MT_mesh_zigzag1_add"
	bl_label = "ZIG ZAG 3D line"
	
	def draw(self, context):
		layout = self.layout
		layout.operator_context = 'INVOKE_REGION_WIN'
		
	
		layout.operator("mesh.primitive_zigzag1_add",
			text="zigzag Line")
	
		layout.operator("mesh.primitive_zigzag2_add",
			text="zigzag Line Random")
	
	

	
import space_info
menu_func = (lambda self,
	context: self.layout.menu("INFO_MT_mesh_zigzag1_add"))
	
	
# Register the operators/menus
	
	# First define the different  functions
	
def register():
	
	
	
	
	bpy.types.register(Addzigzag1)
	bpy.types.register(Addzigzag2)
	
	
	
	
	
	
	
	
# Then defined the Menu add function
	
	bpy.types.register(INFO_MT_mesh_zigzag1_add)
	
	space_info.INFO_MT_mesh_add.append(menu_func)
	
	
	
def unregister():
	# Unregister the operators/menus.
	
	
	
	bpy.types.unregister(Addzigzag1)
	bpy.types.unregister(Addzigzag2)
	
	bpy.types.unregister(INFO_MT_mesh_zigzag1_add)
	
	
	space_info.INFO_MT_mesh_add.remove(menu_func)
	
	
	
if __name__ == "__main__":
	register()
	
	
	


got to reduce the lenght it’s close to the limit of 10000 letters i think
i already had warning in one post for this limit!

did you try it in 2.5
any tough on the vars in tool panel ?

Thaks & happy 2.5

I dont work with 2.5. Under your asking for help, I developed several functions from scratch… up to Make_ZigZag_3D_center_rand(p1,p2,d,steps). I may put the latter in my modules so that people use it. If independant, it only needs an inteface - a matter of another 1/2 hour work for me some day cause it wasnt my project and my goal at present.

Wish you a good luck with your new functions!

i think since last january i did not work with 2.49 i mean scripting
i know if your working on big project 2.49 is still the best one for now

but inside a year it will be 2.5
you begin to get use with 2.5 slowly cause there are so many things that have change
like new GUI location of vars in different panels.

it’s not difficult but when you begin you search things and don’t find them!
but overall 2.5 is better organise and more logical then 2.49
also when you learn where things are located i think it’s even faster to work with

i’ll work out a bit more on the algo to better understand and test some new things to get more results no rush for now so that may take a month or 2 before having enough different choices for different applications in futur projects

thanks and happy 2.5