about wm.context_toggle confused

im confused how to add shortcut easily with wm.context_toggle
currently i notice in input editor most of them uses these active_object.data. ________

i made a few hotkey that i really use a lot for toggling on and off

active_object.data.show_handles
active_object.data.show_normal_face
and are working well

Now i tried here at UV editor Toolbar
im interested adding Stretch to toggle on and off to shortcut because i use it a lot

[ATTACH=CONFIG]362293[/ATTACH]

i tried the following

active_object.data.SpaceUVEditor.show_stretch
active_object.data.SpaceUVEditor.show.stretch
active_object.data.show.stretch
active_object.data.show_stretch

all of them got callerror

my intuition is that
active_object.data is not the right command?

Q > what is right command ? Why and how do you to detect it as right name command? for wm.context_toggle

i hope someone can help me understand by explaining since i really dont get the logic behind it i really have 0 knowledge in reading language python i just do referencing/comparing so i can understand

thank you for time and reading

The access path is space_data.uv_editor.show_stretch

It’s available in SpaceUVEditor only.

I recommend to add a new keybinding to Image > UV Editor > Image Generic (so the keybinding will work while the cursor is over the sidebars too, not just the main area).

For more about access paths see:

hi again mr i want to say thank you always for helping me
its working but i really want to understand the pattern or logic behind it

so far i notice most common use is space_data. _______ and active_object.data ________

now for ________

im still confuse in some areas
this is what i know so far i tried comparing or based from observation please enlighten me more if this method is wrong


my mind is still confuse the logical approach is not confident

can you explain why does this happen …
or do i need to experiment each one then the call error disappear
or do you have any method to easily detect

The names with uppercase letters are types (or classes in object-oriented programming). The access paths refer to instances (or objects) however. All types are available via bpy.types.*, but you can’t access the data structure instances that store the actual data here, only the blueprints. You can figure out the object hierarchies using the API docs or by fiddling around with auto-complete in the Python console.

Hi MatsuikoHiroka

I’ve too started recently testing Python/Blender.

However, I find it a bit unclear, how to “navigate” around “.” paths… windows, context, data, areas and such. It’s not so clear / self-evident where to read and where to set Blender scene data values.

Most likely have to do more reading, I’ve only done trial and error testing and googling so far. But this is how I get similar thing working:

  • Sami

# Access "real" active window viewports (I think)
# bpy.context.window.screen -> bpy.data.screens['Default']
# then the window has screen areas, one of which might be image/UV editor
# bpy.context.window.screen.areas[5].type -> 'IMAGE_EDITOR'

for area in bpy.context.window.screen.areas: 
    
    # if screen area is of type image editor, 
    # bpy.context.window.screen.areas[x].type, where x is 0-N
    
    if area.type == 'IMAGE_EDITOR': 
        
        # then image, perplexing but true, image editor contains, "spaces"
        # first of which is 'IMAGE_EDITOR', then there is 'LOGIC_EDITOR' etc
        
        for space in area.spaces:
           
            # and it seems: bpy.context.window.screen.areas[x].spaces[0].type 
            # --> 'IMAGE_EDITOR', now we got the correct "context"
            
            if space.type == 'IMAGE_EDITOR':
            
            # on command line, this would work:
            # bpy.context.window.screen.areas[5].spaces[0].uv_editor.show_stretch
                
                # here's a toggle code, if on > off and vice versa:

                if space.uv_editor.show_stretch == True:
                    space.uv_editor.show_stretch = False
                else:
                    space.uv_editor.show_stretch = True


Nicer version of ezez’s script:

import bpy

for area in bpy.context.screen.areas: 
    if area.type == 'IMAGE_EDITOR':
        area.spaces.active.uv_editor.show_stretch ^= True
        break

CoDEmanX:

Thanks for cleaning up my example :slight_smile:

So active can be used like that. If I may ask;

  • I’m very limited on time - is there a single good tutorial / book / article where the structure of Blender bpy.* items are explained?
  • Is there some sort “find” for commands? like in 3ds Max, it was very helpful for learning, that you can write apropos “mesh*” and you get all the commands containing mesh…

Anyway, thank you for good info!

  • Sami

Anything wrong with the API docs?

http://www.blender.org/documentation/250PythonDoc/

CoDEmanX;

Thanks, I think it’s API docs then - TBH, it’s more like a reference, not an introduction or tutorial about structure of Blender. As first step, it’s (at least for me) easier to check out some introduction / overview to subject, instead of browsing a references. I bet most of the needed stuff is there, but it’s very much like a phone book, information is just there. Like I mentioned, I’m limited on time and I’m not the best reader of references either, that’s why I asked.

EDIT: it seems there are some tutorial like parts there too, so I’ll check them! Thanks!

  • Sami

Yeah there are some tutorials and embedded examples. But when it comes to the structure, the only meaningful way is the phone book-style - there are simply too many data structures and functions.

You should check out the wiki, the examples are not that accurate and up to date, but you might understand things better.