0
$\begingroup$

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_idname = "myaddon.big_preview"
    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")
$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – batFINGER
    Nov 21, 2016 at 10:41
  • $\begingroup$ 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. $\endgroup$ Nov 21, 2016 at 22:04

1 Answer 1

1
$\begingroup$

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.

enter image description here

import bpy
from bpy.types import Operator
class BigPreview(Operator):
    bl_idname = "myaddon.big_preview"
    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):
    self.layout.operator("myaddon.big_preview")

bpy.types.MATERIAL_PT_preview.append(draw_button)

bpy.utils.register_class(BigPreview)
$\endgroup$
1
  • $\begingroup$ Thank you very much for this answer! This fails in 2.76 but works in 2.77+ $\endgroup$ Nov 22, 2016 at 19:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .