Blender 2.5 Python Parametric Tree Script

In order to get a grip on this stuff i ripped out what i thought was not important from located in .blender\scripts\op in order to get a basic
GUI going on.

#  go read it.

# <pep8 compliant>
import bpy
import mathutils
from bpy.props import *
#from math import cos, sin, pi

class AddTree(bpy.types.Operator):
    '''Add a tree mesh'''
    bl_idname = "mesh.primitive_tree_add"
    bl_label = "Add Tree"
    bl_options = {'REGISTER', 'UNDO'}

    # Trunk

    trunk_base_radius = FloatProperty(name="Trunk Base Radius",
            description="Radius of the Trunk Base",
            default=1.0, min=0.1, max=5.0)
    trunk_end_radius = IntProperty(name="End Radius",
            description="Radius of end of the trunk",
            default=50, min=1, max=100)
    trunk_segments = IntProperty(name="Trunk Segments",
            description="Number of segments from the base to terminator",
            default=3, min=1, max=10)
    trunk_num_branches = IntProperty(name="Number Trunk Branches",
            description="Number of branches attached to the trunk",
            default=1, min=0, max=10)
    trunk_height = FloatProperty(name="Trunk Height",
            description="The z location of the trunk_end",
            default=6.0, min=1.0, max=13.0)

    # Branch
    branch_base_thickness = IntProperty(name="Branch Base Thickness",
            description="Thickness of the base of the branch, as a percentage of the area it is connecting to",
            default=80, min=1, max=100)
    branch_length = FloatProperty(name="Standard Branch Length",
            description="Used to state the modal length, other parameters provide a way to deviate from it",
            default=2.0, min=0.1, max=5.0)
    branch_end_thickness = IntProperty(name="Branch End Thickness",
            description="Thickness of the end of the branch, as a percentage of the branch base",
            default=80, min=1, max=100)
    branch_subbranches = IntProperty(name="Number of sub branches",
            description="Number of branches along this branch",
            default=1, min=0, max=20)
    branch_segments = IntProperty(name="Branch Segments",
            description="Number of segments along the branch",
            default=3, min=1, max=10)
    branch_segment_variation = IntProperty(name="segment randomfactor",
            description="The randomization factor per branch",
            default=6, min=0, max=100)

    # Foliage
    leaf_count = IntProperty(name="Leaf quantity",
            description="The number of leaves per branch",
            default=10, min=0, max=200)
    leaf_count_randomization = IntProperty(name="leaf randomfactor",
            description="The randomization factor per branch",
            default=6, min=0, max=100)
    leaf_size = FloatProperty(name="Leaf Size",
            description="Size of leaf using a float type",
            default=1.0, min=0.1, max=3.0)
    leaf_size_randomization = IntProperty(name="Leaf size randomization",
            description="Percentage to deviate from modal size",
            default=1, min=-20, max=20)

  #  def execute(self, context):
  #      props =

  #  import add_object_utils
  #  add_object_utils.add_object_data(context, mesh, operator=self)
  #  return {'FINISHED'}

def menu_func(self, context):
    self.layout.operator(AddTree.bl_idname, text="Tree", icon='MESH_DONUT')

def register():

def unregister():

if __name__ == "__main__":

perhaps some brighter mind can point me to a tutorial on the GUI side,
i’m constructing the rest of the script now, some tips would be appreciated

where are the buttons supposed to appear here
in operator panel ?

cause i don’t see any buttons yet ?

i have to run the twisted torus script and see what happen there


if you add theses lines at least you can see the tree panel

    def execute(self, context):
        props =

  #  import add_object_utils
  #  add_object_utils.add_object_data(context, mesh, operator=self)
        return {'FINISHED'}

sweet. thanks RickyBlender. i’m such a n00b :slight_smile:

so now i can hookup stuff. currently dummy script produces the menu below :

are there any formatting tags that could be applied to the GUI, i would like to
group the parameters visually.

might be able to do somerows , columns but
more complicated to do
need to add a draw function ect…
and then the window would have to be much wider which reduce the space for the viewport!

till we get an independant script space better keep it simple as it is

so begin to do your part for the calculations

may be later think about changing the look


to have the operator draw different from default you need to define the draw function:

def draw(self,context):
    layout = self.layout

then you can add rows, columns and boxes in which you can add labels, props and/or operators.
you can also add a seperator for grouping.

to see how that work i’dd like to redirect you to examples as curvacious in the addon folder, that one has a rather complex drawing function, but covers everything

hope that helps

OK. i made mini progress on the GUI side, thanks dreampainter for pointing out that i can choose to draw menu’s by doing the

  def draw(self, context):
        layout = self.layout

the most basic form of box grouping, maybe this will help some folks.

now for the interesting bits :slight_smile:

why not to port one of the 2.49 tree scripts? like l-system or tree from curves

lsystem is being worked on by aeonsien,
I have not heard news for a few weeks on that one.

Gen3 would be a good one to clean up & bring forward.

neither Lsystem or Gen3 are familiar to me, care to share gen3/ ( if Lsystem is being worked on)?


Creation and Rendering of Realistic Trees

you can get gen3 in the scripts bundle here: Wiki Bundles

ah yes. thankyou :slight_smile: good material to study.