Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active January 9, 2020 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/8fd7ff2d1bad02cd2b8b73e8f8a91773 to your computer and use it in GitHub Desktop.
Save zeffii/8fd7ff2d1bad02cd2b8b73e8f8a91773 to your computer and use it in GitHub Desktop.
add menu hax
import bpy
import nodeitems_utils
from bpy.app.translations import contexts as i18n_contexts
def is_sverchok_editor(context):
sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'}
tree_type = context.space_data.tree_type
if tree_type in sv_tree_types:
return True
class SVNODE_MT_add(bpy.types.Menu):
bl_space_type = 'NODE_EDITOR'
bl_label = "Add"
bl_translation_context = i18n_contexts.operator_default
def draw(self, context):
layout = self.layout
if is_sverchok_editor(context):
layout.operator_context = 'INVOKE_REGION_WIN'
layout.operator("node.sv_extra_search", text="Search", icon='OUTLINER_DATA_FONT')
else:
layout.operator_context = 'INVOKE_DEFAULT'
props = layout.operator("node.add_search", text="Search...", icon='VIEWZOOM')
props.use_transform = True
layout.separator()
# actual node submenus are defined by draw functions from node categories
nodeitems_utils.draw_node_categories_menu(self, context)
def perform_menu_monkey_patch():
# replace the default Add menu, and update it with sverchok specific search
bpy.types.NODE_MT_add.draw = SVNODE_MT_add.draw
# replace the default Node Categories menu with our implementation
NC = nodeitems_utils._node_categories
SV = NC['SVERCHOK']
SVcatlist, sv_draw, SvCats = SV
NC['SVERCHOK'] = (SVcatlist, bpy.types.NODEVIEW_MT_Dynamic_Menu.draw, SvCats)
perform_menu_monkey_patch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment