0
$\begingroup$

Is it possible to retrieve this text using Python? Reconstructing it is not an option. The reason is that I need to know whether a Viewer node is active, and this information is not exposed in the usual ways.

$\endgroup$
6
  • 2
    $\begingroup$ It would be best to describe context in detail to avoid XY problem kind of situation. What are you trying to do? Why? What exact information do you need to get? For what purpose? $\endgroup$ Commented Aug 3 at 10:54
  • $\begingroup$ retrieving this text would probably require accessing exact place in memory which may be different for different versions, there is something called AoB search which allows you to find something like this based on some value in memory before/after that is unlikely to change and unlikely to be offset away/towards the searched string because it's somehow logically connected (e.g. part of the same struct), but in general such solutions are too hard to maintain and aren't used. $\endgroup$ Commented Aug 3 at 11:24
  • $\begingroup$ @MartynasŽiemys I need to know if a viewer node is active. $\endgroup$ Commented Aug 8 at 8:17
  • $\begingroup$ @clankill3r, yes, but what's the context? $\endgroup$ Commented Aug 8 at 12:43
  • $\begingroup$ @MartynasŽiemys I'm making an addon where I show a stack of current Inspection Indexes that contribute to the result of the currently used viewer. $\endgroup$ Commented Aug 11 at 6:18

1 Answer 1

1
$\begingroup$

There's no direct Python API to get the exact text displayed by the Text Info overlay, so if you want that text you have no choice but to reconstruct it. Fortunately, the overlay contains no hidden or special data, and you can easily retrieve all of its values using the following script:

The Text Info overlay is simply made up of three elements: the viewport perspective, which can be accessed via region_3d.view_perspective; the active collection, accessible with bpy.context.collection.name; and the active object, which you can get using bpy.context.active_object.name. Then simply concatenate these strings together:

import bpy

def get_view_perspective_text(view_type):
    mapping = {
        'PERSP': "User Perspective",
        'ORTHO': "User Orthographic",
        'CAMERA': "Camera Perspective"
    }
    return mapping.get(view_type, "Unknown View")

print()
for area in bpy.context.screen.areas:
    if area.type != 'VIEW_3D':
        continue
    region_3d = area.spaces.active.region_3d
    perspective_text = get_view_perspective_text( \
                       region_3d.view_perspective)
    print(perspective_text)
    break

active_collection = bpy.context.collection
active_obj = bpy.context.active_object


print("(1)", active_collection.name, '|', active_obj.name)
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.