Shortcut button script fail and can't showing and add in 2.8

Hi. We are creating a small addon that creates Blender function shortcut buttons in the menu panel.
The button script that worked in 2.7 was used so far, but in 2.8 there are some things that the script fails.
The following is an example.
This worked very well as a one-touch button in 2.7!
How can We make this possible with 2.8?

box = layout.box()
row = box.row(align = True)
row.scale_x = 1.5
row.operator("object.vertex_group_lock", text="", icon="CAMERA_DATA").action='UNLOCK'

What’s the exact issue here? The button isn’t showing or the action not working?

We apologize for being hard to understand. We can’t showing the button.
Adding that code to a custom script menu will cause the python command to fail.
Custom script menu is constructed from a text editor template. The base is UI Panel simple.
Some script buttons are already working, but this and some others get an error at 2.8 and the button does not appear,

We changed the title.

No problem at all.

I’ve used your exact code in the template panel for 2.8 and it works fine for me. Can you post your full draw code? Have you got the latest 2.8 build?

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " + obj.name)
        row = layout.row()
        row.prop(obj, "name")
        
        box = layout.box()
        row = box.row(align = True)
        row.scale_x = 1.5
        row.operator("object.vertex_group_lock", text="", icon="CAMERA_DATA").action='UNLOCK'

        row = layout.row()
        row.operator("mesh.primitive_cube_add")


def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()

Thank you. Yes, we think that the latest build have. This is the one downloaded from Blender.org.
2.80 Beta Linux 64 bit
April 30, 00:21:00 - 047081841113 Beta141.89MB
We are creating from pure ui_panel_simple. What we need is to display shortcut key buttons in the sidebar and perform operations there.
We are changing the cord here, do you get an error?

    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'

to

    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"

In Blender we have, there is a python error and it can not be executed.

Those changes are fine. Are you running it from the scripting tab? If so, try taking out

bl_context = "object"

It should register your panel in a misc tab of the UI panel. You’ll have to query the context in another way or load your script as an add-on rather than running in the scripting tab.

Also remember, that sometimes if you’ve had issues registering the class, make sure to close Blender and relaunch, before re-running your script.

1 Like

Thank you. We used categories instead of context.

bl_category = "object"

We are not familiar with the python syntax, but should we also indent the comments?

We are trying again. We will try to restart Blender each time. We will try loading it as an add-on.

Thanks to you, We feel that the custom shortcut button add-on can be used with 2.8.
If we publish an add-on, I do not know if there is anyone to use it. But it’s a very important add-on to us, thanks for the help!

My pleasure. I’m glad you got it working.
Comments don’t need to be indented but it makes for more readable code if you do.
As to publishing the add-on, you never know, there may be someone who finds it useful.
All the best!

1 Like

All buttons can be implemented in 2.8 and worked well! It was really good to hear question here. Thank you.
There is also a problem such as switching between displaying and hiding the outliner that has not yet been implemented in 2.8.
But this greatly easy our work at 2.8, it really helps for we!

you never know, there may be someone who finds it useful.

Certainly we do not know that. Certainly, there may be people who need it, even with a shortcut panel that just arranges buttons.
We also consider publishing add-on scripts. thank you.

1 Like