Button from enum

Hey guys, I’m using an add-on called black hole, and I’m trying to create a custom button from one of the functions, however the functions are enumerated and I have no idea how to make a button from it.

http://www.pasteall.org/57451/python

I assumed it would just be:

row.operator(“object.bh_update_origin”, text = “Pivot To Base”)

but with:

.type=‘1’

at the end, where 1 is the enum that sets the origin to the base of the model.

Any help would be very appreciated.

So what’s the exact problem?

row.operator(“op.name”).type = ‘…’

looks good to me.

If you need to set multiple operator properties, use

prop = row.operator(“op.name”)
prop.type = ‘…’
prop.other = ‘…’

BTW: your Blender version tuple is wrong, should be
“blender”: (2, 73, 0),

and please remove

"api": 39347,

it wasn’t ever used and removed from all stock scripts more than a year ago.

Well I’m assuming

 # Set to Object Base    if enum == 1:
        print("Setting to Object Base")
        
        # Enter the object!
        object_data = bpy.context.object.data
        bpy.ops.object.editmode_toggle()
        bpy.ops.mesh.select_all(action="DESELECT")
        bpy.ops.object.editmode_toggle()
        
        #Setup the correct tools to select vertices
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)
        sel_mode = context.tool_settings.mesh_select_mode
        context.tool_settings.mesh_select_mode = [True, False, False]
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
        
        i = -1
        lowestZ = 0
        
        # First find the lowest Z value in the object
        for vertex in object_data.vertices:
            i += 1
            #print (i)
            
            # Used to define a reference point for the first vertex, in case 0 is
            # lower than any vertex on the model.
            if i == 0:
                lowestZ = vertex.co.z
            
            else:
                if vertex.co.z < lowestZ:
                    lowestZ = vertex.co.z
        
        # Now select all vertices with lowestZ
        
        for vertex in object_data.vertices:
            if vertex.co.z == lowestZ:
                vertex.select = True
                #print("Vertex Selected!")


        #Restore previous settings
        bpy.ops.object.mode_set(mode='EDIT', toggle=False)
        context.tool_settings.mesh_select_mode = sel_mode
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
                  
        
        # Saves the current cursor location
        cursor_loc = bpy.data.scenes[bpy.context.scene.name].cursor_location
        previous_cursor_loc = [cursor_loc[0], cursor_loc[1], cursor_loc[2]]
        
        # Snap the cursor
        bpy.ops.object.editmode_toggle()
        bpy.ops.view3D.snap_cursor_to_selected()
        bpy.ops.mesh.select_all(action="DESELECT")
        bpy.ops.object.editmode_toggle()
        
        # Set the origin
        FocusObject(object)
        bpy.ops.object.origin_set(type ='ORIGIN_CURSOR')
        
        # Restore the original cursor location
        bpy.data.scenes[bpy.context.scene.name].cursor_location = previous_cursor_loc

Is the code to set the origin to the base of the object, and it says the enum is 1, but if I try:

        prop=row.operator("object.bh_update_origin")
        prop.type='1'

or:

row_object.operator("object.bh_update_origin", icon = "ROTATE").type='1'

The button just does the same as

row_object.operator("object.bh_update_origin", icon = "ROTATE")

Which is to repeat the objects default origin type from the enums…

Sorry, to be a pain lol I’m a designer not a coder lol
Thanks for your help so far :slight_smile: