Skip to content

Instantly share code, notes, and snippets.

@santolucito
Last active November 28, 2023 18:57
Show Gist options
  • Save santolucito/4f0bda16c6f09c1b64b0584af19a6acd to your computer and use it in GitHub Desktop.
Save santolucito/4f0bda16c6f09c1b64b0584af19a6acd to your computer and use it in GitHub Desktop.
Minimal Blender bpy script for COMS1002
import bpy
#delete all objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
#delete all materials
for m in bpy.data.materials:
bpy.data.materials.remove(m)
#create a new material
bpy.data.materials.new(name="myMaterial")
#set the color of the material
bpy.data.materials['myMaterial'].diffuse_color = (1, 0, 0, 1)
#make a cube
bpy.ops.mesh.primitive_cube_add(size=2, location=(0, 0, 0), scale=(1, 1, 1))
#give the cube the material we just created
bpy.context.object.data.materials.append(bpy.data.materials["myMaterial"]) #add the material to the object
#make a camera
bpy.ops.object.camera_add(location=(5,5,5))
#set the camera to point at the cube
bpy.ops.object.constraint_add(type='TRACK_TO')
bpy.context.object.constraints["Track To"].target = bpy.data.objects["Cube"]
#make a light
bpy.ops.object.light_add(type='AREA', radius=1, align='WORLD', location=(5, 0, 5), scale=(1, 1, 1))
#turn up the power on the light
bpy.context.object.data.energy = 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment