This script works, but can it be simplified?

blender -P simplify.txt

This python 3.4.2 script works with blender 2.72b

to create 3 objects, UNION them together, insert armatures.

What lines can be deleted?

What lines can be put into a sub-routine?

What lines can be combined together?

How to select border and extrude?

How can the armatures stay with thier objects?

How can the armatures move? try bpy.ops.armature.parent_set(type=‘CONNECTED’)

Is this the correct way to rotate? value=(11) seems strange for ninety degrees.

How can view zoom out?

How can everything scale down?

how to render?

import bpy

Create a simple cylinder. Body.

bpy.ops.mesh.primitive_cylinder_add()

Get the cylinder object and rename it. Body.

Body = bpy.context.object
Body.name = ‘Body’

Create a simple cylinder. Trunk.

bpy.ops.mesh.primitive_cylinder_add()

Resize the cylinder. Trunk. horizontal(“x: 135”) deep(“y: 135”) vertical(“z: 250”)

bpy.ops.transform.resize(value=(135, 135, 250))

Get the cylinder object and rename it. Trunk.

Trunk = bpy.context.object
Trunk.name = ‘Trunk’

Create a boolean modifier named ‘my_bool_mod’ for the cylinder.

mod_bool = Body.modifiers.new(‘my_bool_mod’, ‘BOOLEAN’)

Set the mode of the modifier to UNION.

mod_bool.operation = ‘UNION’

Set the object to be used by the modifier.

mod_bool.object = Trunk

The modifier_apply function only works on the active object.

Set Body as the active object.

bpy.context.scene.objects.active = Body

Apply the modifier.

Body = bpy.ops.object.modifier_apply(modifier = ‘my_bool_mod’)

Delete the part.

Trunk.select = True
bpy.ops.object.delete()
Body = bpy.context.object
Body.name = ‘Body’

Create a simple cylinder. Up Arm Left.

bpy.ops.mesh.primitive_cylinder_add()

Rotate.

bpy.ops.transform.rotate(value=(11),axis=(0, 1, 0))

Resize the cylinder. Up Arm Left. horizontal,long(“x: 90”) deep,wide(“y: 30”) vertical,wide(“z: 30”)

bpy.ops.transform.resize(value=(90, 30, 30))

Get the cylinder object and rename it. Up Arm Left.

Up_Arm_Left = bpy.context.object
Up_Arm_Left.name = ‘Up_Arm_Left’

Change the location of the cylinder. Up Arm Left. +x, 0y, +z

horizontal(“x: 135+90=225”) deep(“y: 0”) vertical(“z: 250-30=220”)

Up_Arm_Left.location = (225, 0, 220)

Create a boolean modifier named ‘my_bool_mod’ for the cylinder.

mod_bool = Body.modifiers.new(‘my_bool_mod’, ‘BOOLEAN’)

Set the mode of the modifier to UNION.

mod_bool.operation = ‘UNION’

Set the object to be used by the modifier.

mod_bool.object = Up_Arm_Left

The modifier_apply function only works on the active object.

Set Body as the active object.

bpy.context.scene.objects.active = Body

Apply the modifier.

Body = bpy.ops.object.modifier_apply(modifier = ‘my_bool_mod’)

Delete the part.

Up_Arm_Left.select = True
bpy.ops.object.delete()
Body = bpy.context.object
Body.name = ‘Body’

Create armature and object

amt = bpy.data.armatures.new(‘MyRigData’)
rig = bpy.data.objects.new(‘MyRig’, amt)

Link object to scene

scn = bpy.context.scene
scn.objects.link(rig)
scn.objects.active = rig

Create bones +x, 0y, +z

bpy.ops.object.mode_set(mode=‘EDIT’)
bone = amt.edit_bones.new(‘Up_Arm.L’)

head horizontal,long(“x: 225-90”) deep,(“y: 0”) vertical,(“z: 220”)

bone.head = (135, 0, 220)

head horizontal,long(“x: 225+90”) deep,(“y: 0”) vertical,(“z: 220”)

bone.tail = (315, 0, 220)

Create a simple cylinder. Lo Arm Left.

bpy.ops.mesh.primitive_cylinder_add()

Rotate.

bpy.ops.transform.rotate(value=(11),axis=(0, 1, 0))

Resize the cylinder. Lo Arm Left. horizontal,long(“x: 90”) deep,wide(“y: 20”) vertical,wide(“z: 20”)

bpy.ops.transform.resize(value=(90, 20, 20))

Get the cylinder object and rename it. Lo Arm Left.

Lo_Arm_Left = bpy.context.object
Lo_Arm_Left.name = ‘Lo_Arm_Left’

Change the location of the cylinder. Lo Arm Left. +x, 0y, +z

Body+Up Arm Left+Lo Arm Left+Lo Arm Left=135+90+90+90=405

horizontal(“x: 135+90+90+90=405”) deep(“y: 0”) vertical(“z: 250-30=220”)

Lo_Arm_Left.location = (405, 0, 220)

Create a boolean modifier named ‘my_bool_mod’ for the cylinder.

mod_bool = Body.modifiers.new(‘my_bool_mod’, ‘BOOLEAN’)

Set the mode of the modifier to UNION.

mod_bool.operation = ‘UNION’

Set the object to be used by the modifier.

mod_bool.object = Lo_Arm_Left

The modifier_apply function only works on the active object.

Set Body as the active object.

bpy.context.scene.objects.active = Body

Apply the modifier.

Body = bpy.ops.object.modifier_apply(modifier = ‘my_bool_mod’)

Delete the part.

Lo_Arm_Left.select = True
bpy.ops.object.delete()
Body = bpy.context.object
Body.name = ‘Body’

Create armature and object

amt = bpy.data.armatures.new(‘MyRigData’)
rig = bpy.data.objects.new(‘MyRig’, amt)

Link object to scene

scn = bpy.context.scene
scn.objects.link(rig)
scn.objects.active = rig

Create bones

bpy.ops.object.mode_set(mode=‘EDIT’)
bone = amt.edit_bones.new(‘Lo_Arm.L’)

head horizontal,long(“x: 225-90”) deep,(“y: 0”) vertical,(“z: 220”)

bone.head = (315, 0, 220)

head horizontal,long(“x: 225+90”) deep,(“y: 0”) vertical,(“z: 220”)

bone.tail = (405, 0, 220)