Objective: My goal was to identify how Blender presents itself within the python console it provides.
Materials:
Blender (software)
Methods:
- Open Blender
- Set the rendering to “Blender Game”
- Go to Materials (the icon looks like a globe with a four-square checker pattern on it) on the right
- Make sure that your cube (Blender should provide you one upon starting up) has a material. If not, add a new material by clicking “New”
- Click the button on the lower left and select “Logic Editor”
- Add some sensors, controllers, and actuators to the object
- Do not connect the sensors, controllers, or actuators
- Click the button on the lower left and select “Python Console”
- Click into the Python console window
- Type into the console import bpy and then hit enter
- Type into the console cube = bpy.data.objects[“Cube”]
- Type print(cube.location)
- Type print(cube.game.sensors[:])
- Type print(cube.game.controllers[:])
- Type print(cube.game.actuators[:])
- Type cube.game.actuators[0].link(cube.game.controllers[0])
- Type cube.game.controllers[0].link(cube.game.sensors[0])
- Type print(cube.active_material.diffuse_color)
- Type cube.active_material.diffuse_color.r = 0.0
- Type print(cube.active_material.diffuse_color.hsv)
- Type cube.active_material.diffuse_color.h = 0.8
- Go to the Logic Editor
Results: By performing the above, I first made the python console amenable to Blender and its properties. Then I assigned the premade cube object to the variable cube. After that, I identified the location of the cube. Then I identified the sensors, controllers, and actuators I’ve made for the cube. Proceeding this, I linked the first actuator to the first controller, and then the first controller to the first sensor. I identified the RGB value of the active material on the cube. I changed the red value, r, to 0.0, as the values of RGB and HSV are both floats ranging from 0.0 to 1.0. Once I changed it, the cube became cyan in color. Before changing the hue, h, to 0.8, I identified the HSV values of the active material on the cube. Once I changed it, it became magenta in color. Lastly, I looked to the Logic Editor and observed that I had successfully linked the sensor, controller, and actuator I targeted in the python console.
Discussion: This took a lot of figuring out to do, as the resources online for the Python Console with Blender were shoddy at best, confusing at worst, and for much older versions at “what.” However, that I’ve managed to do this much made me quite happy. I relied on extensive use of dir(command) along the way to understand what I was poking around at, but I managed to do more than I expected on my own. Connecting the different logic pieces may be easier through clicking, but if you have a large amount of logic pieces a looping script may make things easier. I wasn’t expecting the RGB and HSV values to be on a 0.0 to 1.0 scale, rather a 0 to 255 scale, but I recognized the possibility. Additionally, I found the requirement for parentheses on the print statement to be frustrating. Either way, this was a blast!