Skip to content

Instantly share code, notes, and snippets.

@sambler
Created August 9, 2017 14:56
Show Gist options
  • Save sambler/9520e5e4f1cf1778d0b72abc4a06cea4 to your computer and use it in GitHub Desktop.
Save sambler/9520e5e4f1cf1778d0b72abc4a06cea4 to your computer and use it in GitHub Desktop.
Sample of how to set an image to be shown in the 3D viewport as a texture
# made for https://stackoverflow.com/q/45586114/2684771
# expects the current screen to have a 3dviewport and image editor visible
import bpy
bpy.context.scene.render.engine = 'BLENDER_RENDER'
for obj in bpy.data.objects:
bpy.data.objects.remove(obj)
bpy.ops.mesh.primitive_cylinder_add()
bpy.ops.mesh.uv_texture_add()
img = bpy.data.images.new('colgrid', 1024,1024)
img.generated_type = 'COLOR_GRID'
bpy.ops.object.mode_set(mode='EDIT')
for area in bpy.context.screen.areas :
if area.type == 'IMAGE_EDITOR' :
area.spaces.active.image = img
bpy.ops.object.mode_set(mode='OBJECT')
for area in bpy.context.screen.areas :
if area.type == 'VIEW_3D' :
area.spaces.active.viewport_shade = 'SOLID'
area.spaces.active.show_textured_solid = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment