Skip to content
Snippets Groups Projects
Commit ce4fead3 authored by mano-wii's avatar mano-wii
Browse files

mesh_snap_utilities_line: workaround for tool registration

parent 9c914cb3
No related branches found
No related tags found
No related merge requests found
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
bl_info = { bl_info = {
"name": "Snap_Utilities_Line", "name": "Snap_Utilities_Line",
"author": "Germano Cavalcante", "author": "Germano Cavalcante",
"version": (5, 8, 24), "version": (5, 8, 25),
"blender": (0, 0, 0), "blender": (2, 80, 0),
"location": "View3D > TOOLS > Make Line", "location": "View3D > TOOLS > Make Line",
"description": "Extends Blender Snap controls", "description": "Extends Blender Snap controls",
#"wiki_url" : "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities", #"wiki_url" : "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities",
...@@ -65,47 +65,92 @@ def tool_make_line(): ...@@ -65,47 +65,92 @@ def tool_make_line():
"Connect them to split faces" "Connect them to split faces"
), ),
icon=os.path.join(icons_dir, "ops.mesh.make_line"), icon=os.path.join(icons_dir, "ops.mesh.make_line"),
# widget="MESH_GGT_mouse_point", #widget="MESH_GGT_mouse_point",
operator="mesh.make_line", operator="mesh.make_line",
keymap=( keymap="3D View Tool: Edit Mesh, Make Line",
("mesh.make_line", dict(type='LEFTMOUSE', value='PRESS'), None),
),
draw_settings=draw_settings, draw_settings=draw_settings,
) )
def register(): # -----------------------------------------------------------------------------
def get_tool_list(space_type, context_mode): # Tool Registraion
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type) def km_3d_view_tool_make_line(tool_mouse = 'LEFTMOUSE'):
return cls._tools[context_mode] return [(
"3D View Tool: Edit Mesh, Make Line",
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items": [
("mesh.make_line", {"type": tool_mouse, "value": 'CLICK'}, None),
]},
)]
def get_tool_list(space_type, context_mode):
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
return cls._tools[context_mode]
def register_make_line_tool():
tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
for index, tool in enumerate(tools, 1):
if isinstance(tool, ToolDef) and tool.text == "Add Cube":
break
tools.insert(index, tool_make_line)
keyconfigs = bpy.context.window_manager.keyconfigs
kc_defaultconf = keyconfigs.get("blender")
kc_addonconf = keyconfigs.get("blender addon")
# TODO: find the user defined tool_mouse.
keyconfig_data = km_3d_view_tool_make_line()
from bl_keymap_utils.io import keyconfig_init_from_data
keyconfig_init_from_data(kc_defaultconf, keyconfig_data)
keyconfig_init_from_data(kc_addonconf, keyconfig_data)
def unregister_make_line_tool():
tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
tools.remove(tool_make_line)
km_name, km_args, km_content = km_3d_view_tool_make_line()[0]
keyconfigs = bpy.context.window_manager.keyconfigs
defaultmap = keyconfigs.get("blender").keymaps
addonmap = keyconfigs.get("blender addon").keymaps
addonmap.remove(addonmap.find(km_name, **km_args))
defaultmap.remove(defaultmap.find(km_name, **km_args))
# -----------------------------------------------------------------------------
# Addon Registraion
def register():
bpy.utils.register_class(preferences.SnapUtilitiesLinePreferences) bpy.utils.register_class(preferences.SnapUtilitiesLinePreferences)
bpy.utils.register_class(common_classes.VIEW3D_OT_rotate_custom_pivot) bpy.utils.register_class(common_classes.VIEW3D_OT_rotate_custom_pivot)
bpy.utils.register_class(common_classes.VIEW3D_OT_zoom_custom_target) bpy.utils.register_class(common_classes.VIEW3D_OT_zoom_custom_target)
bpy.utils.register_class(ops_line.SnapUtilitiesLine) bpy.utils.register_class(ops_line.SnapUtilitiesLine)
# bpy.utils.register_class(common_classes.MousePointWidget) #bpy.utils.register_class(common_classes.MousePointWidget)
# bpy.utils.register_class(common_classes.MousePointWidgetGroup) #bpy.utils.register_class(common_classes.MousePointWidgetGroup)
bpy.utils.register_tool('VIEW_3D', 'EDIT_MESH', tool_make_line) register_make_line_tool()
# Move tool to after 'Add Cube'
tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
for index, tool in enumerate(tools):
if isinstance(tool, ToolDef) and tool.text == "Add Cube":
break
tools.insert(index + 1, tools.pop(-1))
def unregister(): def unregister():
bpy.utils.unregister_tool('VIEW_3D', 'EDIT_MESH', tool_make_line) unregister_make_line_tool()
# bpy.utils.unregister_class(common_classes.MousePointWidgetGroup) #bpy.utils.unregister_class(common_classes.MousePointWidgetGroup)
# bpy.utils.unregister_class(common_classes.MousePointWidget) #bpy.utils.unregister_class(common_classes.MousePointWidget)
bpy.utils.unregister_class(ops_line.SnapUtilitiesLine) bpy.utils.unregister_class(ops_line.SnapUtilitiesLine)
bpy.utils.unregister_class(common_classes.VIEW3D_OT_zoom_custom_target) bpy.utils.unregister_class(common_classes.VIEW3D_OT_zoom_custom_target)
bpy.utils.unregister_class(common_classes.VIEW3D_OT_rotate_custom_pivot) bpy.utils.unregister_class(common_classes.VIEW3D_OT_rotate_custom_pivot)
bpy.utils.unregister_class(preferences.SnapUtilitiesLinePreferences) bpy.utils.unregister_class(preferences.SnapUtilitiesLinePreferences)
if __name__ == "__main__": if __name__ == "__main__":
__name__ = "mesh_snap_utilities_line" __name__ = "mesh_snap_utilities_line"
__package__ = "mesh_snap_utilities_line" __package__ = "mesh_snap_utilities_line"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment