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.
# 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: