I am trying to write a python script using the info panel.
The first part of the code is unwrapping a mesh which is executing successfully.
The second part is to change the viewport shading to MATERIAL which is used for rendering. But when I try to run the script I get this error .
Thirdly, I am trying to import a .png image. But its not being displayed in the UV Editor.
The code is shown below:
import bpy
for obj in bpy.data.objects:
if(obj.type == 'MESH'):
bpy.context.scene.objects.active = obj
bpy.ops.mesh.uv_texture_add()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.001)
bpy.context.space_data.context = 'MATERIAL'
bpy.ops.material.new()
bpy.ops.image.open(filepath="//finger1.png", directory="C:\\Users\\KM\\Desktop\\blender\\Test 1\\", files=[{"name":"finger1.png", "name":"finger1.png"}], relative_path=True, show_multiview=False)
Anything regarding this would be helpful. Thanks in advance.
bpy.context.space_data
depends on the active window (clicking on the materials button the the property editor). This line can be removed. $\endgroup$ – ideasman42 Jun 24 '15 at 21:11