ebl_info = {
"name": "Pie Menu: Template",
"description": "Pie menu example",
"author": "Viktor Stepanov / pon",
"version": (0, 1, 1),
"blender": (4, 2, 0),
"location": "3D View",
"warning": "",
"doc_url": "",
"category": "Development",
}
import bpy
from bpy.types import Menu
def add_geo_nodes():#(subdiv_viewport_levels, subdiv_render_levels):
obj = bpy.context.active_object
if obj is None:
print("warning: no active object")
return
if obj.type != "MESH":
print("warning: the active object need to be a mesh")
return
bpy.ops.object.modifier_add(type='NODES')
bpy.ops.node.new_geometry_node_group_assign()
# bpy.ops.object.modifier_add(type="SUBSURF")
# bpy.context.object.modifiers["Subdivision"].levels = subdiv_viewport_levels
# bpy.context.object.modifiers["Subdivision"].render_levels = subdiv_render_levels
class MESH_OT_add_subdiv_mod(bpy.types.Operator):
"""Add a subdivision surf modifier to the active mesh"""
bl_idname = "mesh.add_geo_nodes"
bl_label = "Add Subdivision Surf Modifier to the Active Mesh Object"
bl_options = {"REGISTER", "UNDO"}
subdiv_viewport_lvl: bpy.props.IntProperty(
name="Subdiv Viewport",
default=1,
min=1,
max=3,
description="The Subdivision Levels applied in the Viewport",
)
subdiv_render_lvl: bpy.props.IntProperty(
name="Subdiv Render",
default=3,
min=3,
max=7,
description="The Subdivision Levels applied during the Viewport",
)
def execute(self, context):
add_geo_nodes()#(self.subdiv_viewport_lvl, self.subdiv_render_lvl) # I think this is where it runs the goe nodes script
return {"FINISHED"}
# -------------------------------------------------
class SwitchGeometryEditor(bpy.types.Operator):
bl_idname = "node.switch_to_geometry_editor"
bl_label = "Switch to Geometry Editor"
def execute(self, context):
bpy.context.area.ui_type = "GeometryNodeTree"
return {"FINISHED"}
# -------------------------------------------------
class VIEW3D_MT_PIE_template(Menu):
# label is displayed at the center of the pie menu.
bl_label = "Hot Pot Pie"
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
column = pie.split().column()
column.operator("mesh.primitive_plane_add", text="Add Plane", icon="MESH_PLANE")
column.operator("mesh.primitive_cube_add", text="Add Cube", icon="MESH_CUBE")
#column = pie.split().column()
column.operator("mesh.primitive_ico_sphere_add", text="Add Ico Shere", icon="MESH_ICOSPHERE")
column.operator("mesh.primitive_uv_sphere_add", text="Add UV Sphere", icon="MESH_UVSPHERE")
column.operator("object.gpencil_add", text="Add Grease Pencil", icon="GREASEPENCIL")
#column = pie.separator()
#column = pie.separator()
column = pie.separator()
column = pie.split().column()
#column.operator("mesh.add_subdiv_mod", text="Add Geo Nodes", icon="GEOMETRY_NODES")
#pie.operator("object.editmode_toggle", text="Eidt/Object", icon="OBJECT_DATAMODE")
pie.operator("mesh.add_geo_nodes", text="Add Geo Nodes", icon="GEOMETRY_NODES")
column.operator("object.shade_smooth", text="Shade Smooth", icon="MOD_SMOOTH")
#---------------------------------------------------------------------------------------
column = pie.separator()
#column = pie.separator()
column = pie.split().column()
column.operator("mesh.primitive_plane_add", text="Add Plane", icon="MESH_PLANE")
column.operator("mesh.primitive_cube_add", text="Add Cube", icon="MESH_CUBE")
#column = pie.split().column()
column.operator("mesh.primitive_ico_sphere_add", text="Add Ico Shere", icon="MESH_ICOSPHERE")
column.operator("mesh.primitive_uv_sphere_add", text="Add UV Sphere", icon="MESH_UVSPHERE")
column.operator("object.gpencil_add", text="Add Grease Pencil", icon="GREASEPENCIL")
# row = layout.row(align=True)
# row.operator(
# "node.switch_to_geometry_editor", text="", icon="GEOMETRY_NODES"
# )
#column.operator("ui_type= 'CompositorNodeTree'", text= "Comp", icon="NODE_COMPOSITING")
# bpy.context.area.ui_type = 'CompositorNodeTree'
# bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0.150648, -0.147638, -0.13872), scale=(1, 1, 1))
# bpy.ops.mesh.primitive_ico_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0.150648, -0.147638, -0.13872), scale=(1, 1, 1))
# bpy.ops.object.gpencil_add(align='WORLD', location=(-0.39162, -3.99968, -1.56407), scale=(1, 1, 1), type='EMPTY')
# bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(-0.39162, -3.99968, -1.56407), scale=(1, 1, 1))
global_addon_keymaps = []
def register():
bpy.utils.register_class(MESH_OT_add_subdiv_mod)
bpy.utils.register_class(VIEW3D_MT_PIE_template)
window_manager = bpy.context.window_manager
if window_manager.keyconfigs.addon:
keymap = window_manager.keyconfigs.addon.keymaps.new(name="3D View", space_type="VIEW_3D")
# keymap = window_manager.keyconfigs.addon.keymaps.new(name="Node Editor", space_type="NODE_EDITOR")
keymap_item = keymap.keymap_items.new("wm.call_menu_pie", "A", "PRESS", ctrl=True, shift=True)
keymap_item.properties.name = "VIEW3D_MT_PIE_template"
# save the key map to deregister later
global_addon_keymaps.append((keymap, keymap_item))
def unregister():
bpy.utils.unregister_class(VIEW3D_MT_PIE_template)
bpy.utils.unregister_class(MESH_OT_add_subdiv_mod)
window_manager = bpy.context.window_manager
if window_manager and window_manager.keyconfigs and window_manager.keyconfigs.addon:
for keymap, keymap_item in global_addon_keymaps:
keymap.keymap_items.remove(keymap_item)
global_addon_keymaps.clear()
if __name__ == "__main__":
register()