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):
  File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\addons\add_curve_sapling\__init__.py", line 911, in execute
  File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\addons\add_curve_sapling\utils.py", line 1424, in addTree
    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.


Adding the 'INVOKE_DEFAULT' Execution Context to your operator call


"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"

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. Search for bend around line 713 and remove the quotes """ from above and below the property definition.

enter image description here

Save the text file, hit F8 to reload addons. Now it will execute correctly with

  • 1
    $\begingroup$ This has the effect of ignoring parameters and uses only the defaults - any other ideas if I want to provide actual parameters? $\endgroup$ – Oliver Oct 7 '17 at 11:22
  • $\begingroup$ @Oliver correct, looked into it and added needed edit above. Prob needs reporting to tracker. $\endgroup$ – batFINGER Oct 7 '17 at 12:41
  • $\begingroup$ @Oliver also check out github.com/abpy/improved-sapling-tree-generator $\endgroup$ – 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(" ").

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.