This tutorial shows you a simple example of python scripting into Blender 3D software.
You need to select the window for scripting and to test with python scripting shell.
First, you need to add one object: cube.
The default script and most common python script, start with this :
1 2 3 4 5 6 7 8 | >>> import bpy >>> import math >>> from bpy import context >>> from math import sin, cos, radians >>> cubeobject = bpy.ops.mesh.primitive_cube_add >>> cursor = context.scene.cursor_location >>> print(cursor) ... |
You need to see the print python function because will use python ver. 3.
Also, the cube object and cursor vars will take the all you need to use it.
Now, this myvar variable shows you how to deal with python 3.
1 2 3 | >>> myvar=22 >>> print(myvar) 22 |
The next two python script will make editable or not the object: your cube.
1 2 | >>> bpy.ops.object.editmode_toggle() {'FINISHED'} |
… now the next line will change it into Object Mode ( can also use TAB key).
1 2 | >>> bpy.ops.object.editmode_toggle() {'FINISHED'} |
The goal of the edit mode_toggle function can be when you will use vertices.
The changing color of the cube can be done with these functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | >>> bpy.context.object.active_material.diffuse_ color fresnel fresnel_factor intensity ramp ramp_blend ramp_factor ramp_input shader toon_size toon_smooth >>> bpy.context.object.active_material.diffuse_color=(0.7,0.4,0.8) ... |
Now the cube will show you with a new diffuse color.