Created
August 9, 2017 14:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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