Hello all,
I’ve been trying to create a hotkey to call the pivot point menu, but cannot find the appropriate command. Anyone has an idea ?
Thanks,
Hadrien
Hello all,
I’ve been trying to create a hotkey to call the pivot point menu, but cannot find the appropriate command. Anyone has an idea ?
Thanks,
Hadrien
wm.call_menu, but pivot_point is not a menu but an enum property,
so you could use this data path in the input settings:
wm.context_set_enum
data_path=“space_data.pivot_point”
value=“CURSOR”
Thanks CoDEmanX,
I already tried wm.context_toggle_enum to toggle between CURSOR and MEDIAN_POINT but what I would like to do -ideally- is to display the menu itself. Is it not possible out of the box ? Should I write a custom menu for this ? I tried my hand at it but could not figure out, even with the built-in “menu” template… (very rookie at scripting).
Hadrien
here’s a script to add a menu:
import bpy
pivot_prop = bpy.types.SpaceView3D.bl_rna.properties['pivot_point']
pivot_items = [(item.identifier, item.name, item.description) for item in pivot_prop.enum_items]
class VIEW3D_OT_pivot_point_set(bpy.types.Operator):
__doc__ = pivot_prop.description
bl_idname = "view3d.pivot_point_set"
bl_label = "Set Pivot Point (View 3D)"
type = bpy.props.EnumProperty(items=pivot_items)
@classmethod
def poll(cls, context):
for area in context.screen.areas:
if area.type == 'VIEW_3D':
return True
return False
def execute(self, context):
for area in context.screen.areas:
if area.type == 'VIEW_3D':
area.spaces[0].pivot_point = self.type
break
return {'FINISHED'}
class VIEW3D_MT_pivot_point_set(bpy.types.Menu):
bl_label = pivot_prop.name
bl_idname = "VIEW3D_MT_pivot_point_set"
def draw(self, context):
layout = self.layout
enum = bpy.types.SpaceView3D.bl_rna.properties['pivot_point'].enum_items
for item in reversed(enum):
layout.operator("view3d.pivot_point_set", text=item.name, icon=item.icon).type = item.identifier
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
# The menu can also be called from scripts
bpy.ops.wm.call_menu(name=VIEW3D_MT_pivot_point_set.bl_idname)
Waw, very kind of you, thanks ! I must ask a little more though : I can run the script but how exactly can I bind it to a hotkey ? Tried it through the input panel, no luck…
Hadrien
remove the last line of the script, then go to user prefs > input
e.g. View 3D > View 3D (Global)
wm.call_menu
VIEW3D_MT_pivot_point_set
And specify a hotkey
Yeah ! It works perfectly.
If I understand correctly the script needs to be registered ?
What does the “MT” in “View3D_MT” stand for ?
Apologies for the profusion of questions. These are my first steps.
Hadrien
edit
It looks like I have to run the script at every scene load ? Maybe I should make it an addon so it’s loaded by default ?
add this to the very top and install via User prefs > addons:
bl_info = {
"name": "Set Pivot Point (View 3D) Menu",
"author": "CoDEmanX",
"version": (1, 0),
"blender": (2, 65, 0),
"location": "View3D > Spacebar Menu (or bind it to a hotkey)",
"description": "A menu to change the Pivot Point of the 3D View, bindable to a hotkey.",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"}
Classes derived from bpy.types need to be registered to make them available to blender.
MT stands for Menu Type, so subclasses of bpy.types.Menu. OT stands for Operator Type, HT for Header Type, PT for Panel Type.
You are one gem of a dude. Thank you.
Also, this little script proves a nice ground of investigation for a beginner like me.
Cheers,
Hadrien