Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. ui_tex = bpy.data.textures.new('MP', 'IMAGE')
  2.  
  3. ui_tex.image = bpy.data.images.load("D:/pic.png")
  4.  
  5. class UIPanel(bpy.types.Panel):
  6.  
  7. bl_label = "Label"
  8. bl_space_type = "VIEW_3D"
  9. bl_region_type = "TOOLS"
  10. br_name = "Printing"
  11.  
  12. def draw(self, context):
  13.  
  14. layout = self.layout
  15. scn = context.scene
  16.  
  17. ui_tex = bpy.data.textures.new("MP", "IMAGE")
  18. ui_tex.image = bpy.data.images.load("D:/pic.png")
  19.  
  20. row = layout.row(align=True)
  21. row.alignment = 'EXPAND'
  22. row.template_preview(bpy.data.textures["MP"])
  23.  
  24. line 39, in draw
  25. ui_tex.image = bpy.data.images.load(filepath = filepath)
  26. AttributeError: Writing to ID classes in this context is not allowed: MP, Texture datablock, error setting ImageTexture.image
  27.  
  28. bpy.ops.image.open(filepath='full_path_to/your_image.png')
  29. bpy.data.images['your_image.png'].pack(as_png=True) # Pack an image as embedded data into the .blend file
  30. ui_tex.image = bpy.data.images['your_image.png']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement