1
$\begingroup$

I am quite new to Blender and scripting in it. I am looking for a way to use IvyGen in script, but found no tutorials. I checked the Info panel in Blender, but it only says

bpy.ops.object.editmode_toggle()
bpy.ops.object.editmode_toggle()
bpy.ops.curve.ivy_gen(updateIvy=False)

whenever I add an ivy. I am expecting to see more parameters (to control the location, the appearance, etc.) than just it. Indeed, I've tried to run these commands on Blender Python console, but just got:

{'PASS_THROUGH'}

So I am wondering if you could help me understand how scripting is actually working with ivy_gen and maybe some guide of how I can get started with it.

$\endgroup$
1
  • $\begingroup$ This should be an answer. $\endgroup$
    – cmomoney
    Feb 13, 2017 at 15:16

2 Answers 2

2
$\begingroup$

You can call the ivy_gen operator with specific values for all the parameters you would later edit in the context menu:

bpy.ops.curve.ivy_gen(
    maxIvyLength         = 1,
    primaryWeight        = 0.5,
    randomWeight         = 0.2,
    gravityWeight        = 1,
    adhesionWeight       = 0.1,
    branchingProbability = 0.05,
    leafProbability      = 0.35,
    ivySize              = 0.02,
    ivyLeafSize          = 0.02,
    ivyBranchSize        = 0.001,
    maxFloatLength       = 0.5,
    maxAdhesionDistance  = 1,
    randomSeed           = 0,
    maxTime              = 0,
    growLeaves           = True,
    updateIvy            = False
)

To fully automate this, all you need to do prior to calling this operator is to place the 3D cursor where you want your ivy to start growing:

bpy.context.scene.cursor_location = (x,y,z)

And to also select the object you want to grow your ivy on:

bpy.context.scene.objects['MyObject'].select = True
bpy.context.scene.objects.active             = bpy.context.scene.objects['MyObject']
$\endgroup$
0
$\begingroup$

In case anyone needs an updated version of the code running on Blender 4:) I made the following script to set ivy gen parameters, select vertices, and apply the ivy gen.

def set_ivy_gen_parameters():
"""Set IvyGen parameters."""
bpy.data.window_managers["WinMan"].ivy_gen_props.maxIvyLength = 3
bpy.data.window_managers["WinMan"].ivy_gen_props.ivySize = 0.05
bpy.data.window_managers["WinMan"].ivy_gen_props.maxFloatLength = 0.53
bpy.data.window_managers["WinMan"].ivy_gen_props.maxAdhesionDistance = 1.03
bpy.data.window_managers["WinMan"].ivy_gen_props.primaryWeight = 0.59
bpy.data.window_managers["WinMan"].ivy_gen_props.randomWeight = 0.23
bpy.data.window_managers["WinMan"].ivy_gen_props.adhesionWeight = 0.25
bpy.data.window_managers["WinMan"].ivy_gen_props.branchingProbability = 0.08
bpy.data.window_managers["WinMan"].ivy_gen_props.ivyBranchSize = 0.031
bpy.data.window_managers["WinMan"].ivy_gen_props.ivyLeafSize = 0.05
bpy.data.window_managers["WinMan"].ivy_gen_props.leafProbability = 0.38
bpy.data.window_managers["WinMan"].ivy_gen_props.growLeaves = False

def generate_ivy(obj, vert_index):
    """Generate ivy on the specified object at the given vertex index."""
    vert = obj.data.vertices[vert_index]
    bpy.context.scene.cursor.location = obj.matrix_world @ vert.co
    bpy.context.view_layer.objects.active = obj
    obj.select_set(True)
    bpy.ops.curve.ivy_gen(updateIvy=True, defaultIvy=False)

this part allows you to change the parameters of the ivy_gen

def set_ivy_gen_parameters():
"""Set IvyGen parameters."""
bpy.data.window_managers["WinMan"].ivy_gen_props.maxIvyLength = 3
bpy.data.window_managers["WinMan"].ivy_gen_props.ivySize = 0.05
bpy.data.window_managers["WinMan"].ivy_gen_props.maxFloatLength = 0.53
bpy.data.window_managers["WinMan"].ivy_gen_props.maxAdhesionDistance = 1.03
bpy.data.window_managers["WinMan"].ivy_gen_props.primaryWeight = 0.59
bpy.data.window_managers["WinMan"].ivy_gen_props.randomWeight = 0.23
bpy.data.window_managers["WinMan"].ivy_gen_props.adhesionWeight = 0.25
bpy.data.window_managers["WinMan"].ivy_gen_props.branchingProbability = 0.08
bpy.data.window_managers["WinMan"].ivy_gen_props.ivyBranchSize = 0.031
bpy.data.window_managers["WinMan"].ivy_gen_props.ivyLeafSize = 0.05
bpy.data.window_managers["WinMan"].ivy_gen_props.leafProbability = 0.38
bpy.data.window_managers["WinMan"].ivy_gen_props.growLeaves = False

This part allows you to generate the ivy on specific vertices on objects.

def generate_ivy(obj, vert_index):
    """Generate ivy on the specified object at the given vertex index."""
    vert = obj.data.vertices[vert_index]
    bpy.context.scene.cursor.location = obj.matrix_world @ vert.co
    bpy.context.view_layer.objects.active = obj
    obj.select_set(True)
    bpy.ops.curve.ivy_gen(updateIvy=True, defaultIvy=False)

Finally, this is where you can define the object and its vertices.

obj = bpy.data.objects['Your_Object_Name']
generate_ivy(obj, 15)

I hope this helps!!

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .