Thursday, September 20, 2018

blender scripting intro (extruding bones, making mesh)

Hi,

I'm very new to scripting in blender but wanted to share some tips that were helpful in making these two hello world examples:

making a couple cubes:

creating an armature and extruding a few bones:


so far i tried the layout setup with ‘info’ panel open on left, ‘text editor’ panel on upper right, ‘python console’ on upper left.

###making a few cubes then scaling them:

import bpy
for x in range(5):
    bpy.ops.mesh.primitive_cube_add(location=(x,0,0))
    bpy.ops.transform.resize(value=(.25,.25,.25))
 
can learn function by manually making a cube and reading command from ‘info’ panel.
can find more info on parameters by search google ex: ‘blender primitive_cube_add’


###making a few extruded bones in an armature

import bpy

#starting in object mode
bpy.ops.object.armature_add(location=(0,0,0),enter_editmode=True)
for x in range(10):
    bpy.ops.armature.extrude_move(TRANSFORM_OT_translate={"value":(0,0,.25)} )
    

google searched:
‘bpy switch to object mode’ to find command to switch to object mode

import bpy

#to make sure we start in object mode
bpy.ops.object.mode_set(mode='OBJECT')

bpy.ops.object.armature_add(location=(0,0,0),enter_editmode=True)
for x in range(10):
    bpy.ops.armature.extrude_move(TRANSFORM_OT_translate={"value":(0,0,.25)} )

another way to find command to set mode.
could have read from ‘info’ panel when click between modes:
bpy.ops.object.editmode_toggle()
Then could google search “blender bpy.ops.object” and look through api for setting the mode to find ‘mode_set’

Happy Sketching,
Nate