I have the Pivot to Center Of Mass and Pivot to Center Of Volume functions inside a pie menu:
import bpy
from bpy.types import Menu, Operator
class RP_MT_TransformEdits(Menu):
# bl_label is displayed at the center of the pie menu
bl_label = 'Transform Edits'
bl_idname = 'RP_MT_TransformEdits'
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
# Here should be every function for the pie menu
# Order the lines in different order for different pie order
# Pie order: west, east, south, north, north-west, north-east, south-west, south-east
pie.operator('object.center_of_mass', icon = 'SNAP_VOLUME')
pie.operator('object.center_of_volume', icon = 'OUTLINER_OB_SURFACE')
class OT_PivotToCenterOfMass(Operator):
#needs to be lower case and underscores as word separation
bl_idname = 'object.center_of_mass'
bl_label = 'Pivot to Center Of Mass'
bl_description = "Set the object's origin, by either moving the data, or set to center of data, or use 3D cursor."
def execute(self, context):
bpy.ops.object.origin_set(type = 'ORIGIN_CENTER_OF_MASS', center = 'MEDIAN')
return {'FINISHED'}
class OT_PivotToCenterOfVolume(Operator):
#needs to be lower case and underscores as word separation
bl_idname = 'object.center_of_volume'
bl_label = 'Pivot to Center Of Volume'
bl_description = "Set the object's origin, by either moving the data, or set to center of data, or use 3D cursor."
def execute(self, context):
bpy.ops.object.origin_set(type = 'ORIGIN_CENTER_OF_VOLUME', center = 'MEDIAN')
return {'FINISHED'}
classes = (RP_MT_TransformEdits,
OT_PivotToCenterOfMass,
OT_PivotToCenterOfVolume,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == '__main__':
register()
bpy.ops.wm.call_menu_pie(name = 'RP_MT_TransformEdits')
When I try to use one of the functions I get the following error:
Error: Python: Traceback (most recent call last):
File "\Text", line 46, in execute
File "C:\Program Files\Blender Foundation\Blender 3.0\3.0\scripts\modules\bpy\ops.py", line 132, in __call__
ret = _op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties: : keyword "type" unrecognized
But running either
bpy.ops.object.origin_set(type = 'ORIGIN_CENTER_OF_MASS', center = 'MEDIAN')
or
bpy.ops.object.origin_set(type = 'ORIGIN_CENTER_OF_VOLUME', center = 'MEDIAN')
from the text editor works fine. Why do I get this error?