BGL visible in Active view only

hey, devs,

It is possible to show BGL texts or else, only in the active view?



I haven’t tried it, but it should be possible since you have to add a draw handler to the specific Space you want to render in. If you’re wanting something that is “always on” and only appears in the active view as you move through the UI, the challenge is going to be adding/removing the draw handlers as the focus changes. Perhaps a timer that constantly checks bpy.context and manages the draw handlers?

Yes maybe, I’ll try, thx.

If a dev can confirm if it’s possible or not :wink:

You can definitely draw in every 3D View. In fact, that’s what’s going to happen when you do the following from invoke():

args = (self, context, event)
self.drawCallbackHandle = bpy.types.SpaceView3D.draw_handler_add(myDrawCallback, args, 'WINDOW', 'POST_PIXEL')

In the handling function, you can then find out what SpaceView3D you are going to draw for using context.area.

The idea – I believe – is that the same code will just work for every 3D View, since each 3D View is a view of the same scene and data, just from a different perspective.

I want to draw only on the active, not in all 3dview.

I guess, you can specify in which area the drawing should be displayed in the call to area.tag_redraw(). If you call tag_redraw on context.area, only the area in the active context will display the drawing. To display it in all view3d areas, call tag_redraw on each element of areas = [a for a in bpy.context.screen.areas if a.type == 'VIEW_3D']

I accomplished exactly that in another thread I made just yesterday: Why are these two references to an object of type `bpy.types.Area` not the same despite the memory addresses being equal?

Same here…I have a custom panel that I draw on the viewport. I want to make it draw only on the area that it’s been called from. Using the area x,y coordinates to identify the area worked…but when I add the draw handler it just adds it to all VIEW_3D areas.
Even thought I explicitly told it “if the position match,add the draw handler to that area’s space”