3
$\begingroup$

I need help with Quadview drawing. I know how get the quad using the mouse position, but the problem is get the drawing area in the callback.

I have some code like this:

bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, (self, context), 'WINDOW', 'POST_PIXEL')

..

def draw_callback_px(self, context):
    # mi draw code here
      quad = get_quad(x, y) ???
    # need information of area in pixels or location to select Quad

But, I need the area that is drawing to detect the Quad.

how can get it?

$\endgroup$

1 Answer 1

3
$\begingroup$

Thanks to CoDEmanX, I have the solution:

 if not context.space_data.region_quadviews:
        rv3d = bpy.context.space_data.region_3d
    else:
        # verify area 
        if context.area.type != 'VIEW_3D' or context.space_data.type != 'VIEW_3D':
            return
        i = -1
        for region in context.area.regions:
            if region.type == 'WINDOW':
                i += 1
                if context.region.id == region.id:
                    break
        else:
            return

        rv3d = context.space_data.region_quadviews[i]
$\endgroup$
2
  • $\begingroup$ Excellent, just what I was looking for. $\endgroup$
    – batFINGER
    Commented Nov 11, 2015 at 11:34
  • $\begingroup$ For newer versions of Blender, you have to replace if context.region.id == region.id: with if context.region == region:. Also today I learned for-loops in Python can be followed by an else-statement. $\endgroup$
    – Zyl
    Commented Dec 21, 2020 at 17:30

You must log in to answer this question.

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