Skip to content

Commit

Permalink
feat: add name_sync operator and new ND Utils UI panel
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-hm committed Jan 30, 2022
1 parent 52e73ed commit dfcc13d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
from . import sketching
from . import power_mods
from . import generators
from . import utils


registerables = (
interface,
sketching,
power_mods,
generators,
utils,
)


Expand Down
4 changes: 4 additions & 0 deletions interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import importlib
from . import main_ui_panel
from . import utils_ui_panel
from . import main_menu


def reload():
importlib.reload(main_ui_panel)
importlib.reload(utils_ui_panel)
importlib.reload(main_menu)


def register():
main_ui_panel.register()
utils_ui_panel.register()
main_menu.register()


def unregister():
main_ui_panel.unregister()
utils_ui_panel.unregister()
main_menu.unregister()
30 changes: 30 additions & 0 deletions interface/utils_ui_panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import bpy
from .. import bl_info


class ND_PT_utils_ui_panel(bpy.types.Panel):
bl_label = "ND Utils v%s" % ('.'.join([str(v) for v in bl_info['version']]))
bl_idname = "ND_PT_utils_ui_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "HugeMenace"


def draw(self, context):
layout = self.layout

box = layout.box()
box.label(text="Scene Management", icon='SCENE_DATA')
column = box.column()

row = column.row(align=True)
row.scale_y = 1.2
row.operator("nd.name_sync", icon='FILE_REFRESH')


def register():
bpy.utils.register_class(ND_PT_utils_ui_panel)


def unregister():
bpy.utils.unregister_class(ND_PT_utils_ui_panel)
14 changes: 14 additions & 0 deletions utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import importlib
from . import name_sync


def reload():
importlib.reload(name_sync)


def register():
name_sync.register()


def unregister():
name_sync.unregister()
34 changes: 34 additions & 0 deletions utils/name_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import bpy


class ND_OT_name_sync(bpy.types.Operator):
bl_idname = "nd.name_sync"
bl_label = "Name Sync"
bl_description = "Updates all data names to match their corresponding object names"
bl_options = {'UNDO'}


@classmethod
def poll(cls, context):
return len(context.selected_objects) == 1


def execute(self, context):
for obj in context.selected_objects:
obj.data.name = obj.name

return {'FINISHED'}


def menu_func(self, context):
self.layout.operator(ND_OT_name_sync.bl_idname, text=ND_OT_name_sync.bl_label)


def register():
bpy.utils.register_class(ND_OT_name_sync)
bpy.types.VIEW3D_MT_object.append(menu_func)


def unregister():
bpy.utils.unregister_class(ND_OT_name_sync)
bpy.types.VIEW3D_MT_object.remove(menu_func)

0 comments on commit dfcc13d

Please sign in to comment.