# Can I use template_preview in operator dialog?

I have the following in an Operator but it causes an "Error: EXCEPTION_ACCESS_VIOLATION" with no further details. I think (more of a guess) that the template_preview is trying to lookup/find in the region and that is returning null. Other than adding debug code to the .c code is there a way to find out?

class BigPreview(Operator):
bl_label = "Big Preview"

def execute(self, context):
print("Running big preview")
return {'FINISHED'}

def invoke(self, context, event):
wm = context.window_manager
print("Invoke big preview")
return wm.invoke_props_dialog(self, width=600, height=600)

def draw(self, context):
layout = self.layout
layout.template_preview( context.material, show_buttons=False, preview_id="corona.big_preview")

• Where are you trying to run this?, there will only be a context.material in the materials Properties panel. Maybe context.object.active_material if it's not None. Nov 21 '16 at 10:41
• I added a button under the existing preview in the material panel to launch this operator. My intention is to have a larger material preview. Thanks! context.material contains the correct material. I can print out the name in the draw method. Nov 21 '16 at 22:04

I asked re context.material and where you are running this from as the following works for me.

Well to some extent, in that the popup height is not taken up entirely by the preview at times.

Dragging the resize widget ("=" above the Ok) will crash if the check method returns True (enables popup redraw) & throws the error "context object has no attribute "material"" ... or crash blender.

Hence I went for context.object.active_material. (or somehow other than context.material)

If you find the height not right, can add the col.scale_y = 3 to give area to drag resize, then press again to see resize... trying to resize "live" in a popup appears very dodgy (speed wise) on my system.

import bpy
from bpy.types import Operator
class BigPreview(Operator):
bl_label = "Big Preview"

def execute(self, context):
print("Running big preview")
return {'FINISHED'}

def check(self, context):
return False

def invoke(self, context, event):
wm = context.window_manager
print("Invoke big preview")
return wm.invoke_props_dialog(self, width=600, height=400)

def draw(self, context):
layout = self.layout
mat = context.object.active_material
col = layout.column()
#col.scale_y = 2
col.template_preview( mat, show_buttons=False, preview_id="corona.bigpreview")

def draw_button(self, context):