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
add_mesh_torus.py located in .blender\scripts\op in order to get a basic
GUI going on.


# ##### BEGIN GPL LICENSE BLOCK #####
#  go read it.
# ##### END GPL LICENSE BLOCK #####

# <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 = self.properties

  #  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():
    bpy.types.register(AddTree)
    bpy.types.INFO_MT_mesh_add.append(menu_func)


def unregister():
    bpy.types.unregister(AddTree)
    bpy.types.INFO_MT_mesh_add.remove(menu_func)

if __name__ == "__main__":
    register()

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

Thanks

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




    def execute(self, context):
        props = self.properties

  #  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 :
http://digitalaphasia.com/images/blender/Menu_tree.jpg

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

salutations

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 galore.py 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

http://digitalaphasia.com/code/Python/mod3_preCode.jpg

the most basic form of box grouping, maybe this will help some folks.
http://digitalaphasia.com/code/Python/BasicBoxGui.py

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)?

reads


Creation and Rendering of Realistic Trees

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

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