# Creating Sapling Tree in the Python Console

I'm trying to create a Sapling Tree object using Python. The Sapling Tree is an object that comes from this add-on: https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Sapling_Tree

I'm able to create it using the UI (Add > Curve > Sapling Tree Gen). I can see the command executed by the UI in the Info window. That command is:

bpy.ops.curve.tree_add(do_update=True, bevel=False, prune=False, showLeaves=False, useArm=False, seed=0, handleType='0', levels=2, length=(1, 0.3, 0.6, 0.45), lengthV=(0, 0, 0, 0), taperCrown=0, branches=(0, 50, 30, 10), curveRes=(8, 5, 3, 1), curve=(0, -40, -40, 0), curveV=(20, 50, 75, 0), curveBack=(0, 0, 0, 0), baseSplits=0, segSplits=(0, 0, 0, 0), splitByLen=True, rMode='rotate', splitAngle=(0, 0, 0, 0), splitAngleV=(0, 0, 0, 0), scale=13, scaleV=3, attractUp=(0, 0, 0.5, 0.5), attractOut=(0, 0, 0, 0), shape='7', shapeS='4', customShape=(0.5, 1, 0.3, 0.5), branchDist=1, nrings=0, baseSize=0.4, baseSize_s=0.25, splitHeight=0.2, splitBias=0, ratio=0.015, minRadius=0.0015, closeTip=False, rootFlare=1, autoTaper=True, taper=(1, 1, 1, 1), radiusTweak=(1, 1, 1, 1), ratioPower=1.1, downAngle=(90, 110, 45, 45), downAngleV=(0, 80, 10, 10), useOldDownAngle=False, useParentAngle=True, rotate=(99.5, 137.5, 137.5, 137.5), rotateV=(15, 0, 0, 0), scale0=1, scaleV0=0.1, pruneWidth=0.4, pruneBase=0.3, pruneWidthPeak=0.6, prunePowerHigh=0.5, prunePowerLow=0.001, pruneRatio=1, leaves=25, leafDownAngle=45, leafDownAngleV=10, leafRotate=137.5, leafRotateV=0, leafScale=0.17, leafScaleX=1, leafScaleT=0, leafScaleV=0, leafShape='hex', leafangle=0, horzLeaves=True, leafDist='6', bevelRes=0, resU=4, armAnim=False, previewArm=False, leafAnim=False, frameRate=1, loopFrames=0, wind=1, gust=1, gustF=0.075, af1=1, af2=1, af3=4, makeMesh=False, armLevels=2, boneStep=(1, 1, 1, 1))


But, when I copy and paste that command into the Python Console and run it, I get this error:

Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\modules\bpy\ops.py", line 189, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Error: Traceback (most recent call last):
bend = props.bend#
File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\modules\bpy_types.py", line 605, in __getattribute__
return super().__getattribute__(attr)
AttributeError: 'AddTree' object has no attribute 'bend'

location: C:\Program Files\Blender Foundation\Blender\2.78\scripts\modules\bpy\ops.py:189


I am able to copy and paste the UI command for creating a native object (i.e. a bezier curve), and that works just fine. I'm not sure whether this error has to do the Sapling Tree specifically, or applies to all add-on objects.

I understand that using bpy.opscommands are notoriously finicky, but I cannot find any other method to create the Sapling Tree since it isn't a native object.

I am running Blender 2.78 64-bit on Windows 10.

Using 'INVOKE_DEFAULT' Execution Context to your operator call always creates default

bpy.ops.curve.tree_add('INVOKE_DEFAULT')


"Basically" this emulates the pressing (invoking) of button / menu in UI, and calls the invoke method, that in this case is required. This will create the default tree "quaking aspen"

Note using 'INVOKE' is calling the preset

bpy.ops.sapling.importdata(filename="callistemon.py") is hardcoded into the invoke method, changing other settings with 'INVOKE_DEFAULT' will have no effect. Will always get this sucker when invoked.

Fixing to call from command line.

Edit: it appears the bend parameter has been not completely edited out of the addon. . For now to fix, run the addon and right click on any operator property and "view source". This will open __init__.py from the addon in your text editor. (Or go to addons/add_curve_sapling in filebrowser and open with text editor of choice)

Search for bend around line 713 and remove the quotes """ from above and below the property definition.

EDIT

As of 2.83 still need to make edit above as well as commenting out line 1611 in utils.py

#cu.use_uv_as_generated = True


Or for 2.8 run

bpy.ops.script.reload()


Now it will execute correctly with

bpy.ops.curve.tree_add(some_parameter=some_setting)


Test in 2.83 using command from question crunched into console I get

producing

• This has the effect of ignoring parameters and uses only the defaults - any other ideas if I want to provide actual parameters? – Oliver Oct 7 '17 at 11:22
• @Oliver correct, looked into it and added needed edit above. Prob needs reporting to tracker. – batFINGER Oct 7 '17 at 12:41
• @Oliver also check out github.com/abpy/improved-sapling-tree-generator – batFINGER Oct 7 '17 at 18:16

Ok here is what worked for me: Go to your add-on folder - add_curve_sapling and right click on the init.py file. Choose edit in notepad. Use Shortcut cmd+f and type in "bend". Get rid of every comment #Hashtag where it says something with "bend "unless the one which says box.label(" ").

• Deleting comments does absolutely nothing to the functionality of the code. This is not a viable answer. – JakeD Apr 10 '17 at 11:31
• I just searched for "bend" in here and none of the lines it turns up are commented. – David Apr 10 '17 at 12:37
• Needed the INVOKE_DEFAULT execution context, see answer. – batFINGER May 15 '17 at 8:21
• Yes - this line is a bug "bend = props.bend". Either commend this line or un-comment the property inside init.py – Oliver Oct 7 '17 at 11:36
• @JakeD Yes, I believe he means to delete the comment hashtags, not the core commented text. In other words, make it used code again. – Michael Macha Sep 8 '19 at 19:29